Created
June 29, 2022 07:17
-
-
Save manakuro/e90497c12386f6fb51d9d766a0a16578 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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