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

View File

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