Skip to content

Commit

Permalink
fix: correction method reference
Browse files Browse the repository at this point in the history
  • Loading branch information
WX-DongXing committed Nov 28, 2024
1 parent 25e8a38 commit 2fce577
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
const pageConfig = Object.assign({}, global.__mpxPageConfig, currentInject.pageConfig)
const Page = ({ navigation, route }) => {
const [enabled, setEnabled] = useState(false)
const keyboardAvoidContextValue = useRef({ setEnabled })
const currentPageId = useMemo(() => ++pageId, [])
const intersectionObservers = useRef({})
usePageStatus(navigation, currentPageId)
Expand Down Expand Up @@ -487,11 +488,14 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
createElement(
KeyboardAvoidContext.Provider,
{
value: setEnabled
value: keyboardAvoidContextValue
},
createElement(
ReactNative.KeyboardAvoidingView,
{
style: {
flex: 1
},
contentContainerStyle: {
flex: 1
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export type LabelContextValue = MutableRefObject<{
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void
}>

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

export interface GroupValue {
[key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> }
}
Expand All @@ -31,10 +35,6 @@ export interface IntersectionObserver {
}
}

export interface KeyboardAvoidContextValue {
setEnabled: (enabled: boolean) => void
}

export const MovableAreaContext = createContext({ width: 0, height: 0 })

export const FormContext = createContext<FormContextValue | null>(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ import {
TextInputSelectionChangeEventData,
TextInputFocusEventData,
TextInputChangeEventData,
TextInputSubmitEditingEventData
TextInputSubmitEditingEventData,
Keyboard
} from 'react-native'
import { warn } from '@mpxjs/utils'
import { parseInlineStyle, useUpdateEffect, useTransformStyle, useLayout } from './utils'
Expand Down Expand Up @@ -263,7 +264,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
props
)
)
adjustPosition && kyboardAvoidContext?.setEnabled(true)
adjustPosition && kyboardAvoidContext?.current?.setEnabled?.(true)
}

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

const onKeyPress = (evt: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
Expand Down

0 comments on commit 2fce577

Please sign in to comment.