Skip to content

Commit

Permalink
Merge branch 'feat-rn-keyboard-avoiding' into fix-drn
Browse files Browse the repository at this point in the history
  • Loading branch information
WX-DongXing committed Dec 4, 2024
2 parents df0b089 + ee113f6 commit 89349f1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
const { Provider, useSafeAreaInsets, GestureHandlerRootView } = global.__navigationHelper
const pageConfig = Object.assign({}, global.__mpxPageConfig, currentInject.pageConfig)
const Page = ({ navigation, route }) => {
const [enabled, setEnabled] = useState(false)
const keyboardAvoidContextValue = useRef({ setEnabled })
const [enabled, setEnabled] = useState(true)
const currentPageId = useMemo(() => ++pageId, [])
const intersectionObservers = useRef({})
usePageStatus(navigation, currentPageId)
Expand Down Expand Up @@ -488,7 +487,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
createElement(
KeyboardAvoidContext.Provider,
{
value: keyboardAvoidContextValue
value: { setEnabled }
},
createElement(
ReactNative.KeyboardAvoidingView,
Expand All @@ -510,7 +509,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
ref: rootRef,
onLayout,
onTouchStart: () => {
enabled && ReactNative.Keyboard.dismiss()
ReactNative.Keyboard.isVisible() && ReactNative.Keyboard.dismiss()
}
},
createElement(Provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = function ({ print }) {
qa: qaPropLog
},
{
test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|adjust-position|hold-keyboard|safe-password-.+)$/,
test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|hold-keyboard|safe-password-.+)$/,
ios: iosPropLog,
android: androidPropLog
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = function ({ print }) {
}
},
{
test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|adjust-position|hold-keyboard|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
test: /^(placeholder-style|placeholder-class|cursor-spacing|always-embed|hold-keyboard|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
ios: iosPropLog,
android: androidPropLog
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export type LabelContextValue = MutableRefObject<{
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void
}>

export type KeyboardAvoidContextValue = MutableRefObject<{
export type KeyboardAvoidContextValue = {
setEnabled: (enabled: boolean) => void
}>
}

export interface GroupValue {
[key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
'parent-font-size': parentFontSize,
'parent-width': parentWidth,
'parent-height': parentHeight,
'adjust-position': adjustPosition = false,
'adjust-position': adjustPosition = true,
bindinput,
bindfocus,
bindblur,
Expand All @@ -174,7 +174,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
const placeholderTextColor = parseInlineStyle(placeholderStyle)?.color
const textAlignVertical = multiline ? 'top' : 'auto'

const tmpValue = useRef<string>()
const tmpValue = useRef<string | undefined>(defaultValue)
const cursorIndex = useRef<number>(0)
const lineCount = useRef<number>(0)

Expand Down Expand Up @@ -263,7 +263,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
props
)
)
adjustPosition && kyboardAvoidContext?.current?.setEnabled?.(true)
}

const onInputBlur = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
Expand All @@ -281,7 +280,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
props
)
)
adjustPosition && kyboardAvoidContext?.current?.setEnabled?.(false)
}

const onKeyPress = (evt: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
Expand Down Expand Up @@ -384,6 +382,10 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
}
}, [])

useEffect(() => {
kyboardAvoidContext?.setEnabled?.(adjustPosition)
}, [adjustPosition])

useUpdateEffect(() => {
if (!nodeRef?.current) {
return
Expand All @@ -405,8 +407,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
}
},
...layoutProps,
onFocus: (bindfocus || adjustPosition) && onInputFocus,
onBlur: (bindblur || adjustPosition) && onInputBlur,
onFocus: bindfocus && onInputFocus,
onBlur: bindblur && onInputBlur,
onKeyPress: bindconfirm && onKeyPress,
onSubmitEditing: bindconfirm && multiline && onSubmitEditing,
onSelectionChange: bindselectionchange && onSelectionChange
Expand Down

0 comments on commit 89349f1

Please sign in to comment.