UNPKG

@freakycoder/animated-tabbar

Version:

A 60FPS animated tab bar with a variety of cool animation presets.

80 lines (75 loc) 3.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated")); var _reactNativeGestureHandler = require("react-native-gesture-handler"); var _hooks = require("../../hooks"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } const RawButton = ({ index, selectedIndex, accessibilityLabel, children, style, animatedOnChange, onLongPress, onLayout }) => { const rootViewRef = (0, _react.useRef)(null); const longPressGestureHandlerRef = (0, _react.useRef)(null); // Gesture handlers using Reanimated v3 const tapGestureHandler = (0, _reactNativeReanimated.useAnimatedGestureHandler)({ onEnd: () => { animatedOnChange(index); } }); const longPressGestureHandler = (0, _reactNativeReanimated.useAnimatedGestureHandler)({ onActive: () => { (0, _reactNativeReanimated.runOnJS)(onLongPress)(index); } }); // Animated reaction for accessibility changes (0, _reactNativeReanimated.useAnimatedReaction)(() => selectedIndex.value === index, (isSelected, wasSelected) => { if (isSelected !== wasSelected) { var _rootViewRef$current; (0, _reactNativeReanimated.runOnJS)((_rootViewRef$current = rootViewRef.current) === null || _rootViewRef$current === void 0 ? void 0 : _rootViewRef$current.setNativeProps)({ accessibilityState: { selected: isSelected } }); } }); // Layout handling callback const handleContainerLayout = (0, _hooks.useStableCallback)(({ nativeEvent: { layout } }) => onLayout && onLayout(index, layout)); // Animated styles if needed const animatedStyles = (0, _reactNativeReanimated.useAnimatedStyle)(() => { return { // Conditional styles or transitions can be added here }; }); return /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.GestureHandlerRootView, null, /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.TapGestureHandler, { ref: longPressGestureHandlerRef, onHandlerStateChange: tapGestureHandler }, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, { ref: rootViewRef, accessible: true, accessibilityLabel: accessibilityLabel, accessibilityRole: "button", accessibilityComponentType: "button", onLayout: handleContainerLayout, style: [style, animatedStyles] }, /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.LongPressGestureHandler, { onHandlerStateChange: longPressGestureHandler }, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, null, children))))); }; var _default = RawButton; exports.default = _default; //# sourceMappingURL=RawButton.js.map