2022-04-13 20:43:56 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { KeyboardAwareScrollView, KeyboardAwareScrollViewProps } from '@codler/react-native-keyboard-aware-scroll-view';
|
2023-02-14 17:35:49 +00:00
|
|
|
import { Keyboard, Pressable } from 'react-native';
|
2022-04-13 20:43:56 +00:00
|
|
|
|
2022-06-06 14:17:51 +00:00
|
|
|
import scrollPersistTaps from '../lib/methods/helpers/scrollPersistTaps';
|
2023-02-14 17:35:49 +00:00
|
|
|
import sharedStyles from '../views/Styles';
|
2022-04-13 20:43:56 +00:00
|
|
|
|
|
|
|
interface IKeyboardViewProps extends KeyboardAwareScrollViewProps {
|
|
|
|
keyboardVerticalOffset?: number;
|
|
|
|
scrollEnabled?: boolean;
|
|
|
|
children: React.ReactElement[] | React.ReactElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KeyboardView = ({ style, contentContainerStyle, scrollEnabled, keyboardVerticalOffset, children }: IKeyboardViewProps) => (
|
|
|
|
<KeyboardAwareScrollView
|
|
|
|
{...scrollPersistTaps}
|
|
|
|
style={style}
|
|
|
|
contentContainerStyle={contentContainerStyle}
|
|
|
|
scrollEnabled={scrollEnabled}
|
|
|
|
alwaysBounceVertical={false}
|
2022-08-08 21:02:08 +00:00
|
|
|
extraHeight={keyboardVerticalOffset}
|
|
|
|
>
|
2023-02-14 17:35:49 +00:00
|
|
|
{/** Use Pressable instead of TouchableWithoutFeedback, because the TouchableWithoutFeedback requires a view wrapping the children
|
|
|
|
* and this wrapping is causing wrong behavior on ScrollView
|
|
|
|
* https://stackoverflow.com/a/74456534
|
|
|
|
* */}
|
|
|
|
<Pressable style={sharedStyles.container} onPress={() => Keyboard.dismiss()}>
|
|
|
|
{children}
|
|
|
|
</Pressable>
|
2022-04-13 20:43:56 +00:00
|
|
|
</KeyboardAwareScrollView>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default KeyboardView;
|