avoid latch during momentum

This commit is contained in:
balzack 2022-10-04 20:45:53 -07:00
parent 01d82d1097
commit 7441f46dc7
2 changed files with 13 additions and 2 deletions

View File

@ -43,8 +43,10 @@ export function ConversationBody() {
const ref = useRef(); const ref = useRef();
const latch = () => { const latch = () => {
actions.latch(); if (!state.momentum) {
ref.current.scrollToIndex({ animated: true, index: 0 }); actions.latch();
ref.current.scrollToIndex({ animated: true, index: 0 });
}
} }
return ( return (
@ -52,6 +54,8 @@ export function ConversationBody() {
<FlatList <FlatList
ref={ref} ref={ref}
data={state.topics} data={state.topics}
onMomentumScrollBegin={actions.setMomentum}
onMomentumScrollEnd={actions.clearMomentum}
onScrollBeginDrag={actions.unlatch} onScrollBeginDrag={actions.unlatch}
maintainVisibleContentPosition={ state.latched ? null : { minIndexForVisibile: 2, } } maintainVisibleContentPosition={ state.latched ? null : { minIndexForVisibile: 2, } }
inverted={true} inverted={true}

View File

@ -8,6 +8,7 @@ export function useConversation() {
subject: null, subject: null,
logo: null, logo: null,
latched: true, latched: true,
momentum: false,
}); });
const conversation = useContext(ConversationContext); const conversation = useContext(ConversationContext);
@ -40,6 +41,12 @@ export function useConversation() {
unlatch: () => { unlatch: () => {
updateState({ latched: false }); updateState({ latched: false });
}, },
setMomentum: () => {
updateState({ momentum: true });
},
clearMomentum: () => {
updateState({ momentum: false });
},
}; };
return { state, actions }; return { state, actions };