Skip to content

Commit

Permalink
chore: setActiveCategoryIndex was called twice on category change (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateki0 authored Jun 18, 2023
1 parent d859b34 commit 0ee72b3
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/components/Categories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { Animated, FlatList, StyleSheet, View, ViewStyle } from 'react-native'
import { KeyboardContext } from '../contexts/KeyboardContext'
import { CATEGORIES_NAVIGATION, CategoryNavigationItem, CategoryTypes } from '../types'
import { CATEGORIES_NAVIGATION, CategoryNavigationItem } from '../types'
import { CategoryItem } from './CategoryItem'
import { exhaustiveTypeCheck } from '../utils/exhaustiveTypeCheck'
import { defaultTheme } from '../contexts/KeyboardContext'
Expand All @@ -20,28 +20,18 @@ export const Categories = (p: Props) => {
onCategoryChangeFailed,
categoryPosition,
renderList,
setActiveCategoryIndex,
clearEmojiTonesData,
theme,
styles: themeStyles,
enableCategoryChangeAnimation,
setShouldAnimateScroll,
} = React.useContext(KeyboardContext)

const scrollNav = React.useRef(new Animated.Value(0)).current
const handleScrollToCategory = React.useCallback(
(category: CategoryTypes) => {
clearEmojiTonesData()
setActiveCategoryIndex(renderList.findIndex((cat) => cat.title === category))
setShouldAnimateScroll(enableCategoryChangeAnimation)
},
[
clearEmojiTonesData,
setActiveCategoryIndex,
renderList,
setShouldAnimateScroll,
enableCategoryChangeAnimation,
]
)
const handleScrollToCategory = React.useCallback(() => {
clearEmojiTonesData()
setShouldAnimateScroll(enableCategoryChangeAnimation)
}, [clearEmojiTonesData, setShouldAnimateScroll, enableCategoryChangeAnimation])

const renderItem = React.useCallback(
({ item, index }: { item: CategoryNavigationItem; index: number }) => (
Expand Down

0 comments on commit 0ee72b3

Please sign in to comment.