Skip to content

Commit 4de1419

Browse files
committed
fix: scroll to bottom
1 parent b04ba5a commit 4de1419

File tree

1 file changed

+29
-1
lines changed
  • app/views/RoomView/List/components

1 file changed

+29
-1
lines changed

app/views/RoomView/List/components/List.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import React, { useMemo, useState } from 'react';
1+
import React, { useMemo, useRef, useState } from 'react';
22
import { type NativeScrollEvent, type NativeSyntheticEvent, StyleSheet, View } from 'react-native';
33
import { FlashList } from '@shopify/flash-list';
4+
import { useKeyboardHandler } from 'react-native-keyboard-controller';
5+
import { runOnJS } from 'react-native-reanimated';
46

57
import { type IListProps } from '../definitions';
68
import NavBottomFAB from './NavBottomFAB';
@@ -19,6 +21,7 @@ const styles = StyleSheet.create({
1921
const List = ({ listRef, jumpToBottom, ...props }: IListProps) => {
2022
const [visible, setVisible] = useState(false);
2123
const { isAutocompleteVisible } = useRoomContext();
24+
const isNearBottomRef = useRef(true); // Track if user is near bottom
2225

2326
const maintainVisibleContentPositionConfig = useMemo(
2427
() => ({
@@ -33,13 +36,38 @@ const List = ({ listRef, jumpToBottom, ...props }: IListProps) => {
3336
const currentScroll = Math.round(e.nativeEvent?.contentSize?.height) - Math.round(e.nativeEvent?.contentOffset.y);
3437
const layoutLimit = e.nativeEvent.layoutMeasurement.height + SCROLL_LIMIT;
3538

39+
// Update FAB visibility
3640
if (layoutLimit < currentScroll) {
3741
setVisible(true);
42+
isNearBottomRef.current = false;
3843
} else {
3944
setVisible(false);
45+
isNearBottomRef.current = true;
4046
}
4147
};
4248

49+
// Handle keyboard show event
50+
const handleKeyboardShow = () => {
51+
if (isNearBottomRef.current && jumpToBottom) {
52+
jumpToBottom();
53+
}
54+
};
55+
56+
// Listen for keyboard events
57+
useKeyboardHandler(
58+
{
59+
onStart: e => {
60+
'worklet';
61+
62+
// Only scroll when keyboard is opening (height > 0)
63+
if (e.height > 0) {
64+
runOnJS(handleKeyboardShow)();
65+
}
66+
}
67+
},
68+
[jumpToBottom]
69+
);
70+
4371
return (
4472
<View style={styles.list}>
4573
<FlashList

0 commit comments

Comments
 (0)