create keyboardverticaloffset hook (#3823)
parent
aca55cb192
commit
96c5db3e69
|
@ -1,8 +1,10 @@
|
||||||
import React, {useCallback, useRef} from 'react'
|
import React, {useCallback, useEffect, useRef} from 'react'
|
||||||
import {
|
import {
|
||||||
|
Dimensions,
|
||||||
FlatList,
|
FlatList,
|
||||||
NativeScrollEvent,
|
NativeScrollEvent,
|
||||||
NativeSyntheticEvent,
|
NativeSyntheticEvent,
|
||||||
|
Platform,
|
||||||
View,
|
View,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import {KeyboardAvoidingView} from 'react-native-keyboard-controller'
|
import {KeyboardAvoidingView} from 'react-native-keyboard-controller'
|
||||||
|
@ -11,7 +13,6 @@ import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {useFocusEffect} from '@react-navigation/native'
|
import {useFocusEffect} from '@react-navigation/native'
|
||||||
|
|
||||||
import {isIOS} from '#/platform/detection'
|
|
||||||
import {useChat} from '#/state/messages'
|
import {useChat} from '#/state/messages'
|
||||||
import {ConvoItem, ConvoStatus} from '#/state/messages/convo'
|
import {ConvoItem, ConvoStatus} from '#/state/messages/convo'
|
||||||
import {useSetMinimalShellMode} from '#/state/shell'
|
import {useSetMinimalShellMode} from '#/state/shell'
|
||||||
|
@ -125,11 +126,12 @@ export function MessagesList() {
|
||||||
)
|
)
|
||||||
|
|
||||||
const {bottom: bottomInset} = useSafeAreaInsets()
|
const {bottom: bottomInset} = useSafeAreaInsets()
|
||||||
|
const keyboardVerticalOffset = useKeyboardVerticalOffset()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
style={[a.flex_1, {marginBottom: bottomInset}]}
|
style={[a.flex_1, {marginBottom: bottomInset}]}
|
||||||
keyboardVerticalOffset={isIOS ? 60 : 25}
|
keyboardVerticalOffset={keyboardVerticalOffset}
|
||||||
behavior="padding"
|
behavior="padding"
|
||||||
contentContainerStyle={a.flex_1}>
|
contentContainerStyle={a.flex_1}>
|
||||||
<FlatList
|
<FlatList
|
||||||
|
@ -175,3 +177,26 @@ export function MessagesList() {
|
||||||
</KeyboardAvoidingView>
|
</KeyboardAvoidingView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useKeyboardVerticalOffset() {
|
||||||
|
const {top: topInset} = useSafeAreaInsets()
|
||||||
|
const [screenWindowDifference, setScreenWindowDifference] = React.useState(
|
||||||
|
() => Dimensions.get('screen').height - Dimensions.get('window').height,
|
||||||
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const subscription = Dimensions.addEventListener(
|
||||||
|
'change',
|
||||||
|
({screen, window}) => {
|
||||||
|
setScreenWindowDifference(screen.height - window.height)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return () => subscription.remove()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return Platform.select({
|
||||||
|
ios: topInset,
|
||||||
|
android: screenWindowDifference,
|
||||||
|
default: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue