UNPKG

@react-navigation/material-top-tabs

Version:

Integration for the animated tab view component from react-native-tab-view

89 lines (88 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MaterialTopTabView = MaterialTopTabView; var _native = require("@react-navigation/native"); var _reactNativeTabView = require("react-native-tab-view"); var _TabAnimationContext = require("../utils/TabAnimationContext.js"); var _MaterialTopTabBar = require("./MaterialTopTabBar.js"); var _jsxRuntime = require("react/jsx-runtime"); const renderTabBarDefault = props => /*#__PURE__*/(0, _jsxRuntime.jsx)(_MaterialTopTabBar.MaterialTopTabBar, { ...props }); function MaterialTopTabView({ tabBar = renderTabBarDefault, state, navigation, descriptors, ...rest }) { const { colors } = (0, _native.useTheme)(); const { direction } = (0, _native.useLocale)(); const renderTabBar = ({ /* eslint-disable @typescript-eslint/no-unused-vars */ navigationState, options, /* eslint-enable @typescript-eslint/no-unused-vars */ ...rest }) => { return tabBar({ ...rest, state: state, navigation: navigation, descriptors: descriptors }); }; const focusedOptions = descriptors[state.routes[state.index].key].options; return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeTabView.TabView, { ...rest, onIndexChange: index => { const route = state.routes[index]; navigation.dispatch({ ..._native.CommonActions.navigate(route), target: state.key }); }, renderScene: ({ route, position }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabAnimationContext.TabAnimationContext.Provider, { value: { position }, children: descriptors[route.key].render() }), navigationState: state, renderTabBar: renderTabBar, renderLazyPlaceholder: ({ route }) => descriptors[route.key].options.lazyPlaceholder?.() ?? null, lazy: ({ route }) => descriptors[route.key].options.lazy === true && !state.preloadedRouteKeys.includes(route.key), lazyPreloadDistance: focusedOptions.lazyPreloadDistance, swipeEnabled: focusedOptions.swipeEnabled, animationEnabled: focusedOptions.animationEnabled, onSwipeStart: () => navigation.emit({ type: 'swipeStart' }), onSwipeEnd: () => navigation.emit({ type: 'swipeEnd' }), direction: direction, options: Object.fromEntries(state.routes.map(route => { const options = descriptors[route.key]?.options; return [route.key, { sceneStyle: [{ backgroundColor: colors.background }, options?.sceneStyle] }]; })) }); } //# sourceMappingURL=MaterialTopTabView.js.map