react-native-tab-view 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/lib/commonjs/PagerViewAdapter.js +25 -8
- package/lib/commonjs/PagerViewAdapter.js.map +1 -1
- package/lib/commonjs/PanResponderAdapter.js +29 -20
- package/lib/commonjs/PanResponderAdapter.js.map +1 -1
- package/lib/commonjs/SceneMap.js +9 -12
- package/lib/commonjs/SceneMap.js.map +1 -1
- package/lib/commonjs/SceneView.js +54 -101
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/TabBar.js +327 -327
- package/lib/commonjs/TabBar.js.map +1 -1
- package/lib/commonjs/TabBarIndicator.js +81 -99
- package/lib/commonjs/TabBarIndicator.js.map +1 -1
- package/lib/commonjs/TabBarItem.js +184 -161
- package/lib/commonjs/TabBarItem.js.map +1 -1
- package/lib/commonjs/TabView.js +3 -1
- package/lib/commonjs/TabView.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/PagerViewAdapter.js +25 -8
- package/lib/module/PagerViewAdapter.js.map +1 -1
- package/lib/module/PanResponderAdapter.js +29 -19
- package/lib/module/PanResponderAdapter.js.map +1 -1
- package/lib/module/SceneMap.js +9 -14
- package/lib/module/SceneMap.js.map +1 -1
- package/lib/module/SceneView.js +53 -98
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/TabBar.js +323 -323
- package/lib/module/TabBar.js.map +1 -1
- package/lib/module/TabBarIndicator.js +74 -92
- package/lib/module/TabBarIndicator.js.map +1 -1
- package/lib/module/TabBarItem.js +178 -154
- package/lib/module/TabBarItem.js.map +1 -1
- package/lib/module/TabView.js +3 -1
- package/lib/module/TabView.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/PagerViewAdapter.d.ts +1 -1
- package/lib/typescript/PanResponderAdapter.d.ts +1 -1
- package/lib/typescript/SceneMap.d.ts +5 -3
- package/lib/typescript/SceneView.d.ts +1 -18
- package/lib/typescript/TabBar.d.ts +7 -38
- package/lib/typescript/TabBarIndicator.d.ts +2 -10
- package/lib/typescript/TabBarItem.d.ts +3 -5
- package/lib/typescript/TabView.d.ts +1 -1
- package/lib/typescript/types.d.ts +1 -0
- package/package.json +4 -1
- package/src/PagerViewAdapter.tsx +29 -10
- package/src/PanResponderAdapter.tsx +29 -20
- package/src/SceneMap.tsx +11 -7
- package/src/SceneView.tsx +70 -106
- package/src/TabBar.tsx +451 -391
- package/src/TabBarIndicator.tsx +108 -114
- package/src/TabBarItem.tsx +214 -185
- package/src/TabView.tsx +2 -0
- package/src/types.tsx +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Separator","width","TabBar","React","Component","layout","height","tabWidths","Animated","Value","createRef","style","tabStyle","StyleSheet","flatten","undefined","index","routes","scrollEnabled","flattenedWidth","key","endsWith","parseFloat","Number","isFinite","length","tabBarWidth","layoutWidth","props","state","navigationState","reduce","acc","_","i","gap","getComputedTabWidth","getFlattenedTabWidth","value","getTabBarWidth","maxDistance","getMaxScrollDistance","scrollValue","Math","max","min","Platform","OS","I18nManager","isRTL","centerDistance","Array","from","total","tabWidth","scrollAmount","normalizeScrollValue","flatListRef","current","scrollToOffset","offset","getScrollAmount","animated","e","nativeEvent","setState","maxScrollDistance","multiply","add","componentDidUpdate","prevProps","prevState","every","r","resetScroll","render","position","jumpTo","bounces","getAccessibilityLabel","getAccessible","getLabelText","getTestID","renderBadge","renderIcon","renderLabel","renderTabBarItem","activeColor","inactiveColor","pressColor","pressOpacity","onTabPress","onTabLongPress","labelStyle","indicatorStyle","contentContainerStyle","indicatorContainerStyle","isWidthDynamic","separatorsWidth","separatorPercent","tabBarWidthPercent","translateX","getTranslateX","handleLayout","styles","tabBar","indicatorContainer","transform","renderIndicator","getTabWidth","scroll","item","tabContent","container","route","onLayout","measuredTabWidths","onPress","event","defaultPrevented","preventDefault","onLongPress","contentOffset","x","useNativeDriver","title","accessible","accessibilityLabel","testID","create","flex","overflow","select","default","web","backgroundColor","elevation","shadowColor","shadowOpacity","shadowRadius","hairlineWidth","shadowOffset","zIndex","flexDirection","flexWrap","top","left","right","bottom"],"sources":["TabBar.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n StyleSheet,\n View,\n StyleProp,\n ViewStyle,\n TextStyle,\n LayoutChangeEvent,\n I18nManager,\n Platform,\n FlatList,\n ListRenderItemInfo,\n} from 'react-native';\nimport TabBarItem, { Props as TabBarItemProps } from './TabBarItem';\nimport TabBarIndicator, { Props as IndicatorProps } from './TabBarIndicator';\nimport type {\n Route,\n Scene,\n SceneRendererProps,\n NavigationState,\n Layout,\n Event,\n} from './types';\n\nexport type Props<T extends Route> = SceneRendererProps & {\n navigationState: NavigationState<T>;\n scrollEnabled?: boolean;\n bounces?: boolean;\n activeColor?: string;\n inactiveColor?: string;\n pressColor?: string;\n pressOpacity?: number;\n getLabelText: (scene: Scene<T>) => string | undefined;\n getAccessible: (scene: Scene<T>) => boolean | undefined;\n getAccessibilityLabel: (scene: Scene<T>) => string | undefined;\n getTestID: (scene: Scene<T>) => string | undefined;\n renderLabel?: (\n scene: Scene<T> & {\n focused: boolean;\n color: string;\n }\n ) => React.ReactNode;\n renderIcon?: (\n scene: Scene<T> & {\n focused: boolean;\n color: string;\n }\n ) => React.ReactNode;\n renderBadge?: (scene: Scene<T>) => React.ReactNode;\n renderIndicator: (props: IndicatorProps<T>) => React.ReactNode;\n renderTabBarItem?: (\n props: TabBarItemProps<T> & { key: string }\n ) => React.ReactElement;\n onTabPress?: (scene: Scene<T> & Event) => void;\n onTabLongPress?: (scene: Scene<T>) => void;\n tabStyle?: StyleProp<ViewStyle>;\n indicatorStyle?: StyleProp<ViewStyle>;\n indicatorContainerStyle?: StyleProp<ViewStyle>;\n labelStyle?: StyleProp<TextStyle>;\n contentContainerStyle?: StyleProp<ViewStyle>;\n style?: StyleProp<ViewStyle>;\n gap?: number;\n};\n\ntype State = {\n layout: Layout;\n tabWidths: { [key: string]: number };\n};\n\nconst Separator = ({ width }: { width: number }) => {\n return <View style={{ width }} />;\n};\n\nexport default class TabBar<T extends Route> extends React.Component<\n Props<T>,\n State\n> {\n static defaultProps = {\n getLabelText: ({ route }: Scene<Route>) => route.title,\n getAccessible: ({ route }: Scene<Route>) =>\n typeof route.accessible !== 'undefined' ? route.accessible : true,\n getAccessibilityLabel: ({ route }: Scene<Route>) =>\n typeof route.accessibilityLabel === 'string'\n ? route.accessibilityLabel\n : typeof route.title === 'string'\n ? route.title\n : undefined,\n getTestID: ({ route }: Scene<Route>) => route.testID,\n renderIndicator: (props: IndicatorProps<Route>) => (\n <TabBarIndicator {...props} />\n ),\n gap: 0,\n };\n\n state: State = {\n layout: { width: 0, height: 0 },\n tabWidths: {},\n };\n\n componentDidUpdate(prevProps: Props<T>, prevState: State) {\n const { navigationState } = this.props;\n const { layout, tabWidths } = this.state;\n\n if (\n prevProps.navigationState.routes.length !==\n navigationState.routes.length ||\n prevProps.navigationState.index !== navigationState.index ||\n prevState.layout.width !== layout.width ||\n prevState.tabWidths !== tabWidths\n ) {\n if (\n this.getFlattenedTabWidth(this.props.tabStyle) === 'auto' &&\n !(\n layout.width &&\n navigationState.routes.every(\n (r) => typeof tabWidths[r.key] === 'number'\n )\n )\n ) {\n // When tab width is dynamic, only adjust the scroll once we have all tab widths and layout\n return;\n }\n\n this.resetScroll(navigationState.index);\n }\n }\n\n // to store the layout.width of each tab\n // when all onLayout's are fired, this would be set in state\n private measuredTabWidths: { [key: string]: number } = {};\n\n private scrollAmount = new Animated.Value(0);\n\n private flatListRef = React.createRef<FlatList>();\n\n private getFlattenedTabWidth = (style: StyleProp<ViewStyle>) => {\n const tabStyle = StyleSheet.flatten(style);\n\n return tabStyle ? tabStyle.width : undefined;\n };\n\n private getComputedTabWidth = (\n index: number,\n layout: Layout,\n routes: Route[],\n scrollEnabled: boolean | undefined,\n tabWidths: { [key: string]: number },\n flattenedWidth: string | number | undefined\n ) => {\n if (flattenedWidth === 'auto') {\n return tabWidths[routes[index].key] || 0;\n }\n\n switch (typeof flattenedWidth) {\n case 'number':\n return flattenedWidth;\n case 'string':\n if (flattenedWidth.endsWith('%')) {\n const width = parseFloat(flattenedWidth);\n if (Number.isFinite(width)) {\n return layout.width * (width / 100);\n }\n }\n }\n\n if (scrollEnabled) {\n return (layout.width / 5) * 2;\n }\n return layout.width / routes.length;\n };\n\n private getMaxScrollDistance = (tabBarWidth: number, layoutWidth: number) =>\n tabBarWidth - layoutWidth;\n\n private getTabBarWidth = (props: Props<T>, state: State) => {\n const { layout, tabWidths } = state;\n const { scrollEnabled, tabStyle } = props;\n const { routes } = props.navigationState;\n\n return routes.reduce<number>(\n (acc, _, i) =>\n acc +\n (i > 0 ? props.gap ?? 0 : 0) +\n this.getComputedTabWidth(\n i,\n layout,\n routes,\n scrollEnabled,\n tabWidths,\n this.getFlattenedTabWidth(tabStyle)\n ),\n 0\n );\n };\n\n private normalizeScrollValue = (\n props: Props<T>,\n state: State,\n value: number\n ) => {\n const { layout } = state;\n const tabBarWidth = this.getTabBarWidth(props, state);\n const maxDistance = this.getMaxScrollDistance(tabBarWidth, layout.width);\n const scrollValue = Math.max(Math.min(value, maxDistance), 0);\n\n if (Platform.OS === 'android' && I18nManager.isRTL) {\n // On Android, scroll value is not applied in reverse in RTL\n // so we need to manually adjust it to apply correct value\n return maxDistance - scrollValue;\n }\n\n return scrollValue;\n };\n\n private getScrollAmount = (props: Props<T>, state: State, index: number) => {\n const { layout, tabWidths } = state;\n const { scrollEnabled, tabStyle } = props;\n const { routes } = props.navigationState;\n\n const centerDistance = Array.from({ length: index + 1 }).reduce<number>(\n (total, _, i) => {\n const tabWidth = this.getComputedTabWidth(\n i,\n layout,\n routes,\n scrollEnabled,\n tabWidths,\n this.getFlattenedTabWidth(tabStyle)\n );\n\n // To get the current index centered we adjust scroll amount by width of indexes\n // 0 through (i - 1) and add half the width of current index i\n return (\n total +\n (index === i\n ? (tabWidth + (props.gap ?? 0)) / 2\n : tabWidth + (props.gap ?? 0))\n );\n },\n 0\n );\n\n const scrollAmount = centerDistance - layout.width / 2;\n\n return this.normalizeScrollValue(props, state, scrollAmount);\n };\n\n private resetScroll = (index: number) => {\n if (this.props.scrollEnabled) {\n this.flatListRef.current?.scrollToOffset({\n offset: this.getScrollAmount(this.props, this.state, index),\n animated: true,\n });\n }\n };\n\n private handleLayout = (e: LayoutChangeEvent) => {\n const { height, width } = e.nativeEvent.layout;\n\n if (\n this.state.layout.width === width &&\n this.state.layout.height === height\n ) {\n return;\n }\n\n this.setState({\n layout: {\n height,\n width,\n },\n });\n };\n\n private getTranslateX = (\n scrollAmount: Animated.Value,\n maxScrollDistance: number\n ) =>\n Animated.multiply(\n Platform.OS === 'android' && I18nManager.isRTL\n ? Animated.add(maxScrollDistance, Animated.multiply(scrollAmount, -1))\n : scrollAmount,\n I18nManager.isRTL ? 1 : -1\n );\n\n render() {\n const {\n position,\n navigationState,\n jumpTo,\n scrollEnabled,\n bounces,\n getAccessibilityLabel,\n getAccessible,\n getLabelText,\n getTestID,\n renderBadge,\n renderIcon,\n renderLabel,\n renderTabBarItem,\n activeColor,\n inactiveColor,\n pressColor,\n pressOpacity,\n onTabPress,\n onTabLongPress,\n tabStyle,\n labelStyle,\n indicatorStyle,\n contentContainerStyle,\n style,\n indicatorContainerStyle,\n gap = 0,\n } = this.props;\n const { layout, tabWidths } = this.state;\n const { routes } = navigationState;\n\n const isWidthDynamic = this.getFlattenedTabWidth(tabStyle) === 'auto';\n const tabBarWidth = this.getTabBarWidth(this.props, this.state);\n const separatorsWidth = Math.max(0, routes.length - 1) * gap;\n const separatorPercent = (separatorsWidth / tabBarWidth) * 100;\n\n const tabBarWidthPercent = `${routes.length * 40}%`;\n const translateX = this.getTranslateX(\n this.scrollAmount,\n this.getMaxScrollDistance(tabBarWidth, layout.width)\n );\n\n return (\n <Animated.View\n onLayout={this.handleLayout}\n style={[styles.tabBar, style]}\n >\n <Animated.View\n pointerEvents=\"none\"\n style={[\n styles.indicatorContainer,\n scrollEnabled ? { transform: [{ translateX }] as any } : null,\n tabBarWidth > separatorsWidth\n ? { width: tabBarWidth - separatorsWidth }\n : scrollEnabled\n ? { width: tabBarWidthPercent }\n : null,\n indicatorContainerStyle,\n ]}\n >\n {this.props.renderIndicator({\n position,\n layout,\n navigationState,\n jumpTo,\n width: isWidthDynamic\n ? 'auto'\n : `${(100 - separatorPercent) / routes.length}%`,\n style: indicatorStyle,\n getTabWidth: (i: number) =>\n this.getComputedTabWidth(\n i,\n layout,\n routes,\n scrollEnabled,\n tabWidths,\n this.getFlattenedTabWidth(tabStyle)\n ),\n gap,\n })}\n </Animated.View>\n <View style={styles.scroll}>\n <Animated.FlatList\n data={routes as Animated.WithAnimatedValue<T>[]}\n keyExtractor={(item) => item.key}\n horizontal\n accessibilityRole=\"tablist\"\n keyboardShouldPersistTaps=\"handled\"\n scrollEnabled={scrollEnabled}\n bounces={bounces}\n alwaysBounceHorizontal={false}\n scrollsToTop={false}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={false}\n automaticallyAdjustContentInsets={false}\n overScrollMode=\"never\"\n contentContainerStyle={[\n styles.tabContent,\n scrollEnabled\n ? {\n width:\n tabBarWidth > separatorsWidth\n ? tabBarWidth\n : tabBarWidthPercent,\n }\n : styles.container,\n contentContainerStyle,\n ]}\n scrollEventThrottle={16}\n renderItem={({ item: route, index }: ListRenderItemInfo<T>) => {\n const props: TabBarItemProps<T> & { key: string } = {\n key: route.key,\n position: position,\n route: route,\n navigationState: navigationState,\n getAccessibilityLabel: getAccessibilityLabel,\n getAccessible: getAccessible,\n getLabelText: getLabelText,\n getTestID: getTestID,\n renderBadge: renderBadge,\n renderIcon: renderIcon,\n renderLabel: renderLabel,\n activeColor: activeColor,\n inactiveColor: inactiveColor,\n pressColor: pressColor,\n pressOpacity: pressOpacity,\n onLayout: isWidthDynamic\n ? (e) => {\n this.measuredTabWidths[route.key] =\n e.nativeEvent.layout.width;\n\n // When we have measured widths for all of the tabs, we should updates the state\n // We avoid doing separate setState for each layout since it triggers multiple renders and slows down app\n if (\n routes.every(\n (r) =>\n typeof this.measuredTabWidths[r.key] === 'number'\n )\n ) {\n this.setState({\n tabWidths: { ...this.measuredTabWidths },\n });\n }\n }\n : undefined,\n onPress: () => {\n const event: Scene<T> & Event = {\n route,\n defaultPrevented: false,\n preventDefault: () => {\n event.defaultPrevented = true;\n },\n };\n\n onTabPress?.(event);\n\n if (event.defaultPrevented) {\n return;\n }\n\n this.props.jumpTo(route.key);\n },\n onLongPress: () => onTabLongPress?.({ route }),\n labelStyle: labelStyle,\n style: [\n tabStyle,\n // Calculate the deafult width for tab for FlatList to work.\n this.getFlattenedTabWidth(tabStyle) === undefined && {\n width: this.getComputedTabWidth(\n index,\n layout,\n routes,\n scrollEnabled,\n tabWidths,\n this.getFlattenedTabWidth(tabStyle)\n ),\n },\n ],\n };\n\n return (\n <React.Fragment key={route.key}>\n {gap > 0 && index > 0 ? <Separator width={gap} /> : null}\n {renderTabBarItem ? (\n renderTabBarItem(props)\n ) : (\n <TabBarItem {...props} />\n )}\n </React.Fragment>\n );\n }}\n onScroll={Animated.event(\n [\n {\n nativeEvent: {\n contentOffset: { x: this.scrollAmount },\n },\n },\n ],\n { useNativeDriver: true }\n )}\n ref={this.flatListRef}\n />\n </View>\n </Animated.View>\n );\n }\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n },\n scroll: {\n overflow: Platform.select({ default: 'scroll', web: undefined }),\n },\n tabBar: {\n backgroundColor: '#2196f3',\n elevation: 4,\n shadowColor: 'black',\n shadowOpacity: 0.1,\n shadowRadius: StyleSheet.hairlineWidth,\n shadowOffset: {\n height: StyleSheet.hairlineWidth,\n width: 0,\n },\n zIndex: 1,\n },\n tabContent: {\n flexDirection: 'row',\n flexWrap: 'nowrap',\n },\n indicatorContainer: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n },\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;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c,MAAnC;EAAA,CAVS;EAWpBpB,eAAe,EAAGhF,KAAD,iBACf,oBAAC,wBAAD,EAAqBA,KAArB,CAZkB;EAcpBO,GAAG,EAAE;AAde,C;;AAkaxB,MAAMqE,MAAM,GAAG3F,uBAAA,CAAWoH,MAAX,CAAkB;EAC/BhB,SAAS,EAAE;IACTiB,IAAI,EAAE;EADG,CADoB;EAI/BpB,MAAM,EAAE;IACNqB,QAAQ,EAAErF,qBAAA,CAASsF,MAAT,CAAgB;MAAEC,OAAO,EAAE,QAAX;MAAqBC,GAAG,EAAEvH;IAA1B,CAAhB;EADJ,CAJuB;EAO/B0F,MAAM,EAAE;IACN8B,eAAe,EAAE,SADX;IAENC,SAAS,EAAE,CAFL;IAGNC,WAAW,EAAE,OAHP;IAINC,aAAa,EAAE,GAJT;IAKNC,YAAY,EAAE9H,uBAAA,CAAW+H,aALnB;IAMNC,YAAY,EAAE;MACZvI,MAAM,EAAEO,uBAAA,CAAW+H,aADP;MAEZ3I,KAAK,EAAE;IAFK,CANR;IAUN6I,MAAM,EAAE;EAVF,CAPuB;EAmB/B9B,UAAU,EAAE;IACV+B,aAAa,EAAE,KADL;IAEVC,QAAQ,EAAE;EAFA,CAnBmB;EAuB/BtC,kBAAkB,EAAE;IAClB9B,QAAQ,EAAE,UADQ;IAElBqE,GAAG,EAAE,CAFa;IAGlBC,IAAI,EAAE,CAHY;IAIlBC,KAAK,EAAE,CAJW;IAKlBC,MAAM,EAAE;EALU;AAvBW,CAAlB,CAAf"}
|
|
1
|
+
{"version":3,"names":["Separator","width","getFlattenedTabWidth","style","tabStyle","StyleSheet","flatten","getComputedTabWidth","index","layout","routes","scrollEnabled","tabWidths","flattenedWidth","key","endsWith","parseFloat","Number","isFinite","length","getMaxScrollDistance","tabBarWidth","layoutWidth","getTranslateX","scrollAmount","maxScrollDistance","Animated","multiply","Platform","OS","I18nManager","isRTL","add","getTabBarWidth","navigationState","gap","flattenedTabWidth","reduce","acc","_","i","normalizeScrollValue","value","maxDistance","scrollValue","Math","max","min","getScrollAmount","centerDistance","Array","from","total","tabWidth","getLabelTextDefault","route","title","getAccessibleDefault","accessible","getAccessibilityLabelDefault","accessibilityLabel","undefined","renderIndicatorDefault","props","getTestIdDefault","testID","TabBar","getLabelText","getAccessible","getAccessibilityLabel","getTestID","renderIndicator","jumpTo","position","activeColor","bounces","contentContainerStyle","inactiveColor","indicatorContainerStyle","indicatorStyle","labelStyle","onTabLongPress","onTabPress","pressColor","pressOpacity","renderBadge","renderIcon","renderLabel","renderTabBarItem","setLayout","React","useState","height","setTabWidths","flatListRef","useRef","isFirst","useAnimatedValue","measuredTabWidths","isWidthDynamic","scrollOffset","hasMeasuredTabWidths","Boolean","every","r","useEffect","current","scrollToOffset","offset","animated","handleLayout","e","nativeEvent","separatorsWidth","separatorPercent","tabBarWidthPercent","translateX","useMemo","renderItem","useCallback","item","onLayout","onPress","event","defaultPrevented","preventDefault","onLongPress","defaultTabWidth","keyExtractor","contentContainerStyleMemoized","styles","tabContent","container","handleScroll","contentOffset","x","useNativeDriver","tabBar","indicatorContainer","transform","getTabWidth","scroll","create","flex","overflow","select","default","web","backgroundColor","elevation","shadowColor","shadowOpacity","shadowRadius","hairlineWidth","shadowOffset","zIndex","flexDirection","flexWrap","top","left","right","bottom"],"sources":["TabBar.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n StyleSheet,\n View,\n StyleProp,\n ViewStyle,\n TextStyle,\n LayoutChangeEvent,\n I18nManager,\n Platform,\n FlatList,\n ListRenderItemInfo,\n} from 'react-native';\nimport TabBarItem, { Props as TabBarItemProps } from './TabBarItem';\nimport TabBarIndicator, { Props as IndicatorProps } from './TabBarIndicator';\nimport type {\n Route,\n Scene,\n SceneRendererProps,\n NavigationState,\n Layout,\n Event,\n} from './types';\nimport useAnimatedValue from './useAnimatedValue';\n\nexport type Props<T extends Route> = SceneRendererProps & {\n navigationState: NavigationState<T>;\n scrollEnabled?: boolean;\n bounces?: boolean;\n activeColor?: string;\n inactiveColor?: string;\n pressColor?: string;\n pressOpacity?: number;\n getLabelText?: (scene: Scene<T>) => string | undefined;\n getAccessible?: (scene: Scene<T>) => boolean | undefined;\n getAccessibilityLabel?: (scene: Scene<T>) => string | undefined;\n getTestID?: (scene: Scene<T>) => string | undefined;\n renderLabel?: (\n scene: Scene<T> & {\n focused: boolean;\n color: string;\n }\n ) => React.ReactNode;\n renderIcon?: (\n scene: Scene<T> & {\n focused: boolean;\n color: string;\n }\n ) => React.ReactNode;\n renderBadge?: (scene: Scene<T>) => React.ReactNode;\n renderIndicator?: (props: IndicatorProps<T>) => React.ReactNode;\n renderTabBarItem?: (\n props: TabBarItemProps<T> & { key: string }\n ) => React.ReactElement;\n onTabPress?: (scene: Scene<T> & Event) => void;\n onTabLongPress?: (scene: Scene<T>) => void;\n tabStyle?: StyleProp<ViewStyle>;\n indicatorStyle?: StyleProp<ViewStyle>;\n indicatorContainerStyle?: StyleProp<ViewStyle>;\n labelStyle?: StyleProp<TextStyle>;\n contentContainerStyle?: StyleProp<ViewStyle>;\n style?: StyleProp<ViewStyle>;\n gap?: number;\n};\n\ntype FlattenedTabWidth = string | number | undefined;\n\nconst Separator = ({ width }: { width: number }) => {\n return <View style={{ width }} />;\n};\n\nconst getFlattenedTabWidth = (style: StyleProp<ViewStyle>) => {\n const tabStyle = StyleSheet.flatten(style);\n\n return tabStyle?.width;\n};\n\nconst getComputedTabWidth = (\n index: number,\n layout: Layout,\n routes: Route[],\n scrollEnabled: boolean | undefined,\n tabWidths: { [key: string]: number },\n flattenedWidth: FlattenedTabWidth\n) => {\n if (flattenedWidth === 'auto') {\n return tabWidths[routes[index].key] || 0;\n }\n\n switch (typeof flattenedWidth) {\n case 'number':\n return flattenedWidth;\n case 'string':\n if (flattenedWidth.endsWith('%')) {\n const width = parseFloat(flattenedWidth);\n if (Number.isFinite(width)) {\n return layout.width * (width / 100);\n }\n }\n }\n\n if (scrollEnabled) {\n return (layout.width / 5) * 2;\n }\n return layout.width / routes.length;\n};\n\nconst getMaxScrollDistance = (tabBarWidth: number, layoutWidth: number) =>\n tabBarWidth - layoutWidth;\n\nconst getTranslateX = (\n scrollAmount: Animated.Value,\n maxScrollDistance: number\n) =>\n Animated.multiply(\n Platform.OS === 'android' && I18nManager.isRTL\n ? Animated.add(maxScrollDistance, Animated.multiply(scrollAmount, -1))\n : scrollAmount,\n I18nManager.isRTL ? 1 : -1\n );\n\nconst getTabBarWidth = <T extends Route>({\n navigationState,\n layout,\n gap,\n scrollEnabled,\n flattenedTabWidth,\n tabWidths,\n}: Pick<Props<T>, 'navigationState' | 'gap' | 'layout' | 'scrollEnabled'> & {\n tabWidths: Record<string, number>;\n flattenedTabWidth: FlattenedTabWidth;\n}) => {\n const { routes } = navigationState;\n\n return routes.reduce<number>(\n (acc, _, i) =>\n acc +\n (i > 0 ? gap ?? 0 : 0) +\n getComputedTabWidth(\n i,\n layout,\n routes,\n scrollEnabled,\n tabWidths,\n flattenedTabWidth\n ),\n 0\n );\n};\n\nconst normalizeScrollValue = <T extends Route>({\n layout,\n navigationState,\n gap,\n scrollEnabled,\n tabWidths,\n value,\n flattenedTabWidth,\n}: Pick<Props<T>, 'layout' | 'navigationState' | 'gap' | 'scrollEnabled'> & {\n tabWidths: Record<string, number>;\n value: number;\n flattenedTabWidth: FlattenedTabWidth;\n}) => {\n const tabBarWidth = getTabBarWidth({\n layout,\n navigationState,\n tabWidths,\n gap,\n scrollEnabled,\n flattenedTabWidth,\n });\n const maxDistance = getMaxScrollDistance(tabBarWidth, layout.width);\n const scrollValue = Math.max(Math.min(value, maxDistance), 0);\n\n if (Platform.OS === 'android' && I18nManager.isRTL) {\n // On Android, scroll value is not applied in reverse in RTL\n // so we need to manually adjust it to apply correct value\n return maxDistance - scrollValue;\n }\n\n return scrollValue;\n};\n\nconst getScrollAmount = <T extends Route>({\n layout,\n navigationState,\n gap,\n scrollEnabled,\n flattenedTabWidth,\n tabWidths,\n}: Pick<Props<T>, 'layout' | 'navigationState' | 'scrollEnabled' | 'gap'> & {\n tabWidths: Record<string, number>;\n flattenedTabWidth: FlattenedTabWidth;\n}) => {\n const centerDistance = Array.from({\n length: navigationState.index + 1,\n }).reduce<number>((total, _, i) => {\n const tabWidth = getComputedTabWidth(\n i,\n layout,\n navigationState.routes,\n scrollEnabled,\n tabWidths,\n flattenedTabWidth\n );\n\n // To get the current index centered we adjust scroll amount by width of indexes\n // 0 through (i - 1) and add half the width of current index i\n return (\n total +\n (navigationState.index === i\n ? (tabWidth + (gap ?? 0)) / 2\n : tabWidth + (gap ?? 0))\n );\n }, 0);\n\n const scrollAmount = centerDistance - layout.width / 2;\n\n return normalizeScrollValue({\n layout,\n navigationState,\n tabWidths,\n value: scrollAmount,\n gap,\n scrollEnabled,\n flattenedTabWidth,\n });\n};\n\nconst getLabelTextDefault = ({ route }: Scene<Route>) => route.title;\n\nconst getAccessibleDefault = ({ route }: Scene<Route>) =>\n typeof route.accessible !== 'undefined' ? route.accessible : true;\n\nconst getAccessibilityLabelDefault = ({ route }: Scene<Route>) =>\n typeof route.accessibilityLabel === 'string'\n ? route.accessibilityLabel\n : typeof route.title === 'string'\n ? route.title\n : undefined;\n\nconst renderIndicatorDefault = (props: IndicatorProps<Route>) => (\n <TabBarIndicator {...props} />\n);\n\nconst getTestIdDefault = ({ route }: Scene<Route>) => route.testID;\n\nexport default function TabBar<T extends Route>({\n getLabelText = getLabelTextDefault,\n getAccessible = getAccessibleDefault,\n getAccessibilityLabel = getAccessibilityLabelDefault,\n getTestID = getTestIdDefault,\n renderIndicator = renderIndicatorDefault,\n gap = 0,\n scrollEnabled,\n jumpTo,\n navigationState,\n position,\n activeColor,\n bounces,\n contentContainerStyle,\n inactiveColor,\n indicatorContainerStyle,\n indicatorStyle,\n labelStyle,\n onTabLongPress,\n onTabPress,\n pressColor,\n pressOpacity,\n renderBadge,\n renderIcon,\n renderLabel,\n renderTabBarItem,\n style,\n tabStyle,\n}: Props<T>) {\n const [layout, setLayout] = React.useState<Layout>({ width: 0, height: 0 });\n const [tabWidths, setTabWidths] = React.useState<Record<string, number>>({});\n const flatListRef = React.useRef<FlatList>(null);\n const isFirst = React.useRef(true);\n const scrollAmount = useAnimatedValue(0);\n const measuredTabWidths = React.useRef<Record<string, number>>({});\n\n const { routes } = navigationState;\n const flattenedTabWidth = getFlattenedTabWidth(tabStyle);\n const isWidthDynamic = flattenedTabWidth === 'auto';\n const scrollOffset = getScrollAmount({\n layout,\n navigationState,\n tabWidths,\n gap,\n scrollEnabled,\n flattenedTabWidth,\n });\n\n const hasMeasuredTabWidths =\n Boolean(layout.width) &&\n routes.every((r) => typeof tabWidths[r.key] === 'number');\n\n React.useEffect(() => {\n if (isFirst.current) {\n isFirst.current = false;\n return;\n }\n\n if (isWidthDynamic && !hasMeasuredTabWidths) {\n // When tab width is dynamic, only adjust the scroll once we have all tab widths and layout\n return;\n }\n\n if (scrollEnabled) {\n flatListRef.current?.scrollToOffset({\n offset: scrollOffset,\n animated: true,\n });\n }\n }, [hasMeasuredTabWidths, isWidthDynamic, scrollEnabled, scrollOffset]);\n\n const handleLayout = (e: LayoutChangeEvent) => {\n const { height, width } = e.nativeEvent.layout;\n\n setLayout((layout) =>\n layout.width === width && layout.height === height\n ? layout\n : { width, height }\n );\n };\n\n const tabBarWidth = getTabBarWidth({\n layout,\n navigationState,\n tabWidths,\n gap,\n scrollEnabled,\n flattenedTabWidth,\n });\n\n const separatorsWidth = Math.max(0, routes.length - 1) * gap;\n const separatorPercent = (separatorsWidth / tabBarWidth) * 100;\n const tabBarWidthPercent = `${routes.length * 40}%`;\n\n const translateX = React.useMemo(\n () =>\n getTranslateX(\n scrollAmount,\n getMaxScrollDistance(tabBarWidth, layout.width)\n ),\n [layout.width, scrollAmount, tabBarWidth]\n );\n\n const renderItem = React.useCallback(\n ({ item: route, index }: ListRenderItemInfo<T>) => {\n const props: TabBarItemProps<T> & { key: string } = {\n key: route.key,\n position: position,\n route: route,\n navigationState: navigationState,\n getAccessibilityLabel: getAccessibilityLabel,\n getAccessible: getAccessible,\n getLabelText: getLabelText,\n getTestID: getTestID,\n renderBadge: renderBadge,\n renderIcon: renderIcon,\n renderLabel: renderLabel,\n activeColor: activeColor,\n inactiveColor: inactiveColor,\n pressColor: pressColor,\n pressOpacity: pressOpacity,\n onLayout: isWidthDynamic\n ? (e: LayoutChangeEvent) => {\n measuredTabWidths.current[route.key] = e.nativeEvent.layout.width;\n\n // When we have measured widths for all of the tabs, we should updates the state\n // We avoid doing separate setState for each layout since it triggers multiple renders and slows down app\n if (\n routes.every(\n (r) => typeof measuredTabWidths.current[r.key] === 'number'\n )\n ) {\n setTabWidths({ ...measuredTabWidths.current });\n }\n }\n : undefined,\n onPress: () => {\n const event: Scene<T> & Event = {\n route,\n defaultPrevented: false,\n preventDefault: () => {\n event.defaultPrevented = true;\n },\n };\n\n onTabPress?.(event);\n\n if (event.defaultPrevented) {\n return;\n }\n\n jumpTo(route.key);\n },\n onLongPress: () => onTabLongPress?.({ route }),\n labelStyle: labelStyle,\n style: tabStyle,\n // Calculate the deafult width for tab for FlatList to work\n defaultTabWidth: !isWidthDynamic\n ? getComputedTabWidth(\n index,\n layout,\n routes,\n scrollEnabled,\n tabWidths,\n getFlattenedTabWidth(tabStyle)\n )\n : undefined,\n };\n\n return (\n <>\n {gap > 0 && index > 0 ? <Separator width={gap} /> : null}\n {renderTabBarItem ? (\n renderTabBarItem(props)\n ) : (\n <TabBarItem {...props} />\n )}\n </>\n );\n },\n [\n activeColor,\n gap,\n getAccessibilityLabel,\n getAccessible,\n getLabelText,\n getTestID,\n inactiveColor,\n isWidthDynamic,\n jumpTo,\n labelStyle,\n layout,\n navigationState,\n onTabLongPress,\n onTabPress,\n position,\n pressColor,\n pressOpacity,\n renderBadge,\n renderIcon,\n renderLabel,\n renderTabBarItem,\n routes,\n scrollEnabled,\n tabStyle,\n tabWidths,\n ]\n );\n\n const keyExtractor = React.useCallback((item: T) => item.key, []);\n\n const contentContainerStyleMemoized = React.useMemo(\n () => [\n styles.tabContent,\n scrollEnabled\n ? {\n width:\n tabBarWidth > separatorsWidth ? tabBarWidth : tabBarWidthPercent,\n }\n : styles.container,\n contentContainerStyle,\n ],\n [\n contentContainerStyle,\n scrollEnabled,\n separatorsWidth,\n tabBarWidth,\n tabBarWidthPercent,\n ]\n );\n\n const handleScroll = React.useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n contentOffset: { x: scrollAmount },\n },\n },\n ],\n { useNativeDriver: true }\n ),\n [scrollAmount]\n );\n\n return (\n <Animated.View onLayout={handleLayout} style={[styles.tabBar, style]}>\n <Animated.View\n pointerEvents=\"none\"\n style={[\n styles.indicatorContainer,\n scrollEnabled ? { transform: [{ translateX }] as any } : null,\n tabBarWidth > separatorsWidth\n ? { width: tabBarWidth - separatorsWidth }\n : scrollEnabled\n ? { width: tabBarWidthPercent }\n : null,\n indicatorContainerStyle,\n ]}\n >\n {renderIndicator({\n position,\n layout,\n navigationState,\n jumpTo,\n width: isWidthDynamic\n ? 'auto'\n : `${(100 - separatorPercent) / routes.length}%`,\n style: indicatorStyle,\n getTabWidth: (i: number) =>\n getComputedTabWidth(\n i,\n layout,\n routes,\n scrollEnabled,\n tabWidths,\n flattenedTabWidth\n ),\n gap,\n })}\n </Animated.View>\n <View style={styles.scroll}>\n <Animated.FlatList\n data={routes as Animated.WithAnimatedValue<T>[]}\n keyExtractor={keyExtractor}\n horizontal\n accessibilityRole=\"tablist\"\n keyboardShouldPersistTaps=\"handled\"\n scrollEnabled={scrollEnabled}\n bounces={bounces}\n alwaysBounceHorizontal={false}\n scrollsToTop={false}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={false}\n automaticallyAdjustContentInsets={false}\n overScrollMode=\"never\"\n contentContainerStyle={contentContainerStyleMemoized}\n scrollEventThrottle={16}\n renderItem={renderItem}\n onScroll={handleScroll}\n ref={flatListRef}\n />\n </View>\n </Animated.View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n },\n scroll: {\n overflow: Platform.select({ default: 'scroll', web: undefined }),\n },\n tabBar: {\n backgroundColor: '#2196f3',\n elevation: 4,\n shadowColor: 'black',\n shadowOpacity: 0.1,\n shadowRadius: StyleSheet.hairlineWidth,\n shadowOffset: {\n height: StyleSheet.hairlineWidth,\n width: 0,\n },\n zIndex: 1,\n },\n tabContent: {\n flexDirection: 'row',\n flexWrap: 'nowrap',\n },\n indicatorContainer: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n },\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AAaA;;AACA;;AASA;;;;;;;;AA4CA,MAAMA,SAAS,GAAG,QAAkC;EAAA,IAAjC;IAAEC;EAAF,CAAiC;EAClD,oBAAO,oBAAC,iBAAD;IAAM,KAAK,EAAE;MAAEA;IAAF;EAAb,EAAP;AACD,CAFD;;AAIA,MAAMC,oBAAoB,GAAIC,KAAD,IAAiC;EAC5D,MAAMC,QAAQ,GAAGC,uBAAA,CAAWC,OAAX,CAAmBH,KAAnB,CAAjB;;EAEA,OAAOC,QAAP,aAAOA,QAAP,uBAAOA,QAAQ,CAAEH,KAAjB;AACD,CAJD;;AAMA,MAAMM,mBAAmB,GAAG,CAC1BC,KAD0B,EAE1BC,MAF0B,EAG1BC,MAH0B,EAI1BC,aAJ0B,EAK1BC,SAL0B,EAM1BC,cAN0B,KAOvB;EACH,IAAIA,cAAc,KAAK,MAAvB,EAA+B;IAC7B,OAAOD,SAAS,CAACF,MAAM,CAACF,KAAD,CAAN,CAAcM,GAAf,CAAT,IAAgC,CAAvC;EACD;;EAED,QAAQ,OAAOD,cAAf;IACE,KAAK,QAAL;MACE,OAAOA,cAAP;;IACF,KAAK,QAAL;MACE,IAAIA,cAAc,CAACE,QAAf,CAAwB,GAAxB,CAAJ,EAAkC;QAChC,MAAMd,KAAK,GAAGe,UAAU,CAACH,cAAD,CAAxB;;QACA,IAAII,MAAM,CAACC,QAAP,CAAgBjB,KAAhB,CAAJ,EAA4B;UAC1B,OAAOQ,MAAM,CAACR,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TW,IAAI,EAAE;EADG,CADoB;EAI/BF,MAAM,EAAE;IACNG,QAAQ,EAAEpH,qBAAA,CAASqH,MAAT,CAAgB;MAAEC,OAAO,EAAE,QAAX;MAAqBC,GAAG,EAAEtF;IAA1B,CAAhB;EADJ,CAJuB;EAO/B4E,MAAM,EAAE;IACNW,eAAe,EAAE,SADX;IAENC,SAAS,EAAE,CAFL;IAGNC,WAAW,EAAE,OAHP;IAINC,aAAa,EAAE,GAJT;IAKNC,YAAY,EAAEnJ,uBAAA,CAAWoJ,aALnB;IAMNC,YAAY,EAAE;MACZ9D,MAAM,EAAEvF,uBAAA,CAAWoJ,aADP;MAEZxJ,KAAK,EAAE;IAFK,CANR;IAUN0J,MAAM,EAAE;EAVF,CAPuB;EAmB/BxB,UAAU,EAAE;IACVyB,aAAa,EAAE,KADL;IAEVC,QAAQ,EAAE;EAFA,CAnBmB;EAuB/BnB,kBAAkB,EAAE;IAClBjE,QAAQ,EAAE,UADQ;IAElBqF,GAAG,EAAE,CAFa;IAGlBC,IAAI,EAAE,CAHY;IAIlBC,KAAK,EAAE,CAJW;IAKlBC,MAAM,EAAE;EALU;AAvBW,CAAlB,CAAf"}
|
|
@@ -3,130 +3,112 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = TabBarIndicator;
|
|
7
7
|
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
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; }
|
|
15
|
-
|
|
16
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
var _useAnimatedValue = _interopRequireDefault(require("./useAnimatedValue"));
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
constructor() {
|
|
20
|
-
super(...arguments);
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
navigationState,
|
|
25
|
-
layout,
|
|
26
|
-
width,
|
|
27
|
-
getTabWidth
|
|
28
|
-
} = this.props;
|
|
16
|
+
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); }
|
|
29
17
|
|
|
30
|
-
|
|
31
|
-
navigationState.routes.every((_, i) => getTabWidth(i))) {
|
|
32
|
-
this.isIndicatorShown = true;
|
|
18
|
+
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; }
|
|
33
19
|
|
|
34
|
-
|
|
20
|
+
const getTranslateX = (position, routes, getTabWidth, gap) => {
|
|
21
|
+
const inputRange = routes.map((_, i) => i); // every index contains widths at all previous indices
|
|
22
|
+
|
|
23
|
+
const outputRange = routes.reduce((acc, _, i) => {
|
|
24
|
+
if (i === 0) return [0];
|
|
25
|
+
return [...acc, acc[i - 1] + getTabWidth(i - 1) + (gap ?? 0)];
|
|
26
|
+
}, []);
|
|
27
|
+
const translateX = position.interpolate({
|
|
28
|
+
inputRange,
|
|
29
|
+
outputRange,
|
|
30
|
+
extrapolate: 'clamp'
|
|
31
|
+
});
|
|
32
|
+
return _reactNative.Animated.multiply(translateX, _reactNative.I18nManager.isRTL ? -1 : 1);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function TabBarIndicator(_ref) {
|
|
36
|
+
let {
|
|
37
|
+
getTabWidth,
|
|
38
|
+
layout,
|
|
39
|
+
navigationState,
|
|
40
|
+
position,
|
|
41
|
+
width,
|
|
42
|
+
gap,
|
|
43
|
+
style
|
|
44
|
+
} = _ref;
|
|
45
|
+
const isIndicatorShown = React.useRef(false);
|
|
46
|
+
const isWidthDynamic = width === 'auto';
|
|
47
|
+
const opacity = (0, _useAnimatedValue.default)(isWidthDynamic ? 0 : 1);
|
|
48
|
+
const hasMeasuredTabWidths = Boolean(layout.width) && navigationState.routes.every((_, i) => getTabWidth(i));
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
const fadeInIndicator = () => {
|
|
51
|
+
if (!isIndicatorShown.current && isWidthDynamic && // We should fade-in the indicator when we have widths for all the tab items
|
|
52
|
+
hasMeasuredTabWidths) {
|
|
53
|
+
isIndicatorShown.current = true;
|
|
54
|
+
|
|
55
|
+
_reactNative.Animated.timing(opacity, {
|
|
35
56
|
toValue: 1,
|
|
36
57
|
duration: 150,
|
|
37
58
|
easing: _reactNative.Easing.in(_reactNative.Easing.linear),
|
|
38
59
|
useNativeDriver: true
|
|
39
60
|
}).start();
|
|
40
61
|
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
fadeInIndicator();
|
|
65
|
+
return () => opacity.stopAnimation();
|
|
66
|
+
}, [hasMeasuredTabWidths, isWidthDynamic, opacity]);
|
|
67
|
+
const {
|
|
68
|
+
routes
|
|
69
|
+
} = navigationState;
|
|
70
|
+
const transform = [];
|
|
71
|
+
|
|
72
|
+
if (layout.width) {
|
|
73
|
+
const translateX = routes.length > 1 ? getTranslateX(position, routes, getTabWidth, gap) : 0;
|
|
74
|
+
transform.push({
|
|
75
|
+
translateX
|
|
41
76
|
});
|
|
77
|
+
}
|
|
42
78
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const inputRange = routes.map((_, i) => i); // every index contains widths at all previous indices
|
|
49
|
-
|
|
50
|
-
const outputRange = routes.reduce((acc, _, i) => {
|
|
51
|
-
if (i === 0) return [0];
|
|
52
|
-
return [...acc, acc[i - 1] + getTabWidth(i - 1) + (gap ?? 0)];
|
|
53
|
-
}, []);
|
|
54
|
-
const translateX = position.interpolate({
|
|
79
|
+
if (width === 'auto') {
|
|
80
|
+
const inputRange = routes.map((_, i) => i);
|
|
81
|
+
const outputRange = inputRange.map(getTabWidth);
|
|
82
|
+
transform.push({
|
|
83
|
+
scaleX: routes.length > 1 ? position.interpolate({
|
|
55
84
|
inputRange,
|
|
56
85
|
outputRange,
|
|
57
86
|
extrapolate: 'clamp'
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
componentDidMount() {
|
|
64
|
-
this.fadeInIndicator();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
componentDidUpdate() {
|
|
68
|
-
this.fadeInIndicator();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
render() {
|
|
72
|
-
const {
|
|
73
|
-
position,
|
|
74
|
-
navigationState,
|
|
75
|
-
getTabWidth,
|
|
76
|
-
width,
|
|
77
|
-
style,
|
|
78
|
-
layout,
|
|
79
|
-
gap
|
|
80
|
-
} = this.props;
|
|
81
|
-
const {
|
|
82
|
-
routes
|
|
83
|
-
} = navigationState;
|
|
84
|
-
const transform = [];
|
|
85
|
-
|
|
86
|
-
if (layout.width) {
|
|
87
|
-
const translateX = routes.length > 1 ? this.getTranslateX(position, routes, getTabWidth, gap) : 0;
|
|
88
|
-
transform.push({
|
|
89
|
-
translateX
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (width === 'auto') {
|
|
94
|
-
const inputRange = routes.map((_, i) => i);
|
|
95
|
-
const outputRange = inputRange.map(getTabWidth);
|
|
96
|
-
transform.push({
|
|
97
|
-
scaleX: routes.length > 1 ? position.interpolate({
|
|
98
|
-
inputRange,
|
|
99
|
-
outputRange,
|
|
100
|
-
extrapolate: 'clamp'
|
|
101
|
-
}) : outputRange[0]
|
|
102
|
-
}, {
|
|
103
|
-
translateX: 0.5
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
|
|
108
|
-
style: [styles.indicator, {
|
|
109
|
-
width: width === 'auto' ? 1 : width
|
|
110
|
-
}, // If layout is not available, use `left` property for positioning the indicator
|
|
111
|
-
// This avoids rendering delay until we are able to calculate translateX
|
|
112
|
-
// If platform is macos use `left` property as `transform` is broken at the moment.
|
|
113
|
-
// See: https://github.com/microsoft/react-native-macos/issues/280
|
|
114
|
-
layout.width && _reactNative.Platform.OS !== 'macos' ? {
|
|
115
|
-
left: 0
|
|
116
|
-
} : {
|
|
117
|
-
left: `${100 / routes.length * navigationState.index}%`
|
|
118
|
-
}, {
|
|
119
|
-
transform
|
|
120
|
-
}, width === 'auto' ? {
|
|
121
|
-
opacity: this.opacity
|
|
122
|
-
} : null, style]
|
|
87
|
+
}) : outputRange[0]
|
|
88
|
+
}, {
|
|
89
|
+
translateX: 0.5
|
|
123
90
|
});
|
|
124
91
|
}
|
|
125
92
|
|
|
93
|
+
return /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
|
|
94
|
+
style: [styles.indicator, {
|
|
95
|
+
width: width === 'auto' ? 1 : width
|
|
96
|
+
}, // If layout is not available, use `left` property for positioning the indicator
|
|
97
|
+
// This avoids rendering delay until we are able to calculate translateX
|
|
98
|
+
// If platform is macos use `left` property as `transform` is broken at the moment.
|
|
99
|
+
// See: https://github.com/microsoft/react-native-macos/issues/280
|
|
100
|
+
layout.width && _reactNative.Platform.OS !== 'macos' ? {
|
|
101
|
+
left: 0
|
|
102
|
+
} : {
|
|
103
|
+
left: `${100 / routes.length * navigationState.index}%`
|
|
104
|
+
}, {
|
|
105
|
+
transform
|
|
106
|
+
}, width === 'auto' ? {
|
|
107
|
+
opacity: opacity
|
|
108
|
+
} : null, style]
|
|
109
|
+
});
|
|
126
110
|
}
|
|
127
111
|
|
|
128
|
-
exports.default = TabBarIndicator;
|
|
129
|
-
|
|
130
112
|
const styles = _reactNative.StyleSheet.create({
|
|
131
113
|
indicator: {
|
|
132
114
|
backgroundColor: '#ffeb3b',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["getTranslateX","position","routes","getTabWidth","gap","inputRange","map","_","i","outputRange","reduce","acc","translateX","interpolate","extrapolate","Animated","multiply","I18nManager","isRTL","TabBarIndicator","layout","navigationState","width","style","isIndicatorShown","React","useRef","isWidthDynamic","opacity","useAnimatedValue","hasMeasuredTabWidths","Boolean","every","useEffect","fadeInIndicator","current","timing","toValue","duration","easing","Easing","in","linear","useNativeDriver","start","stopAnimation","transform","length","push","scaleX","styles","indicator","Platform","OS","left","index","StyleSheet","create","backgroundColor","bottom","right","height"],"sources":["TabBarIndicator.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n Easing,\n StyleSheet,\n I18nManager,\n StyleProp,\n ViewStyle,\n Platform,\n} from 'react-native';\n\nimport type { Route, SceneRendererProps, NavigationState } from './types';\nimport useAnimatedValue from './useAnimatedValue';\n\nexport type GetTabWidth = (index: number) => number;\n\nexport type Props<T extends Route> = SceneRendererProps & {\n navigationState: NavigationState<T>;\n width: string | number;\n style?: StyleProp<ViewStyle>;\n getTabWidth: GetTabWidth;\n gap?: number;\n};\n\nconst getTranslateX = (\n position: Animated.AnimatedInterpolation,\n routes: Route[],\n getTabWidth: GetTabWidth,\n gap?: number\n) => {\n const inputRange = routes.map((_, i) => i);\n\n // every index contains widths at all previous indices\n const outputRange = routes.reduce<number[]>((acc, _, i) => {\n if (i === 0) return [0];\n return [...acc, acc[i - 1] + getTabWidth(i - 1) + (gap ?? 0)];\n }, []);\n\n const translateX = position.interpolate({\n inputRange,\n outputRange,\n extrapolate: 'clamp',\n });\n\n return Animated.multiply(translateX, I18nManager.isRTL ? -1 : 1);\n};\n\nexport default function TabBarIndicator<T extends Route>({\n getTabWidth,\n layout,\n navigationState,\n position,\n width,\n gap,\n style,\n}: Props<T>) {\n const isIndicatorShown = React.useRef(false);\n const isWidthDynamic = width === 'auto';\n\n const opacity = useAnimatedValue(isWidthDynamic ? 0 : 1);\n\n const hasMeasuredTabWidths =\n Boolean(layout.width) &&\n navigationState.routes.every((_, i) => getTabWidth(i));\n\n React.useEffect(() => {\n const fadeInIndicator = () => {\n if (\n !isIndicatorShown.current &&\n isWidthDynamic &&\n // We should fade-in the indicator when we have widths for all the tab items\n hasMeasuredTabWidths\n ) {\n isIndicatorShown.current = true;\n\n Animated.timing(opacity, {\n toValue: 1,\n duration: 150,\n easing: Easing.in(Easing.linear),\n useNativeDriver: true,\n }).start();\n }\n };\n\n fadeInIndicator();\n\n return () => opacity.stopAnimation();\n }, [hasMeasuredTabWidths, isWidthDynamic, opacity]);\n\n const { routes } = navigationState;\n\n const transform = [];\n\n if (layout.width) {\n const translateX =\n routes.length > 1 ? getTranslateX(position, routes, getTabWidth, gap) : 0;\n\n transform.push({ translateX });\n }\n\n if (width === 'auto') {\n const inputRange = routes.map((_, i) => i);\n const outputRange = inputRange.map(getTabWidth);\n\n transform.push(\n {\n scaleX:\n routes.length > 1\n ? position.interpolate({\n inputRange,\n outputRange,\n extrapolate: 'clamp',\n })\n : outputRange[0],\n },\n { translateX: 0.5 }\n );\n }\n\n return (\n <Animated.View\n style={[\n styles.indicator,\n { width: width === 'auto' ? 1 : width },\n // If layout is not available, use `left` property for positioning the indicator\n // This avoids rendering delay until we are able to calculate translateX\n // If platform is macos use `left` property as `transform` is broken at the moment.\n // See: https://github.com/microsoft/react-native-macos/issues/280\n layout.width && Platform.OS !== 'macos'\n ? { left: 0 }\n : { left: `${(100 / routes.length) * navigationState.index}%` },\n { transform },\n width === 'auto' ? { opacity: opacity } : null,\n style,\n ]}\n />\n );\n}\n\nconst styles = StyleSheet.create({\n indicator: {\n backgroundColor: '#ffeb3b',\n position: 'absolute',\n left: 0,\n bottom: 0,\n right: 0,\n height: 2,\n },\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AAWA;;;;;;;;AAYA,MAAMA,aAAa,GAAG,CACpBC,QADoB,EAEpBC,MAFoB,EAGpBC,WAHoB,EAIpBC,GAJoB,KAKjB;EACH,MAAMC,UAAU,GAAGH,MAAM,CAACI,GAAP,CAAW,CAACC,CAAD,EAAIC,CAAJ,KAAUA,CAArB,CAAnB,CADG,CAGH;;EACA,MAAMC,WAAW,GAAGP,MAAM,CAACQ,MAAP,CAAwB,CAACC,GAAD,EAAMJ,CAAN,EAASC,CAAT,KAAe;IACzD,IAAIA,CAAC,KAAK,CAAV,EAAa,OAAO,CAAC,CAAD,CAAP;IACb,OAAO,CAAC,GAAGG,GAAJ,EAASA,GAAG,CAACH,CAAC,GAAG,CAAL,CAAH,GAAaL,WAAW,CAACK,CAAC,GAAG,CAAL,CAAxB,IAAmCJ,GAAG,IAAI,CAA1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