Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: categories index change #179

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
} = 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 @@
[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 All @@ -130,7 +139,7 @@
>
<ConditionalContainer
condition={!disableSafeArea}
container={(children) => (

Check warning on line 142 in src/components/EmojiStaticKeyboard.tsx

View workflow job for this annotation

GitHub Actions / eslint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
<SafeAreaView
style={[styles.flex, categoryPosition === 'top' && styles.containerReverse]}
>
Expand Down Expand Up @@ -169,7 +178,8 @@
maxToRenderPerBatch={1}
onScroll={handleScroll}
keyboardShouldPersistTaps="handled"
onMomentumScrollEnd={onScrollEnd}
onMomentumScrollBegin={onMomentumScrollBegin}
onMomentumScrollEnd={onMomentumScrollEnd}
/>
<Categories
scrollEmojiCategoryListToIndex={scrollEmojiCategoryListToIndex}
Expand Down