UNPKG

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

Version:
120 lines (116 loc) 4.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TabItem = void 0; var _reactNative = require("react-native"); var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated")); var _TabBar = require("./TabBar.js"); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const { width: SCREEN_WIDTH } = _reactNative.Dimensions.get('window'); const ICON_SIZE = 30; const LABEL_WIDTH = SCREEN_WIDTH / 4; const TRANSITION_SPEED = 400; const TabItem = props => { const { curvedPaths, index, activeIndex = 1, label, onTabPress, activeIcon, currentIndex, inactiveIcon, transitionSpeed } = props; const animatedActiveIndex = (0, _reactNativeReanimated.useSharedValue)(activeIndex); const iconPosition = (0, _TabBar.getPathXCenterByIndex)(curvedPaths, index); const tabStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => { const translateY = animatedActiveIndex.value - 1 === index ? 20 : 20; const iconPositionX = iconPosition - index * ICON_SIZE; return { width: ICON_SIZE, height: ICON_SIZE, transform: [{ translateY: (0, _reactNativeReanimated.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__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, { children: currentIndex === index ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, { style: [tabStyle, styles.tabItem, styles.activeTabItem], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, { testID: `tab${label}` //Increasing touchable Area , hitSlop: { top: 30, bottom: 30, left: 50, right: 50 }, onPress: onTabPress, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, { entering: _reactNativeReanimated.FadeIn.delay(transitionSpeed ? transitionSpeed : TRANSITION_SPEED), children: activeIcon }) }) }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, { style: [tabStyle, styles.tabItem], children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, { testID: `tab${label}` //Increasing touchable Area , hitSlop: { top: 30, bottom: 30, left: 50, right: 50 }, onPress: onTabPress, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { children: inactiveIcon }) }) }) }); }; exports.TabItem = TabItem; const styles = _reactNative.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