Skip to content

Instantly share code, notes, and snippets.

@manakuro
Created June 29, 2022 07:17
Show Gist options
  • Save manakuro/e90497c12386f6fb51d9d766a0a16578 to your computer and use it in GitHub Desktop.
Save manakuro/e90497c12386f6fb51d9d766a0a16578 to your computer and use it in GitHub Desktop.
import React, {forwardRef, useCallback} from 'react';
import {TouchableOpacity, Animated, View} from 'react-native';
type Props = {
onPress: (index: number) => void;
index: number;
opacity: Animated.AnimatedInterpolation;
ref: React.RefObject<any>;
children: React.ReactNode;
};
export const TabBarItem = forwardRef<any, Props>((props, ref) => {
const handlePress = useCallback(() => {
props.onPress(props.index);
}, [props]);
return (
<TouchableOpacity
style={{paddingHorizontal: 16, paddingTop: 16, alignItems: 'center'}}
onPress={handlePress}>
<View style={{paddingBottom: 4}} ref={ref}>
<Animated.Text
style={{color: 'white', fontSize: 16, opacity: props.opacity}}>
{props.children}
</Animated.Text>
</View>
</TouchableOpacity>
);
});
TabBarItem.displayName = 'TabBarItem';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment