tooot/src/components/ModalScrollView.tsx

30 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-01-26 13:59:42 +01:00
import { useHeaderHeight } from '@react-navigation/elements'
import { StyleConstants } from '@utils/styles/constants'
2023-02-11 22:04:32 +01:00
import { ForwardedRef, forwardRef, PropsWithChildren } from 'react'
2023-01-26 13:59:42 +01:00
import { KeyboardAvoidingView, Platform, ScrollView } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'
export const ModalScrollView = forwardRef(
2023-02-11 22:04:32 +01:00
({ children }: PropsWithChildren, ref: ForwardedRef<ScrollView>) => {
2023-01-26 13:59:42 +01:00
const headerHeight = useHeaderHeight()
return (
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
keyboardVerticalOffset={headerHeight}
>
<SafeAreaView style={{ flex: 1 }} edges={['bottom']}>
<ScrollView
ref={ref}
keyboardShouldPersistTaps='always'
contentContainerStyle={{ padding: StyleConstants.Spacing.Global.PagePadding }}
>
{children}
</ScrollView>
</SafeAreaView>
</KeyboardAvoidingView>
)
}
)