Skip to content

Commit

Permalink
Fix/emoji tones bugs (#137)
Browse files Browse the repository at this point in the history
* fix: updating active category on scroll, clear emoji tones on scroll

* fix: add reseting tones box position on category change

* chore: deletes unneccesary clearEmojiTones
  • Loading branch information
mateki0 committed Jun 18, 2023
1 parent 0ee72b3 commit bfb10ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/components/Categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const Categories = (p: Props) => {
onCategoryChangeFailed,
categoryPosition,
renderList,
clearEmojiTonesData,
theme,
styles: themeStyles,
enableCategoryChangeAnimation,
Expand All @@ -29,9 +28,8 @@ export const Categories = (p: Props) => {

const scrollNav = React.useRef(new Animated.Value(0)).current
const handleScrollToCategory = React.useCallback(() => {
clearEmojiTonesData()
setShouldAnimateScroll(enableCategoryChangeAnimation)
}, [clearEmojiTonesData, setShouldAnimateScroll, enableCategoryChangeAnimation])
}, [setShouldAnimateScroll, enableCategoryChangeAnimation])

const renderItem = React.useCallback(
({ item, index }: { item: CategoryNavigationItem; index: number }) => (
Expand Down
13 changes: 11 additions & 2 deletions src/components/EmojiStaticKeyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const EmojiStaticKeyboard = React.memo(
index: activeCategoryIndex,
animated: shouldAnimateScroll && enableCategoryChangeAnimation,
})
setKeyboardScrollOffsetY(0)
}, [activeCategoryIndex, enableCategoryChangeAnimation, shouldAnimateScroll])

const keyExtractor = React.useCallback((item: EmojisByCategory) => item.title, [])
Expand All @@ -72,9 +73,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 +122,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 bfb10ec

Please sign in to comment.