-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathKeyboardAvoidingView.ios.tsx
52 lines (44 loc) · 1.4 KB
/
KeyboardAvoidingView.ios.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { requireNativeViewManager } from 'expo-modules-core';
import type * as React from 'react';
import { useCallback, useState } from 'react';
import { LayoutAnimation } from 'react-native';
import type { KeyboardAvoidingViewProps } from './KeyboardAvoidingView.types';
type KeyboardHeightChangedEvent = {
nativeEvent: { height: number, duration: number}
}
type NativeViewProps = KeyboardAvoidingViewProps & {
onKeyboardHeightChanged: (event: KeyboardHeightChangedEvent) => void
}
const NativeView: React.ComponentType<NativeViewProps> =
requireNativeViewManager('KeyboardAvoidingView');
export default function KeyboardAvoidingView({
children,
style,
...props
}: KeyboardAvoidingViewProps) {
const [keyboardHeight, setKeyboardHeight] = useState<number>();
const onKeyboardHeightChanged = useCallback(
({ nativeEvent: { height, duration } }: KeyboardHeightChangedEvent) => {
console.log(height, duration)
setKeyboardHeight(height);
if (duration === 0) return;
LayoutAnimation.configureNext({
duration: duration > 10 ? duration : 10,
update: {
duration: duration > 10 ? duration : 10,
type: 'keyboard'
}
});
},
[]
);
return (
<NativeView
{...props}
style={[style, {paddingBottom: keyboardHeight}]}
onKeyboardHeightChanged={onKeyboardHeightChanged}
>
{children}
</NativeView>
);
}