UNPKG

@mindinventory/react-native-tab-bar-interaction

Version:
113 lines (109 loc) 3.25 kB
"use strict"; import { StyleSheet, Dimensions, Pressable, View } from 'react-native'; import Animated, { useAnimatedStyle, useSharedValue, withTiming, FadeIn } from 'react-native-reanimated'; import { getPathXCenterByIndex } from "./TabBar.js"; import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; const { width: SCREEN_WIDTH } = Dimensions.get('window'); const ICON_SIZE = 30; const LABEL_WIDTH = SCREEN_WIDTH / 4; const TRANSITION_SPEED = 400; export const TabItem = props => { const { curvedPaths, index, activeIndex = 1, label, onTabPress, activeIcon, currentIndex, inactiveIcon, transitionSpeed } = props; const animatedActiveIndex = useSharedValue(activeIndex); const iconPosition = getPathXCenterByIndex(curvedPaths, index); const tabStyle = useAnimatedStyle(() => { const translateY = animatedActiveIndex.value - 1 === index ? 20 : 20; const iconPositionX = iconPosition - index * ICON_SIZE; return { width: ICON_SIZE, height: ICON_SIZE, transform: [{ translateY: withTiming(translateY) }, { translateX: iconPositionX - ICON_SIZE / 2 }] }; }); // const iconColor = useSharedValue( // activeIndex === index + 1 ? 'white' : 'rgba(128,128,128,0.8)' // ); // //Adjust Icon color for this first render // useEffect(() => { // animatedActiveIndex.value = activeIndex; // if (activeIndex === index + 1) { // iconColor.value = withTiming('white', { // duration: transitionSpeed ? transitionSpeed : TRANSITION_SPEED, // }); // } else { // iconColor.value = withTiming('rgba(128,128,128,0.8)', { // duration: transitionSpeed ? transitionSpeed : TRANSITION_SPEED, // }); // } // }, [activeIndex, animatedActiveIndex, iconColor, index, transitionSpeed]); return /*#__PURE__*/_jsx(_Fragment, { children: currentIndex === index ? /*#__PURE__*/_jsx(Animated.View, { style: [tabStyle, styles.tabItem, styles.activeTabItem], children: /*#__PURE__*/_jsx(Pressable, { testID: `tab${label}` //Increasing touchable Area , hitSlop: { top: 30, bottom: 30, left: 50, right: 50 }, onPress: onTabPress, children: /*#__PURE__*/_jsx(Animated.View, { entering: FadeIn.delay(transitionSpeed ? transitionSpeed : TRANSITION_SPEED), children: activeIcon }) }) }) : /*#__PURE__*/_jsx(Animated.View, { style: [tabStyle, styles.tabItem], children: /*#__PURE__*/_jsx(Pressable, { testID: `tab${label}` //Increasing touchable Area , hitSlop: { top: 30, bottom: 30, left: 50, right: 50 }, onPress: onTabPress, children: /*#__PURE__*/_jsx(View, { children: inactiveIcon }) }) }) }); }; const styles = StyleSheet.create({ labelContainer: { position: 'absolute', alignItems: 'center', width: LABEL_WIDTH }, label: { color: 'rgba(128,128,128,0.8)', fontSize: 17 }, tabItem: {}, activeTabItem: { bottom: 25 } }); //# sourceMappingURL=TabItem.js.map