Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/core/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ export interface RnConfig {
* @param packages 分包名数组
*/
downloadChunkAsync?: (packages: Array<string>) => void

/**
* bundle 中是否关闭 android 键盘避让功能,如果关闭需要将该配置设置为 false,使用 mpx 内置的键盘避让逻辑
* @platform android
* @default true
*/
enableNativeKeyboardAvoiding?: boolean
}

interface MpxConfig {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/platform/createApp.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createElement, memo, useRef, useEffect } from 'react'
import * as ReactNative from 'react-native'
import { initAppProvides } from './export/inject'
import { NavigationContainer, createNativeStackNavigator, SafeAreaProvider, GestureHandlerRootView } from './env/navigationHelper'
import { innerNav } from './env/nav'
import MpxNav from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-nav'

const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)

Expand Down Expand Up @@ -66,8 +66,8 @@ export default function createApp (options) {
flex: 1
}
},
createElement(innerNav, {
pageConfig: pageConfig,
createElement(MpxNav, {
pageConfig,
navigation
}),
children
Expand Down
137 changes: 0 additions & 137 deletions packages/core/src/platform/env/nav.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/platform/patch/getDefaultOptions.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RouteContext
} from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/context'
import { PortalHost, useSafeAreaInsets } from '../env/navigationHelper'
import { useInnerHeaderHeight } from '../env/nav'
import { useInnerHeaderHeight } from '@mpxjs/webpack-plugin/lib/runtime/components/react/dist/mpx-nav'

function getSystemInfo () {
const windowDimensions = ReactNative.Dimensions.get('window')
Expand Down
16 changes: 10 additions & 6 deletions packages/webpack-plugin/lib/runtime/components/react/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ export type LabelContextValue = MutableRefObject<{
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void
}>

export type KeyboardAvoidContextValue = MutableRefObject<
{ cursorSpacing: number, ref: MutableRefObject<any> } | null
>
export type KeyboardAvoidContextValue = MutableRefObject<{
cursorSpacing: number
ref: MutableRefObject<any>
adjustPosition: boolean
keyboardHeight?: number
onKeyboardShow?: () => void
} | null>

export interface GroupValue {
[key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> }
Expand Down Expand Up @@ -37,13 +41,13 @@ export interface IntersectionObserver {
}

export interface PortalContextValue {
mount: (children: React.ReactNode, key?: number | null, id?: number| null) => number| undefined
mount: (children: React.ReactNode, key?: number | null, id?: number | null) => number | undefined
update: (key: number, children: React.ReactNode) => void
unmount: (key: number) => void
}

export interface ScrollViewContextValue {
gestureRef: React.RefObject<any> | null,
gestureRef: React.RefObject<any> | null
scrollOffset: Animated.Value
}

Expand All @@ -53,7 +57,7 @@ export interface RouteContextValue {
}

export interface StickyContextValue {
registerStickyHeader: Function,
registerStickyHeader: Function
unregisterStickyHeader: Function
}

Expand Down
57 changes: 41 additions & 16 deletions packages/webpack-plugin/lib/runtime/components/react/mpx-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
}

const setKeyboardAvoidContext = () => {
if (adjustPosition && keyboardAvoid) {
keyboardAvoid.current = { cursorSpacing, ref: nodeRef }
if (keyboardAvoid) {
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition }
}
}

Expand All @@ -295,20 +295,45 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
}

const onFocus = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
setKeyboardAvoidContext()
bindfocus && bindfocus(
getCustomEvent(
'focus',
evt,
{
detail: {
value: tmpValue.current || ''
},
layoutRef
},
props
)
)
if (!keyboardAvoid?.current) {
setKeyboardAvoidContext()
}

if (bindfocus) {
const focusAction = () => {
bindfocus(
getCustomEvent(
'focus',
evt,
{
detail: {
value: tmpValue.current || '',
height: keyboardAvoid?.current?.keyboardHeight
},
layoutRef
},
props
)
)
if (keyboardAvoid?.current?.onKeyboardShow) {
keyboardAvoid.current.onKeyboardShow = undefined
}
}
if (keyboardAvoid?.current) {
// 有 keyboardAvoiding
if (keyboardAvoid.current.keyboardHeight) {
// iOS: keyboard 获取高度时机 keyboardWillShow 在 input focus 之前,可以立即执行
focusAction()
} else {
// Android,Harmony: keyboard 获取高度时机 keyboardDidShow 在 input focus 之后,需要延迟回调
evt.persist()
keyboardAvoid.current.onKeyboardShow = focusAction
}
} else {
// 无 keyboardAvoiding,直接执行 focus 回调
focusAction()
}
}
}

const onBlur = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
Expand Down
Loading
Loading