PRD-2153: Allow user to scroll up while response is generating#44
PRD-2153: Allow user to scroll up while response is generating#44veliseev93 merged 3 commits intodevelopmentfrom
Conversation
| renderItem={renderItem} | ||
| // TODO: Add autoscrollToBottom logic when it implemented in lib | ||
| maintainVisibleContentPosition={{ | ||
| startRenderingFromBottom: true, |
veliseev93
left a comment
There was a problem hiding this comment.
@Tomass673 I left a few suggestions on how to improve gesture interception during auto-scrolling at the bottom - could you please check them out?
| const isScrollToBottomVisible = useSharedValue(0); | ||
| const previousScrollY = useRef(0); | ||
| const [autoscrollToBottomThreshold, setAutoscrollToBottomThreshold] = useState<number | undefined>(1); | ||
| const isNearBottomRef = useRef(true); |
There was a problem hiding this comment.
| const isNearBottomRef = useRef(true); | |
| const shouldAutoscrollToBottomRef = useRef(true); | |
| const touchStartY = useRef(0); |
| isScrollToBottomAvailable.current = true; | ||
| }, 500); | ||
|
|
||
| if (isNearBottomRef.current && listRef.current && messages?.length > 0) { |
There was a problem hiding this comment.
| if (isNearBottomRef.current && listRef.current && messages?.length > 0) { | |
| if (shouldAutoscrollToBottomRef.current) { | |
| requestAnimationFrame(() => { | |
| listRef.current?.scrollToEnd({ animated: true }); | |
| }); | |
| } |
| return ( | ||
| <View className='relative flex-1'> | ||
| <AppFlashList<Message> | ||
| ref={listRef} |
There was a problem hiding this comment.
| ref={listRef} | |
| onTouchStart={(e) => { | |
| touchStartY.current = e.nativeEvent.pageY; | |
| shouldAutoscrollToBottomRef.current = false; | |
| }} | |
| onTouchEnd={(e) => { | |
| const deltaY = e.nativeEvent.pageY - touchStartY.current; | |
| if (deltaY < 20) { | |
| shouldAutoscrollToBottomRef.current = true; | |
| } | |
| }} |
It works mostly fine on iOS (though still a bit flaky), but it doesn’t work on Android at all. When the user scrolls up during response generation and then scrolls back down to the bottom, Your suggested approach relies on |
We can use similar callbacks like this: It works on both platforms: Test.mov |
Now it works fine on both platforms indeed. Thank you! |

Task: https://app.clickup.com/t/24336023/PRD-2022