mirror of
https://github.com/status-im/rn-emoji-keyboard.git
synced 2025-02-19 19:28:12 +00:00
refactor: temporary disable scroll and fix active category
This commit is contained in:
parent
4b72f5ec5b
commit
3acc45b21e
@ -6,8 +6,8 @@ import {
|
|||||||
FlatList,
|
FlatList,
|
||||||
useWindowDimensions,
|
useWindowDimensions,
|
||||||
Animated,
|
Animated,
|
||||||
NativeSyntheticEvent,
|
// NativeSyntheticEvent,
|
||||||
NativeScrollEvent,
|
// NativeScrollEvent,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { CATEGORIES, CategoryTypes } from './types';
|
import { CATEGORIES, CategoryTypes } from './types';
|
||||||
import { EmojiCategory } from './components/EmojiCategory';
|
import { EmojiCategory } from './components/EmojiCategory';
|
||||||
@ -20,7 +20,7 @@ export const EmojiKeyboard = () => {
|
|||||||
|
|
||||||
const flatListRef = React.useRef<FlatList>(null);
|
const flatListRef = React.useRef<FlatList>(null);
|
||||||
|
|
||||||
const scrollX = React.useRef(new Animated.Value(0)).current;
|
// const scrollX = React.useRef(new Animated.Value(0)).current;
|
||||||
const scrollNav = React.useRef(new Animated.Value(0)).current;
|
const scrollNav = React.useRef(new Animated.Value(0)).current;
|
||||||
|
|
||||||
const getItemLayout = (
|
const getItemLayout = (
|
||||||
@ -36,28 +36,36 @@ export const EmojiKeyboard = () => {
|
|||||||
(props) => <EmojiCategory {...props} />,
|
(props) => <EmojiCategory {...props} />,
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
const onScroll = Animated.event(
|
// const onScroll = Animated.event(
|
||||||
[{ nativeEvent: { contentOffset: { x: scrollX } } }],
|
// [{ nativeEvent: { contentOffset: { x: scrollX } } }],
|
||||||
{
|
// {
|
||||||
listener: ({
|
// listener: ({
|
||||||
nativeEvent: {
|
// nativeEvent: {
|
||||||
contentOffset: { x },
|
// contentOffset: { x },
|
||||||
},
|
// },
|
||||||
}: NativeSyntheticEvent<NativeScrollEvent>) => {
|
// }: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||||
|
// console.log(Math.round(x / width));
|
||||||
|
// ctx.setActiveCategoryIndex(Math.round(x / width));
|
||||||
|
// // Animated.spring(scrollNav, {
|
||||||
|
// // toValue: (x / width) * (28 + 9),
|
||||||
|
// // useNativeDriver: true,
|
||||||
|
// // }).start();
|
||||||
|
// },
|
||||||
|
// useNativeDriver: true,
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
React.useEffect(() => {
|
||||||
Animated.spring(scrollNav, {
|
Animated.spring(scrollNav, {
|
||||||
toValue: (x / width) * (28 + 9),
|
toValue: ctx.activeCategoryIndex * (28 + 9),
|
||||||
useNativeDriver: false,
|
useNativeDriver: true,
|
||||||
}).start();
|
}).start();
|
||||||
},
|
}, [ctx, scrollNav]);
|
||||||
useNativeDriver: false,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[styles.container, ctx.containerStyles]}>
|
<View style={[styles.container, ctx.containerStyles]}>
|
||||||
<FlatList
|
<Animated.FlatList
|
||||||
data={CATEGORIES}
|
data={CATEGORIES}
|
||||||
keyExtractor={(item) => item}
|
keyExtractor={(item: CategoryTypes) => item}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
removeClippedSubviews={true}
|
removeClippedSubviews={true}
|
||||||
ref={flatListRef}
|
ref={flatListRef}
|
||||||
@ -68,7 +76,8 @@ export const EmojiKeyboard = () => {
|
|||||||
scrollEventThrottle={16}
|
scrollEventThrottle={16}
|
||||||
decelerationRate="fast"
|
decelerationRate="fast"
|
||||||
getItemLayout={getItemLayout}
|
getItemLayout={getItemLayout}
|
||||||
onScroll={onScroll}
|
scrollEnabled={false}
|
||||||
|
// onScroll={onScroll}
|
||||||
/>
|
/>
|
||||||
<Categories flatListRef={flatListRef} scrollNav={scrollNav} />
|
<Categories flatListRef={flatListRef} scrollNav={scrollNav} />
|
||||||
</View>
|
</View>
|
||||||
|
@ -28,6 +28,15 @@ export const EmojiPicker = ({
|
|||||||
const { height: screenHeight } = useWindowDimensions();
|
const { height: screenHeight } = useWindowDimensions();
|
||||||
const offsetY = React.useRef(new Animated.Value(0)).current;
|
const offsetY = React.useRef(new Animated.Value(0)).current;
|
||||||
const height = React.useRef(new Animated.Value(screenHeight * 0.4)).current;
|
const height = React.useRef(new Animated.Value(screenHeight * 0.4)).current;
|
||||||
|
// const backdropOpacity = React.useRef(new Animated.Value(0)).current;
|
||||||
|
|
||||||
|
// React.useEffect(() => {
|
||||||
|
// Animated.timing(backdropOpacity, {
|
||||||
|
// toValue: isOpen ? 1 : 0,
|
||||||
|
// useNativeDriver: false,
|
||||||
|
// duration: 2000,
|
||||||
|
// }).start();
|
||||||
|
// }, [backdropOpacity, isOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KeyboardProvider
|
<KeyboardProvider
|
||||||
@ -37,6 +46,7 @@ export const EmojiPicker = ({
|
|||||||
onEmojiSelected(emoji);
|
onEmojiSelected(emoji);
|
||||||
onClose();
|
onClose();
|
||||||
}}
|
}}
|
||||||
|
isOpen={isOpen}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<Modal visible={isOpen} animationType="slide" transparent={true}>
|
<Modal visible={isOpen} animationType="slide" transparent={true}>
|
||||||
|
@ -10,6 +10,7 @@ export type KeyboardProps = {
|
|||||||
onEmojiSelected: (emoji: EmojiType) => void;
|
onEmojiSelected: (emoji: EmojiType) => void;
|
||||||
emojiSize?: number;
|
emojiSize?: number;
|
||||||
containerStyles?: ViewStyle;
|
containerStyles?: ViewStyle;
|
||||||
|
isOpen?: boolean;
|
||||||
};
|
};
|
||||||
export type ContextValues = {
|
export type ContextValues = {
|
||||||
activeCategoryIndex: number;
|
activeCategoryIndex: number;
|
||||||
|
@ -14,6 +14,7 @@ export const defaultKeyboardContext: Required<KeyboardProps> = {
|
|||||||
onEmojiSelected: (_emoji: EmojiType) => {},
|
onEmojiSelected: (_emoji: EmojiType) => {},
|
||||||
emojiSize: 24,
|
emojiSize: 24,
|
||||||
containerStyles: {},
|
containerStyles: {},
|
||||||
|
isOpen: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const defaultKeyboardValues: ContextValues = {
|
export const defaultKeyboardValues: ContextValues = {
|
||||||
@ -23,11 +24,11 @@ export const defaultKeyboardValues: ContextValues = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const KeyboardProvider: React.FC<ProviderProps> = React.memo((props) => {
|
export const KeyboardProvider: React.FC<ProviderProps> = React.memo((props) => {
|
||||||
const [activeCategoryIndex, setActive] = React.useState(0);
|
const [activeCategoryIndex, setActiveCategoryIndex] = React.useState(0);
|
||||||
|
|
||||||
const setActiveCategoryIndex = React.useCallback((index: number) => {
|
React.useEffect(() => {
|
||||||
setActive(index);
|
if (props.isOpen) setActiveCategoryIndex(0);
|
||||||
}, []);
|
}, [props.isOpen]);
|
||||||
|
|
||||||
const value: Required<KeyboardProps> & ContextValues = {
|
const value: Required<KeyboardProps> & ContextValues = {
|
||||||
...defaultKeyboardContext,
|
...defaultKeyboardContext,
|
||||||
|
@ -33,7 +33,15 @@ export const Categories = ({ flatListRef, scrollNav }: CategoriesProps) => {
|
|||||||
|
|
||||||
const activeIndicator = React.useCallback(
|
const activeIndicator = React.useCallback(
|
||||||
() => (
|
() => (
|
||||||
<Animated.View style={[styles.activeIndicator, { left: scrollNav }]} />
|
// <Animated.View style={[styles.activeIndicator, { left: scrollNav }]} />
|
||||||
|
<Animated.View
|
||||||
|
style={[
|
||||||
|
styles.activeIndicator,
|
||||||
|
{
|
||||||
|
transform: [{ translateX: scrollNav }],
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
),
|
),
|
||||||
[scrollNav]
|
[scrollNav]
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user