Skip to content

Commit

Permalink
fix: categories index change (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmark0116 committed May 9, 2024
1 parent 9939016 commit a2db051
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/EmojiStaticKeyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const EmojiStaticKeyboard = React.memo(
} = React.useContext(KeyboardContext)
const { keyboardState } = useKeyboardStore()
const flatListRef = React.useRef<FlatList>(null)
const hasMomentumBegan = React.useRef(false)

const getItemLayout = React.useCallback(
(_: EmojisByCategory[] | null | undefined, index: number) => ({
Expand Down Expand Up @@ -109,10 +110,18 @@ export const EmojiStaticKeyboard = React.memo(
[scrollNav, width],
)

const onScrollEnd = React.useCallback(
const onMomentumScrollBegin = React.useCallback(() => {
hasMomentumBegan.current = true
}, [])

const onMomentumScrollEnd = React.useCallback(
(el: NativeSyntheticEvent<NativeScrollEvent>) => {
if (!hasMomentumBegan.current) return

const index = el.nativeEvent.contentOffset.x / width
setActiveCategoryIndex(Math.round(index))

hasMomentumBegan.current = false
},
[setActiveCategoryIndex, width],
)
Expand Down Expand Up @@ -169,7 +178,8 @@ export const EmojiStaticKeyboard = React.memo(
maxToRenderPerBatch={1}
onScroll={handleScroll}
keyboardShouldPersistTaps="handled"
onMomentumScrollEnd={onScrollEnd}
onMomentumScrollBegin={onMomentumScrollBegin}
onMomentumScrollEnd={onMomentumScrollEnd}
/>
<Categories
scrollEmojiCategoryListToIndex={scrollEmojiCategoryListToIndex}
Expand Down

0 comments on commit a2db051

Please sign in to comment.