Skip to content

Commit

Permalink
fix: updating active category on scroll, clear emoji tones on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
mateki0 authored and jakex7 committed Jun 18, 2023
1 parent 0ee72b3 commit 6c3b86c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/EmojiStaticKeyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,16 @@ export const EmojiStaticKeyboard = React.memo(
(el: NativeSyntheticEvent<NativeScrollEvent>) => {
const index = el.nativeEvent.contentOffset.x / width
scrollNav.setValue(index * CATEGORY_ELEMENT_WIDTH)
if (Number.isInteger(index)) setActiveCategoryIndex(index)
},
[scrollNav, setActiveCategoryIndex, width]
[scrollNav, width]
)

const onScrollEnd = React.useCallback(
(el: NativeSyntheticEvent<NativeScrollEvent>) => {
const index = el.nativeEvent.contentOffset.x / width
setActiveCategoryIndex(Math.round(index))
},
[setActiveCategoryIndex, width]
)

return (
Expand Down Expand Up @@ -114,6 +121,7 @@ export const EmojiStaticKeyboard = React.memo(
maxToRenderPerBatch={1}
onScroll={handleScroll}
keyboardShouldPersistTaps="handled"
onMomentumScrollEnd={onScrollEnd}
/>
<Categories scrollNav={enableCategoryChangeGesture ? scrollNav : undefined} />
<SkinTones keyboardScrollOffsetY={keyboardScrollOffsetY} />
Expand Down
4 changes: 4 additions & 0 deletions src/contexts/KeyboardProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export const KeyboardProvider: React.FC<ProviderProps> = React.memo((props) => {

const clearEmojiTonesData = () => setEmojiTonesData(null)

React.useEffect(() => {
clearEmojiTonesData()
}, [activeCategoryIndex])

React.useEffect(() => {
if (props.open) setActiveCategoryIndex(0)
setSearchPhrase('')
Expand Down

0 comments on commit 6c3b86c

Please sign in to comment.