@fountain-ui/core 2.0.0-beta.76 → 2.0.0-beta.77

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.
@@ -21,6 +21,8 @@ var _IndexAwareTab = _interopRequireDefault(require("./IndexAwareTab"));
21
21
 
22
22
  var _useTabCoordinates = _interopRequireDefault(require("./useTabCoordinates"));
23
23
 
24
+ var _useTabInnerContentsWidth = _interopRequireDefault(require("./useTabInnerContentsWidth"));
25
+
24
26
  var _useIndexStore = _interopRequireDefault(require("./useIndexStore"));
25
27
 
26
28
  var _InternalContext = _interopRequireDefault(require("./InternalContext"));
@@ -85,28 +87,28 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(function Tabs(props, ref) {
85
87
  }), [sharedIndex]);
86
88
  const styles = useStyles();
87
89
  const [outerCoordinates, updateCoordinate] = (0, _useTabCoordinates.default)(children);
88
- const [innerCoordinates, updateInnerCoordinate] = (0, _useTabCoordinates.default)(children);
89
- const canRenderIndicator = indicatorSize === 'fit-content' ? (0, _utils.isEveryTabCoordinatesDefined)(innerCoordinates, children) : (0, _utils.isEveryTabCoordinatesDefined)(outerCoordinates, children);
90
+ const [innerContentsWidthList, updateInnerContentsWidth] = (0, _useTabInnerContentsWidth.default)(children);
91
+ const canRenderIndicator = indicatorSize === 'fit-content' ? (0, _utils.isEveryTabCoordinatesDefined)(innerContentsWidthList, children) : (0, _utils.isEveryTabCoordinatesDefined)(outerCoordinates, children);
90
92
  const indexStore = (0, _useIndexStore.default)(sharedIndex);
91
93
  const coordinates = (0, _react.useMemo)(() => {
92
94
  if (indicatorSize !== 'fit-content') {
93
95
  return outerCoordinates;
94
96
  }
95
97
 
96
- return innerCoordinates.map((coordinate, idx) => {
97
- const {
98
- x1,
99
- x2
100
- } = coordinate;
98
+ return innerContentsWidthList.map((innerContentWidth, idx) => {
101
99
  const {
102
- x1: outerX1
100
+ x1: outerX1,
101
+ x2: outerX2
103
102
  } = outerCoordinates[idx];
103
+ const tabWidth = outerX2 - outerX1;
104
+ const distanceFromParent = (tabWidth - innerContentWidth) / 2;
105
+ const indicatorStartCoordinate = outerX1 + distanceFromParent;
104
106
  return {
105
- x1: x1 + outerX1,
106
- x2: x2 + outerX1
107
+ x1: indicatorStartCoordinate,
108
+ x2: indicatorStartCoordinate + innerContentWidth
107
109
  };
108
110
  });
109
- }, [outerCoordinates, innerCoordinates, variant]);
111
+ }, [outerCoordinates, innerContentsWidthList, variant]);
110
112
  (0, _react.useEffect)(() => {
111
113
  return indexStore.subscribe(newIndex => {
112
114
  onChange === null || onChange === void 0 ? void 0 : onChange(newIndex);
@@ -120,10 +122,9 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(function Tabs(props, ref) {
120
122
 
121
123
  const onTabInnerLayout = event => {
122
124
  const {
123
- x,
124
125
  width
125
126
  } = event.nativeEvent.layout;
126
- updateInnerCoordinate(index, x, width);
127
+ updateInnerContentsWidth(index, width);
127
128
  };
128
129
 
129
130
  const onLayout = event => {
@@ -1 +1 @@
1
- {"version":3,"names":["useStyles","theme","useTheme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","forwardRef","props","ref","children","indicatorColor","initialIndex","disableIndicator","indicatorSize","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","onTabSelected","fallbackSharedIndex","useSyncAnimatedValue","initialValue","sharedIndex","realInitialIndex","currentIndexRef","useRef","setTab","newIndex","currentIndex","current","animatedValue","setValue","useImperativeHandle","styles","outerCoordinates","updateCoordinate","useTabCoordinates","innerCoordinates","updateInnerCoordinate","canRenderIndicator","isEveryTabCoordinatesDefined","indexStore","useIndexStore","coordinates","useMemo","map","coordinate","idx","x1","x2","outerX1","useEffect","subscribe","tabElements","React","Children","child","index","onTabInnerLayout","event","x","width","nativeEvent","layout","onLayout","onMouseDown","e","preventDefault","onPress","tabElement","cloneElement","enableIndicator","undefined","filter","Boolean","tabIndicator","css"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';\nimport type { GestureResponderEvent, LayoutChangeEvent } from 'react-native';\nimport { View } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport { useSyncAnimatedValue } from '../hooks';\nimport type TabsProps from './TabsProps';\nimport type { TabsInstance } from './types';\nimport TabIndicator from './TabIndicator';\nimport ScrollableTabsView from './ScrollableTabsView';\nimport IndexAwareTab from './IndexAwareTab';\nimport useTabCoordinates from './useTabCoordinates';\nimport useIndexStore from './useIndexStore';\nimport InternalContext from './InternalContext';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\ntype TabsStyleKeys =\n | 'root'\n | 'fixedRoot'\n | 'fixedTab'\n | 'scrollableContainer';\n\ntype TabsStyles = NamedStylesStringUnion<TabsStyleKeys>;\n\nconst useStyles: UseStyles<TabsStyles> = function (): TabsStyles {\n const theme = useTheme();\n\n return {\n root: {},\n fixedRoot: {\n flexDirection: 'row',\n },\n fixedTab: {\n flex: 1,\n },\n scrollableContainer: {\n paddingHorizontal: theme.spacing(1),\n },\n };\n};\n\nconst Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {\n const {\n children,\n indicatorColor = 'primary',\n initialIndex = 0,\n disableIndicator = false,\n indicatorSize = 'full',\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n onTabSelected,\n } = props;\n\n const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n const realInitialIndex = sharedIndex.initialValue;\n\n const currentIndexRef = useRef(initialIndex);\n\n const setTab = (newIndex: number) => {\n const currentIndex = currentIndexRef.current;\n onTabSelected?.(newIndex, currentIndex);\n\n sharedIndex.animatedValue.setValue(newIndex);\n };\n\n useImperativeHandle(\n ref,\n () => ({\n setTab,\n }),\n [sharedIndex],\n );\n\n const styles = useStyles();\n\n const [outerCoordinates, updateCoordinate] = useTabCoordinates(children);\n const [innerCoordinates, updateInnerCoordinate] = useTabCoordinates(children);\n\n const canRenderIndicator = indicatorSize === 'fit-content'\n ? isEveryTabCoordinatesDefined(innerCoordinates, children)\n : isEveryTabCoordinatesDefined(outerCoordinates, children);\n\n const indexStore = useIndexStore(sharedIndex);\n\n const coordinates = useMemo(() => {\n if (indicatorSize !== 'fit-content') {\n return outerCoordinates;\n }\n\n return innerCoordinates.map((coordinate, idx) => {\n const { x1, x2 } = coordinate;\n const { x1: outerX1 } = outerCoordinates[idx];\n return {\n x1: x1 + outerX1,\n x2: x2 + outerX1,\n }\n });\n }, [outerCoordinates, innerCoordinates, variant]);\n\n useEffect(() => {\n return indexStore.subscribe(newIndex => {\n onChange?.(newIndex);\n currentIndexRef.current = newIndex;\n });\n }, [indexStore, onChange]);\n\n const tabElements = React.Children.map(children, (child, index) => {\n if (!child) {\n return null;\n }\n\n const onTabInnerLayout = (event: LayoutChangeEvent) => {\n const { x, width } = event.nativeEvent.layout;\n\n updateInnerCoordinate(index, x, width);\n };\n\n const onLayout = (event: LayoutChangeEvent) => {\n const { x, width } = event.nativeEvent.layout;\n\n updateCoordinate(index, x, width);\n\n // @ts-ignore\n child.props.onLayout?.(event);\n };\n\n const onMouseDown = (e: GestureResponderEvent) => {\n if (keyboardShouldPersistTaps === 'always') {\n e.preventDefault();\n }\n };\n\n const onPress = () => {\n setTab(index);\n\n // @ts-ignore\n child.props.onPress?.();\n };\n\n // @ts-ignore\n const tabElement = cloneElement(child, {\n enableIndicator: !disableIndicator && !canRenderIndicator,\n indicatorColor,\n onTabInnerLayout,\n onLayout,\n onPress,\n onMouseDown,\n variant,\n indicatorSize,\n style: scrollable ? undefined : styles.fixedTab,\n });\n\n return (\n <IndexAwareTab\n children={tabElement}\n index={index}\n initialIndex={realInitialIndex}\n />\n );\n })?.filter(Boolean);\n\n const tabIndicator = canRenderIndicator ? (\n <TabIndicator\n color={indicatorColor}\n coordinates={coordinates}\n disabled={disableIndicator}\n initialIndex={realInitialIndex}\n scrollable={scrollable}\n />\n ) : null;\n\n return (\n <InternalContext.Provider value={{ indexStore }}>\n <View\n style={css([\n styles.root,\n scrollable ? undefined : styles.fixedRoot,\n style,\n ])}\n >\n {scrollable ? (\n <ScrollableTabsView\n automaticallyAdjustContentInsets={false}\n bounces={false}\n contentContainerStyle={styles.scrollableContainer}\n coordinates={coordinates}\n directionalLockEnabled={true}\n horizontal={true}\n initialIndex={realInitialIndex}\n scrollsToTop={false}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={false}\n keyboardDismissMode={keyboardDismissMode}\n keyboardShouldPersistTaps={keyboardShouldPersistTaps}\n >\n {tabElements}\n {tabIndicator}\n </ScrollableTabsView>\n ) : (\n <React.Fragment>\n {tabElements}\n {tabIndicator}\n </React.Fragment>\n )}\n </View>\n </InternalContext.Provider>\n );\n});\n\nexport default Tabs;\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAUA,MAAMA,SAAgC,GAAG,YAAwB;EAC7D,MAAMC,KAAK,GAAG,IAAAC,gBAAA,GAAd;EAEA,OAAO;IACHC,IAAI,EAAE,EADH;IAEHC,SAAS,EAAE;MACPC,aAAa,EAAE;IADR,CAFR;IAKHC,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA,CALP;IAQHC,mBAAmB,EAAE;MACjBC,iBAAiB,EAAER,KAAK,CAACS,OAAN,CAAc,CAAd;IADF;EARlB,CAAP;AAYH,CAfD;;AAiBA,MAAMC,IAAI,gBAAG,IAAAC,iBAAA,EAAoC,SAASD,IAAT,CAAcE,KAAd,EAAqBC,GAArB,EAA0B;EAAA;;EACvE,MAAM;IACFC,QADE;IAEFC,cAAc,GAAG,SAFf;IAGFC,YAAY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;EAUA,oBACI,6BAAC,wBAAD,CAAiB,QAAjB;IAA0B,KAAK,EAAE;MAAE2B;IAAF;EAAjC,gBACI,6BAAC,iBAAD;IACI,KAAK,EAAE,IAAAmC,WAAA,EAAI,CACP3C,MAAM,CAACvC,IADA,EAEPoB,UAAU,GAAG0D,SAAH,GAAevC,MAAM,CAACtC,SAFzB,EAGPoB,KAHO,CAAJ;EADX,GAOKD,UAAU,gBACP,6BAAC,2BAAD;IACI,gCAAgC,EAAE,KADtC;IAEI,OAAO,EAAE,KAFb;IAGI,qBAAqB,EAAEmB,MAAM,CAAClC,mBAHlC;IAII,WAAW,EAAE4C,WAJjB;IAKI,sBAAsB,EAAE,IAL5B;IAMI,UAAU,EAAE,IANhB;IAOI,YAAY,EAAEpB,gBAPlB;IAQI,YAAY,EAAE,KARlB;IASI,8BAA8B,EAAE,KATpC;IAUI,4BAA4B,EAAE,KAVlC;IAWI,mBAAmB,EAAEZ,mBAXzB;IAYI,yBAAyB,EAAEC;EAZ/B,GAcKyC,WAdL,EAeKsB,YAfL,CADO,gBAmBP,6BAAC,cAAD,CAAO,QAAP,QACKtB,WADL,EAEKsB,YAFL,CA1BR,CADJ,CADJ;AAoCH,CA5KY,CAAb;eA8KezE,I"}
1
+ {"version":3,"names":["useStyles","theme","useTheme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","forwardRef","props","ref","children","indicatorColor","initialIndex","disableIndicator","indicatorSize","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","onTabSelected","fallbackSharedIndex","useSyncAnimatedValue","initialValue","sharedIndex","realInitialIndex","currentIndexRef","useRef","setTab","newIndex","currentIndex","current","animatedValue","setValue","useImperativeHandle","styles","outerCoordinates","updateCoordinate","useTabCoordinates","innerContentsWidthList","updateInnerContentsWidth","useTabInnerContentsWidth","canRenderIndicator","isEveryTabCoordinatesDefined","indexStore","useIndexStore","coordinates","useMemo","map","innerContentWidth","idx","x1","outerX1","x2","outerX2","tabWidth","distanceFromParent","indicatorStartCoordinate","useEffect","subscribe","tabElements","React","Children","child","index","onTabInnerLayout","event","width","nativeEvent","layout","onLayout","x","onMouseDown","e","preventDefault","onPress","tabElement","cloneElement","enableIndicator","undefined","filter","Boolean","tabIndicator","css"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';\nimport type { GestureResponderEvent, LayoutChangeEvent } from 'react-native';\nimport { View } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport { useSyncAnimatedValue } from '../hooks';\nimport type TabsProps from './TabsProps';\nimport type { TabsInstance } from './types';\nimport TabIndicator from './TabIndicator';\nimport ScrollableTabsView from './ScrollableTabsView';\nimport IndexAwareTab from './IndexAwareTab';\nimport useTabCoordinates from './useTabCoordinates';\nimport useTabInnerContentsWidth from './useTabInnerContentsWidth';\nimport useIndexStore from './useIndexStore';\nimport InternalContext from './InternalContext';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\ntype TabsStyleKeys =\n | 'root'\n | 'fixedRoot'\n | 'fixedTab'\n | 'scrollableContainer';\n\ntype TabsStyles = NamedStylesStringUnion<TabsStyleKeys>;\n\nconst useStyles: UseStyles<TabsStyles> = function (): TabsStyles {\n const theme = useTheme();\n\n return {\n root: {},\n fixedRoot: {\n flexDirection: 'row',\n },\n fixedTab: {\n flex: 1,\n },\n scrollableContainer: {\n paddingHorizontal: theme.spacing(1),\n },\n };\n};\n\nconst Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {\n const {\n children,\n indicatorColor = 'primary',\n initialIndex = 0,\n disableIndicator = false,\n indicatorSize = 'full',\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n onTabSelected,\n } = props;\n\n const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n const realInitialIndex = sharedIndex.initialValue;\n\n const currentIndexRef = useRef(initialIndex);\n\n const setTab = (newIndex: number) => {\n const currentIndex = currentIndexRef.current;\n onTabSelected?.(newIndex, currentIndex);\n\n sharedIndex.animatedValue.setValue(newIndex);\n };\n\n useImperativeHandle(\n ref,\n () => ({\n setTab,\n }),\n [sharedIndex],\n );\n\n const styles = useStyles();\n\n const [outerCoordinates, updateCoordinate] = useTabCoordinates(children);\n const [innerContentsWidthList, updateInnerContentsWidth] = useTabInnerContentsWidth(children);\n\n const canRenderIndicator = indicatorSize === 'fit-content'\n ? isEveryTabCoordinatesDefined(innerContentsWidthList, children)\n : isEveryTabCoordinatesDefined(outerCoordinates, children);\n\n const indexStore = useIndexStore(sharedIndex);\n\n const coordinates = useMemo(() => {\n if (indicatorSize !== 'fit-content') {\n return outerCoordinates;\n }\n\n return innerContentsWidthList.map((innerContentWidth, idx) => {\n const { x1: outerX1, x2: outerX2 } = outerCoordinates[idx];\n\n const tabWidth = outerX2 - outerX1;\n const distanceFromParent = (tabWidth - innerContentWidth) / 2;\n const indicatorStartCoordinate = outerX1 + distanceFromParent;\n\n return {\n x1: indicatorStartCoordinate,\n x2: indicatorStartCoordinate + innerContentWidth,\n };\n });\n }, [outerCoordinates, innerContentsWidthList, variant]);\n\n useEffect(() => {\n return indexStore.subscribe(newIndex => {\n onChange?.(newIndex);\n currentIndexRef.current = newIndex;\n });\n }, [indexStore, onChange]);\n\n const tabElements = React.Children.map(children, (child, index) => {\n if (!child) {\n return null;\n }\n\n const onTabInnerLayout = (event: LayoutChangeEvent) => {\n const { width } = event.nativeEvent.layout;\n\n updateInnerContentsWidth(index, width);\n };\n\n const onLayout = (event: LayoutChangeEvent) => {\n const { x, width } = event.nativeEvent.layout;\n\n updateCoordinate(index, x, width);\n\n // @ts-ignore\n child.props.onLayout?.(event);\n };\n\n const onMouseDown = (e: GestureResponderEvent) => {\n if (keyboardShouldPersistTaps === 'always') {\n e.preventDefault();\n }\n };\n\n const onPress = () => {\n setTab(index);\n\n // @ts-ignore\n child.props.onPress?.();\n };\n\n // @ts-ignore\n const tabElement = cloneElement(child, {\n enableIndicator: !disableIndicator && !canRenderIndicator,\n indicatorColor,\n onTabInnerLayout,\n onLayout,\n onPress,\n onMouseDown,\n variant,\n indicatorSize,\n style: scrollable ? undefined : styles.fixedTab,\n });\n\n return (\n <IndexAwareTab\n children={tabElement}\n index={index}\n initialIndex={realInitialIndex}\n />\n );\n })?.filter(Boolean);\n\n const tabIndicator = canRenderIndicator ? (\n <TabIndicator\n color={indicatorColor}\n coordinates={coordinates}\n disabled={disableIndicator}\n initialIndex={realInitialIndex}\n scrollable={scrollable}\n />\n ) : null;\n\n return (\n <InternalContext.Provider value={{ indexStore }}>\n <View\n style={css([\n styles.root,\n scrollable ? undefined : styles.fixedRoot,\n style,\n ])}\n >\n {scrollable ? (\n <ScrollableTabsView\n automaticallyAdjustContentInsets={false}\n bounces={false}\n contentContainerStyle={styles.scrollableContainer}\n coordinates={coordinates}\n directionalLockEnabled={true}\n horizontal={true}\n initialIndex={realInitialIndex}\n scrollsToTop={false}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={false}\n keyboardDismissMode={keyboardDismissMode}\n keyboardShouldPersistTaps={keyboardShouldPersistTaps}\n >\n {tabElements}\n {tabIndicator}\n </ScrollableTabsView>\n ) : (\n <React.Fragment>\n {tabElements}\n {tabIndicator}\n </React.Fragment>\n )}\n </View>\n </InternalContext.Provider>\n );\n});\n\nexport default Tabs;\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAUA,MAAMA,SAAgC,GAAG,YAAwB;EAC7D,MAAMC,KAAK,GAAG,IAAAC,gBAAA,GAAd;EAEA,OAAO;IACHC,IAAI,EAAE,EADH;IAEHC,S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AAb;eAkLe9E,I"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _utils = require("./utils");
11
+
12
+ const useTabInnerContentsWidth = tabElements => {
13
+ const [innerContentsWidthList, setInnerContentsWidth] = (0, _react.useState)([]);
14
+ const cacheRef = (0, _react.useRef)([]);
15
+
16
+ const updateInnerContentsWidth = (index, width) => {
17
+ cacheRef.current[index] = width;
18
+
19
+ if ((0, _utils.isEveryTabCoordinatesDefined)(cacheRef.current, tabElements)) {
20
+ setInnerContentsWidth([...cacheRef.current]);
21
+ cacheRef.current = [];
22
+ }
23
+ };
24
+
25
+ return [innerContentsWidthList, updateInnerContentsWidth];
26
+ };
27
+
28
+ var _default = useTabInnerContentsWidth;
29
+ exports.default = _default;
30
+ //# sourceMappingURL=useTabInnerContentsWidth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useTabInnerContentsWidth","tabElements","innerContentsWidthList","setInnerContentsWidth","useState","cacheRef","useRef","updateInnerContentsWidth","index","width","current","isEveryTabCoordinatesDefined"],"sources":["useTabInnerContentsWidth.ts"],"sourcesContent":["import React, { useRef, useState } from 'react';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\nexport interface UpdateInnerContentsWidth {\n (index: number, width: number): void;\n}\n\nconst useTabInnerContentsWidth = (tabElements: React.ReactNode): [number[], UpdateInnerContentsWidth] => {\n const [innerContentsWidthList, setInnerContentsWidth] = useState<number[]>([]);\n\n const cacheRef = useRef<number[]>([]);\n\n const updateInnerContentsWidth: UpdateInnerContentsWidth = (index, width) => {\n cacheRef.current[index] = width;\n\n if (isEveryTabCoordinatesDefined(cacheRef.current, tabElements)) {\n setInnerContentsWidth([...cacheRef.current]);\n\n cacheRef.current = [];\n }\n };\n\n return [innerContentsWidthList, updateInnerContentsWidth];\n};\n\nexport default useTabInnerContentsWidth;\n"],"mappings":";;;;;;;AAAA;;AACA;;AAMA,MAAMA,wBAAwB,GAAIC,WAAD,IAAwE;EACrG,MAAM,CAACC,sBAAD,EAAyBC,qBAAzB,IAAkD,IAAAC,eAAA,EAAmB,EAAnB,CAAxD;EAEA,MAAMC,QAAQ,GAAG,IAAAC,aAAA,EAAiB,EAAjB,CAAjB;;EAEA,MAAMC,wBAAkD,GAAG,CAACC,KAAD,EAAQC,KAAR,KAAkB;IACzEJ,QAAQ,CAACK,OAAT,CAAiBF,KAAjB,IAA0BC,KAA1B;;IAEA,IAAI,IAAAE,mCAAA,EAA6BN,QAAQ,CAACK,OAAtC,EAA+CT,WAA/C,CAAJ,EAAiE;MAC7DE,qBAAqB,CAAC,CAAC,GAAGE,QAAQ,CAACK,OAAb,CAAD,CAArB;MAEAL,QAAQ,CAACK,OAAT,GAAmB,EAAnB;IACH;EACJ,CARD;;EAUA,OAAO,CAACR,sBAAD,EAAyBK,wBAAzB,CAAP;AACH,CAhBD;;eAkBeP,wB"}
@@ -1 +1 @@
1
- {"version":3,"names":["isEveryTabCoordinatesDefined","coordinates","tabElements","numberOfTabs","Children","count","numberOfCoordinates","length","everyCoordinatesDefined","isEveryDefined"],"sources":["utils.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { Children } from 'react';\nimport { isEveryDefined } from '@fountain-ui/utils';\nimport type TabCoordinate from './TabCoordinate';\n\n\nexport function isEveryTabCoordinatesDefined(coordinates: TabCoordinate[], tabElements: ReactNode): boolean {\n const numberOfTabs = Children.count(tabElements);\n const numberOfCoordinates = coordinates.length;\n\n const everyCoordinatesDefined = isEveryDefined(coordinates);\n\n return numberOfTabs === numberOfCoordinates && everyCoordinatesDefined;\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AAIO,SAASA,4BAAT,CAAsCC,WAAtC,EAAoEC,WAApE,EAAqG;EACxG,MAAMC,YAAY,GAAGC,eAAA,CAASC,KAAT,CAAeH,WAAf,CAArB;;EACA,MAAMI,mBAAmB,GAAGL,WAAW,CAACM,MAAxC;EAEA,MAAMC,uBAAuB,GAAG,IAAAC,qBAAA,EAAeR,WAAf,CAAhC;EAEA,OAAOE,YAAY,KAAKG,mBAAjB,IAAwCE,uBAA/C;AACH"}
1
+ {"version":3,"names":["isEveryTabCoordinatesDefined","coordinates","tabElements","numberOfTabs","Children","count","numberOfCoordinates","length","everyCoordinatesDefined","isEveryDefined"],"sources":["utils.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { Children } from 'react';\nimport { isEveryDefined } from '@fountain-ui/utils';\nimport type TabCoordinate from './TabCoordinate';\n\n\nexport function isEveryTabCoordinatesDefined(coordinates: (TabCoordinate | number)[], tabElements: ReactNode): boolean {\n const numberOfTabs = Children.count(tabElements);\n const numberOfCoordinates = coordinates.length;\n\n const everyCoordinatesDefined = isEveryDefined(coordinates);\n\n return numberOfTabs === numberOfCoordinates && everyCoordinatesDefined;\n}\n"],"mappings":";;;;;;;AACA;;AACA;;AAIO,SAASA,4BAAT,CAAsCC,WAAtC,EAA+EC,WAA/E,EAAgH;EACnH,MAAMC,YAAY,GAAGC,eAAA,CAASC,KAAT,CAAeH,WAAf,CAArB;;EACA,MAAMI,mBAAmB,GAAGL,WAAW,CAACM,MAAxC;EAEA,MAAMC,uBAAuB,GAAG,IAAAC,qBAAA,EAAeR,WAAf,CAAhC;EAEA,OAAOE,YAAY,KAAKG,mBAAjB,IAAwCE,uBAA/C;AACH"}
@@ -6,6 +6,7 @@ import TabIndicator from './TabIndicator';
6
6
  import ScrollableTabsView from './ScrollableTabsView';
7
7
  import IndexAwareTab from './IndexAwareTab';
8
8
  import useTabCoordinates from './useTabCoordinates';
9
+ import useTabInnerContentsWidth from './useTabInnerContentsWidth';
9
10
  import useIndexStore from './useIndexStore';
10
11
  import InternalContext from './InternalContext';
11
12
  import { isEveryTabCoordinatesDefined } from './utils';
@@ -62,28 +63,28 @@ const Tabs = /*#__PURE__*/forwardRef(function Tabs(props, ref) {
62
63
  }), [sharedIndex]);
63
64
  const styles = useStyles();
64
65
  const [outerCoordinates, updateCoordinate] = useTabCoordinates(children);
65
- const [innerCoordinates, updateInnerCoordinate] = useTabCoordinates(children);
66
- const canRenderIndicator = indicatorSize === 'fit-content' ? isEveryTabCoordinatesDefined(innerCoordinates, children) : isEveryTabCoordinatesDefined(outerCoordinates, children);
66
+ const [innerContentsWidthList, updateInnerContentsWidth] = useTabInnerContentsWidth(children);
67
+ const canRenderIndicator = indicatorSize === 'fit-content' ? isEveryTabCoordinatesDefined(innerContentsWidthList, children) : isEveryTabCoordinatesDefined(outerCoordinates, children);
67
68
  const indexStore = useIndexStore(sharedIndex);
68
69
  const coordinates = useMemo(() => {
69
70
  if (indicatorSize !== 'fit-content') {
70
71
  return outerCoordinates;
71
72
  }
72
73
 
73
- return innerCoordinates.map((coordinate, idx) => {
74
+ return innerContentsWidthList.map((innerContentWidth, idx) => {
74
75
  const {
75
- x1,
76
- x2
77
- } = coordinate;
78
- const {
79
- x1: outerX1
76
+ x1: outerX1,
77
+ x2: outerX2
80
78
  } = outerCoordinates[idx];
79
+ const tabWidth = outerX2 - outerX1;
80
+ const distanceFromParent = (tabWidth - innerContentWidth) / 2;
81
+ const indicatorStartCoordinate = outerX1 + distanceFromParent;
81
82
  return {
82
- x1: x1 + outerX1,
83
- x2: x2 + outerX1
83
+ x1: indicatorStartCoordinate,
84
+ x2: indicatorStartCoordinate + innerContentWidth
84
85
  };
85
86
  });
86
- }, [outerCoordinates, innerCoordinates, variant]);
87
+ }, [outerCoordinates, innerContentsWidthList, variant]);
87
88
  useEffect(() => {
88
89
  return indexStore.subscribe(newIndex => {
89
90
  onChange === null || onChange === void 0 ? void 0 : onChange(newIndex);
@@ -97,10 +98,9 @@ const Tabs = /*#__PURE__*/forwardRef(function Tabs(props, ref) {
97
98
 
98
99
  const onTabInnerLayout = event => {
99
100
  const {
100
- x,
101
101
  width
102
102
  } = event.nativeEvent.layout;
103
- updateInnerCoordinate(index, x, width);
103
+ updateInnerContentsWidth(index, width);
104
104
  };
105
105
 
106
106
  const onLayout = event => {
@@ -1 +1 @@
1
- {"version":3,"names":["React","cloneElement","forwardRef","useEffect","useImperativeHandle","useMemo","useRef","View","css","useTheme","useSyncAnimatedValue","TabIndicator","ScrollableTabsView","IndexAwareTab","useTabCoordinates","useIndexStore","InternalContext","isEveryTabCoordinatesDefined","useStyles","theme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","props","ref","children","indicatorColor","initialIndex","disableIndicator","indicatorSize","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","onTabSelected","fallbackSharedIndex","initialValue","sharedIndex","realInitialIndex","currentIndexRef","setTab","newIndex","currentIndex","current","animatedValue","setValue","styles","outerCoordinates","updateCoordinate","innerCoordinates","updateInnerCoordinate","canRenderIndicator","indexStore","coordinates","map","coordinate","idx","x1","x2","outerX1","subscribe","tabElements","Children","child","index","onTabInnerLayout","event","x","width","nativeEvent","layout","onLayout","onMouseDown","e","preventDefault","onPress","tabElement","enableIndicator","undefined","filter","Boolean","tabIndicator"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';\nimport type { GestureResponderEvent, LayoutChangeEvent } from 'react-native';\nimport { View } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport { useSyncAnimatedValue } from '../hooks';\nimport type TabsProps from './TabsProps';\nimport type { TabsInstance } from './types';\nimport TabIndicator from './TabIndicator';\nimport ScrollableTabsView from './ScrollableTabsView';\nimport IndexAwareTab from './IndexAwareTab';\nimport useTabCoordinates from './useTabCoordinates';\nimport useIndexStore from './useIndexStore';\nimport InternalContext from './InternalContext';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\ntype TabsStyleKeys =\n | 'root'\n | 'fixedRoot'\n | 'fixedTab'\n | 'scrollableContainer';\n\ntype TabsStyles = NamedStylesStringUnion<TabsStyleKeys>;\n\nconst useStyles: UseStyles<TabsStyles> = function (): TabsStyles {\n const theme = useTheme();\n\n return {\n root: {},\n fixedRoot: {\n flexDirection: 'row',\n },\n fixedTab: {\n flex: 1,\n },\n scrollableContainer: {\n paddingHorizontal: theme.spacing(1),\n },\n };\n};\n\nconst Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {\n const {\n children,\n indicatorColor = 'primary',\n initialIndex = 0,\n disableIndicator = false,\n indicatorSize = 'full',\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n onTabSelected,\n } = props;\n\n const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n const realInitialIndex = sharedIndex.initialValue;\n\n const currentIndexRef = useRef(initialIndex);\n\n const setTab = (newIndex: number) => {\n const currentIndex = currentIndexRef.current;\n onTabSelected?.(newIndex, currentIndex);\n\n sharedIndex.animatedValue.setValue(newIndex);\n };\n\n useImperativeHandle(\n ref,\n () => ({\n setTab,\n }),\n [sharedIndex],\n );\n\n const styles = useStyles();\n\n const [outerCoordinates, updateCoordinate] = useTabCoordinates(children);\n const [innerCoordinates, updateInnerCoordinate] = useTabCoordinates(children);\n\n const canRenderIndicator = indicatorSize === 'fit-content'\n ? isEveryTabCoordinatesDefined(innerCoordinates, children)\n : isEveryTabCoordinatesDefined(outerCoordinates, children);\n\n const indexStore = useIndexStore(sharedIndex);\n\n const coordinates = useMemo(() => {\n if (indicatorSize !== 'fit-content') {\n return outerCoordinates;\n }\n\n return innerCoordinates.map((coordinate, idx) => {\n const { x1, x2 } = coordinate;\n const { x1: outerX1 } = outerCoordinates[idx];\n return {\n x1: x1 + outerX1,\n x2: x2 + outerX1,\n }\n });\n }, [outerCoordinates, innerCoordinates, variant]);\n\n useEffect(() => {\n return indexStore.subscribe(newIndex => {\n onChange?.(newIndex);\n currentIndexRef.current = newIndex;\n });\n }, [indexStore, onChange]);\n\n const tabElements = React.Children.map(children, (child, index) => {\n if (!child) {\n return null;\n }\n\n const onTabInnerLayout = (event: LayoutChangeEvent) => {\n const { x, width } = event.nativeEvent.layout;\n\n updateInnerCoordinate(index, x, width);\n };\n\n const onLayout = (event: LayoutChangeEvent) => {\n const { x, width } = event.nativeEvent.layout;\n\n updateCoordinate(index, x, width);\n\n // @ts-ignore\n child.props.onLayout?.(event);\n };\n\n const onMouseDown = (e: GestureResponderEvent) => {\n if (keyboardShouldPersistTaps === 'always') {\n e.preventDefault();\n }\n };\n\n const onPress = () => {\n setTab(index);\n\n // @ts-ignore\n child.props.onPress?.();\n };\n\n // @ts-ignore\n const tabElement = cloneElement(child, {\n enableIndicator: !disableIndicator && !canRenderIndicator,\n indicatorColor,\n onTabInnerLayout,\n onLayout,\n onPress,\n onMouseDown,\n variant,\n indicatorSize,\n style: scrollable ? undefined : styles.fixedTab,\n });\n\n return (\n <IndexAwareTab\n children={tabElement}\n index={index}\n initialIndex={realInitialIndex}\n />\n );\n })?.filter(Boolean);\n\n const tabIndicator = canRenderIndicator ? (\n <TabIndicator\n color={indicatorColor}\n coordinates={coordinates}\n disabled={disableIndicator}\n initialIndex={realInitialIndex}\n scrollable={scrollable}\n />\n ) : null;\n\n return (\n <InternalContext.Provider value={{ indexStore }}>\n <View\n style={css([\n styles.root,\n scrollable ? undefined : styles.fixedRoot,\n style,\n ])}\n >\n {scrollable ? (\n <ScrollableTabsView\n automaticallyAdjustContentInsets={false}\n bounces={false}\n contentContainerStyle={styles.scrollableContainer}\n coordinates={coordinates}\n directionalLockEnabled={true}\n horizontal={true}\n initialIndex={realInitialIndex}\n scrollsToTop={false}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={false}\n keyboardDismissMode={keyboardDismissMode}\n keyboardShouldPersistTaps={keyboardShouldPersistTaps}\n >\n {tabElements}\n {tabIndicator}\n </ScrollableTabsView>\n ) : (\n <React.Fragment>\n {tabElements}\n {tabIndicator}\n </React.Fragment>\n )}\n </View>\n </InternalContext.Provider>\n );\n});\n\nexport default Tabs;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,YAAhB,EAA8BC,UAA9B,EAA0CC,SAA1C,EAAqDC,mBAArD,EAA0EC,OAA1E,EAAmFC,MAAnF,QAAiG,OAAjG;AAEA,SAASC,IAAT,QAAqB,cAArB;AAEA,SAASC,GAAT,EAAcC,QAAd,QAA8B,WAA9B;AACA,SAASC,oBAAT,QAAqC,UAArC;AAGA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,kBAAP,MAA+B,sBAA/B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,SAASC,4BAAT,QAA6C,SAA7C;;AAUA,MAAMC,SAAgC,GAAG,YAAwB;EAC7D,MAAMC,KAAK,GAAGV,QAAQ,EAAtB;EAEA,OAAO;IACHW,IAAI,EAAE,EADH;IAEHC,SAAS,EAAE;MACPC,aAAa,EAAE;IADR,CAFR;IAKHC,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA,CALP;IAQHC,mBAAmB,EAAE;MACjBC,iBAAiB,EAAEP,KAAK,CAACQ,OAAN,CAAc,CAAd;IADF;EARlB,CAAP;AAYH,CAfD;;AAiBA,MAAMC,IAAI,gBAAG1B,UAAU,CAA0B,SAAS0B,IAAT,CAAcC,KAAd,EAAqBC,GAArB,EAA0B;EAAA;;EACvE,MAAM;IACFC,QADE;IAEFC,cAAc,GAAG,SAFf;IAGFC,YAAY,GAAG,CAHb;IAIFC,gBAAgB,GAAG,KAJjB;IAKFC,aAAa,GAAG,MALd;IAMFC,mBAAmB,GAAG,MANpB;IAOFC,yBAAyB,GAAG,OAP1B;IAQFC,QARE;IASFC,UAAU,GAAG,KATX;IAUFC,KAVE;IAWFC,OA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ADd,GAOKD,UAAU,gBACP,oBAAC,kBAAD;IACI,gCAAgC,EAAE,KADtC;IAEI,OAAO,EAAE,KAFb;IAGI,qBAAqB,EAAEgB,MAAM,CAAC9B,mBAHlC;IAII,WAAW,EAAEqC,WAJjB;IAKI,sBAAsB,EAAE,IAL5B;IAMI,UAAU,EAAE,IANhB;IAOI,YAAY,EAAEf,gBAPlB;IAQI,YAAY,EAAE,KARlB;IASI,8BAA8B,EAAE,KATpC;IAUI,4BAA4B,EAAE,KAVlC;IAWI,mBAAmB,EAAEX,mBAXzB;IAYI,yBAAyB,EAAEC;EAZ/B,GAcKiC,WAdL,EAeKoB,YAfL,CADO,gBAmBP,oBAAC,KAAD,CAAO,QAAP,QACKpB,WADL,EAEKoB,YAFL,CA1BR,CADJ,CADJ;AAoCH,CA5KsB,CAAvB;AA8KA,eAAe9D,IAAf"}
1
+ {"version":3,"names":["React","cloneElement","forwardRef","useEffect","useImperativeHandle","useMemo","useRef","View","css","useTheme","useSyncAnimatedValue","TabIndicator","ScrollableTabsView","IndexAwareTab","useTabCoordinates","useTabInnerContentsWidth","useIndexStore","InternalContext","isEveryTabCoordinatesDefined","useStyles","theme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","props","ref","children","indicatorColor","initialIndex","disableIndicator","indicatorSize","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","onTabSelected","fallbackSharedIndex","initialValue","sharedIndex","realInitialIndex","currentIndexRef","setTab","newIndex","currentIndex","current","animatedValue","setValue","styles","outerCoordinates","updateCoordinate","innerContentsWidthList","updateInnerContentsWidth","canRenderIndicator","indexStore","coordinates","map","innerContentWidth","idx","x1","outerX1","x2","outerX2","tabWidth","distanceFromParent","indicatorStartCoordinate","subscribe","tabElements","Children","child","index","onTabInnerLayout","event","width","nativeEvent","layout","onLayout","x","onMouseDown","e","preventDefault","onPress","tabElement","enableIndicator","undefined","filter","Boolean","tabIndicator"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';\nimport type { GestureResponderEvent, LayoutChangeEvent } from 'react-native';\nimport { View } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport { useSyncAnimatedValue } from '../hooks';\nimport type TabsProps from './TabsProps';\nimport type { TabsInstance } from './types';\nimport TabIndicator from './TabIndicator';\nimport ScrollableTabsView from './ScrollableTabsView';\nimport IndexAwareTab from './IndexAwareTab';\nimport useTabCoordinates from './useTabCoordinates';\nimport useTabInnerContentsWidth from './useTabInnerContentsWidth';\nimport useIndexStore from './useIndexStore';\nimport InternalContext from './InternalContext';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\ntype TabsStyleKeys =\n | 'root'\n | 'fixedRoot'\n | 'fixedTab'\n | 'scrollableContainer';\n\ntype TabsStyles = NamedStylesStringUnion<TabsStyleKeys>;\n\nconst useStyles: UseStyles<TabsStyles> = function (): TabsStyles {\n const theme = useTheme();\n\n return {\n root: {},\n fixedRoot: {\n flexDirection: 'row',\n },\n fixedTab: {\n flex: 1,\n },\n scrollableContainer: {\n paddingHorizontal: theme.spacing(1),\n },\n };\n};\n\nconst Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {\n const {\n children,\n indicatorColor = 'primary',\n initialIndex = 0,\n disableIndicator = false,\n indicatorSize = 'full',\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n onTabSelected,\n } = props;\n\n const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n const realInitialIndex = sharedIndex.initialValue;\n\n const currentIndexRef = useRef(initialIndex);\n\n const setTab = (newIndex: number) => {\n const currentIndex = currentIndexRef.current;\n onTabSelected?.(newIndex, currentIndex);\n\n sharedIndex.animatedValue.setValue(newIndex);\n };\n\n useImperativeHandle(\n ref,\n () => ({\n setTab,\n }),\n [sharedIndex],\n );\n\n const styles = useStyles();\n\n const [outerCoordinates, updateCoordinate] = useTabCoordinates(children);\n const [innerContentsWidthList, updateInnerContentsWidth] = useTabInnerContentsWidth(children);\n\n const canRenderIndicator = indicatorSize === 'fit-content'\n ? isEveryTabCoordinatesDefined(innerContentsWidthList, children)\n : isEveryTabCoordinatesDefined(outerCoordinates, children);\n\n const indexStore = useIndexStore(sharedIndex);\n\n const coordinates = useMemo(() => {\n if (indicatorSize !== 'fit-content') {\n return outerCoordinates;\n }\n\n return innerContentsWidthList.map((innerContentWidth, idx) => {\n const { x1: outerX1, x2: outerX2 } = outerCoordinates[idx];\n\n const tabWidth = outerX2 - outerX1;\n const distanceFromParent = (tabWidth - innerContentWidth) / 2;\n const indicatorStartCoordinate = outerX1 + distanceFromParent;\n\n return {\n x1: indicatorStartCoordinate,\n x2: indicatorStartCoordinate + innerContentWidth,\n };\n });\n }, [outerCoordinates, innerContentsWidthList, variant]);\n\n useEffect(() => {\n return indexStore.subscribe(newIndex => {\n onChange?.(newIndex);\n currentIndexRef.current = newIndex;\n });\n }, [indexStore, onChange]);\n\n const tabElements = React.Children.map(children, (child, index) => {\n if (!child) {\n return null;\n }\n\n const onTabInnerLayout = (event: LayoutChangeEvent) => {\n const { width } = event.nativeEvent.layout;\n\n updateInnerContentsWidth(index, width);\n };\n\n const onLayout = (event: LayoutChangeEvent) => {\n const { x, width } = event.nativeEvent.layout;\n\n updateCoordinate(index, x, width);\n\n // @ts-ignore\n child.props.onLayout?.(event);\n };\n\n const onMouseDown = (e: GestureResponderEvent) => {\n if (keyboardShouldPersistTaps === 'always') {\n e.preventDefault();\n }\n };\n\n const onPress = () => {\n setTab(index);\n\n // @ts-ignore\n child.props.onPress?.();\n };\n\n // @ts-ignore\n const tabElement = cloneElement(child, {\n enableIndicator: !disableIndicator && !canRenderIndicator,\n indicatorColor,\n onTabInnerLayout,\n onLayout,\n onPress,\n onMouseDown,\n variant,\n indicatorSize,\n style: scrollable ? undefined : styles.fixedTab,\n });\n\n return (\n <IndexAwareTab\n children={tabElement}\n index={index}\n initialIndex={realInitialIndex}\n />\n );\n })?.filter(Boolean);\n\n const tabIndicator = canRenderIndicator ? (\n <TabIndicator\n color={indicatorColor}\n coordinates={coordinates}\n disabled={disableIndicator}\n initialIndex={realInitialIndex}\n scrollable={scrollable}\n />\n ) : null;\n\n return (\n <InternalContext.Provider value={{ indexStore }}>\n <View\n style={css([\n styles.root,\n scrollable ? undefined : styles.fixedRoot,\n style,\n ])}\n >\n {scrollable ? (\n <ScrollableTabsView\n automaticallyAdjustContentInsets={false}\n bounces={false}\n contentContainerStyle={styles.scrollableContainer}\n coordinates={coordinates}\n directionalLockEnabled={true}\n horizontal={true}\n initialIndex={realInitialIndex}\n scrollsToTop={false}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={false}\n keyboardDismissMode={keyboardDismissMode}\n keyboardShouldPersistTaps={keyboardShouldPersistTaps}\n >\n {tabElements}\n {tabIndicator}\n </ScrollableTabsView>\n ) : (\n <React.Fragment>\n {tabElements}\n {tabIndicator}\n </React.Fragment>\n )}\n </View>\n </InternalContext.Provider>\n );\n});\n\nexport default Tabs;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,YAAhB,EAA8BC,UAA9B,EAA0CC,SAA1C,EAAqDC,mBAArD,EAA0EC,OAA1E,EAAmFC,MAAnF,QAAiG,OAAjG;AAEA,SAASC,IAAT,QAAqB,cAArB;AAEA,SAASC,GAAT,EAAcC,QAAd,QAA8B,WAA9B;AACA,SAASC,oBAAT,QAAqC,UAArC;AAGA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,kBAAP,MAA+B,sBAA/B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,wBAAP,MAAqC,4BAArC;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;IAYI,yBAAyB,EAAEC;EAZ/B,GAcKqC,WAdL,EAeKoB,YAfL,CADO,gBAmBP,oBAAC,KAAD,CAAO,QAAP,QACKpB,WADL,EAEKoB,YAFL,CA1BR,CADJ,CADJ;AAoCH,CAhLsB,CAAvB;AAkLA,eAAelE,IAAf"}
@@ -0,0 +1,21 @@
1
+ import { useRef, useState } from 'react';
2
+ import { isEveryTabCoordinatesDefined } from './utils';
3
+
4
+ const useTabInnerContentsWidth = tabElements => {
5
+ const [innerContentsWidthList, setInnerContentsWidth] = useState([]);
6
+ const cacheRef = useRef([]);
7
+
8
+ const updateInnerContentsWidth = (index, width) => {
9
+ cacheRef.current[index] = width;
10
+
11
+ if (isEveryTabCoordinatesDefined(cacheRef.current, tabElements)) {
12
+ setInnerContentsWidth([...cacheRef.current]);
13
+ cacheRef.current = [];
14
+ }
15
+ };
16
+
17
+ return [innerContentsWidthList, updateInnerContentsWidth];
18
+ };
19
+
20
+ export default useTabInnerContentsWidth;
21
+ //# sourceMappingURL=useTabInnerContentsWidth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useRef","useState","isEveryTabCoordinatesDefined","useTabInnerContentsWidth","tabElements","innerContentsWidthList","setInnerContentsWidth","cacheRef","updateInnerContentsWidth","index","width","current"],"sources":["useTabInnerContentsWidth.ts"],"sourcesContent":["import React, { useRef, useState } from 'react';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\nexport interface UpdateInnerContentsWidth {\n (index: number, width: number): void;\n}\n\nconst useTabInnerContentsWidth = (tabElements: React.ReactNode): [number[], UpdateInnerContentsWidth] => {\n const [innerContentsWidthList, setInnerContentsWidth] = useState<number[]>([]);\n\n const cacheRef = useRef<number[]>([]);\n\n const updateInnerContentsWidth: UpdateInnerContentsWidth = (index, width) => {\n cacheRef.current[index] = width;\n\n if (isEveryTabCoordinatesDefined(cacheRef.current, tabElements)) {\n setInnerContentsWidth([...cacheRef.current]);\n\n cacheRef.current = [];\n }\n };\n\n return [innerContentsWidthList, updateInnerContentsWidth];\n};\n\nexport default useTabInnerContentsWidth;\n"],"mappings":"AAAA,SAAgBA,MAAhB,EAAwBC,QAAxB,QAAwC,OAAxC;AACA,SAASC,4BAAT,QAA6C,SAA7C;;AAMA,MAAMC,wBAAwB,GAAIC,WAAD,IAAwE;EACrG,MAAM,CAACC,sBAAD,EAAyBC,qBAAzB,IAAkDL,QAAQ,CAAW,EAAX,CAAhE;EAEA,MAAMM,QAAQ,GAAGP,MAAM,CAAW,EAAX,CAAvB;;EAEA,MAAMQ,wBAAkD,GAAG,CAACC,KAAD,EAAQC,KAAR,KAAkB;IACzEH,QAAQ,CAACI,OAAT,CAAiBF,KAAjB,IAA0BC,KAA1B;;IAEA,IAAIR,4BAA4B,CAACK,QAAQ,CAACI,OAAV,EAAmBP,WAAnB,CAAhC,EAAiE;MAC7DE,qBAAqB,CAAC,CAAC,GAAGC,QAAQ,CAACI,OAAb,CAAD,CAArB;MAEAJ,QAAQ,CAACI,OAAT,GAAmB,EAAnB;IACH;EACJ,CARD;;EAUA,OAAO,CAACN,sBAAD,EAAyBG,wBAAzB,CAAP;AACH,CAhBD;;AAkBA,eAAeL,wBAAf"}
@@ -1 +1 @@
1
- {"version":3,"names":["Children","isEveryDefined","isEveryTabCoordinatesDefined","coordinates","tabElements","numberOfTabs","count","numberOfCoordinates","length","everyCoordinatesDefined"],"sources":["utils.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { Children } from 'react';\nimport { isEveryDefined } from '@fountain-ui/utils';\nimport type TabCoordinate from './TabCoordinate';\n\n\nexport function isEveryTabCoordinatesDefined(coordinates: TabCoordinate[], tabElements: ReactNode): boolean {\n const numberOfTabs = Children.count(tabElements);\n const numberOfCoordinates = coordinates.length;\n\n const everyCoordinatesDefined = isEveryDefined(coordinates);\n\n return numberOfTabs === numberOfCoordinates && everyCoordinatesDefined;\n}\n"],"mappings":"AACA,SAASA,QAAT,QAAyB,OAAzB;AACA,SAASC,cAAT,QAA+B,oBAA/B;AAIA,OAAO,SAASC,4BAAT,CAAsCC,WAAtC,EAAoEC,WAApE,EAAqG;EACxG,MAAMC,YAAY,GAAGL,QAAQ,CAACM,KAAT,CAAeF,WAAf,CAArB;EACA,MAAMG,mBAAmB,GAAGJ,WAAW,CAACK,MAAxC;EAEA,MAAMC,uBAAuB,GAAGR,cAAc,CAACE,WAAD,CAA9C;EAEA,OAAOE,YAAY,KAAKE,mBAAjB,IAAwCE,uBAA/C;AACH"}
1
+ {"version":3,"names":["Children","isEveryDefined","isEveryTabCoordinatesDefined","coordinates","tabElements","numberOfTabs","count","numberOfCoordinates","length","everyCoordinatesDefined"],"sources":["utils.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { Children } from 'react';\nimport { isEveryDefined } from '@fountain-ui/utils';\nimport type TabCoordinate from './TabCoordinate';\n\n\nexport function isEveryTabCoordinatesDefined(coordinates: (TabCoordinate | number)[], tabElements: ReactNode): boolean {\n const numberOfTabs = Children.count(tabElements);\n const numberOfCoordinates = coordinates.length;\n\n const everyCoordinatesDefined = isEveryDefined(coordinates);\n\n return numberOfTabs === numberOfCoordinates && everyCoordinatesDefined;\n}\n"],"mappings":"AACA,SAASA,QAAT,QAAyB,OAAzB;AACA,SAASC,cAAT,QAA+B,oBAA/B;AAIA,OAAO,SAASC,4BAAT,CAAsCC,WAAtC,EAA+EC,WAA/E,EAAgH;EACnH,MAAMC,YAAY,GAAGL,QAAQ,CAACM,KAAT,CAAeF,WAAf,CAArB;EACA,MAAMG,mBAAmB,GAAGJ,WAAW,CAACK,MAAxC;EAEA,MAAMC,uBAAuB,GAAGR,cAAc,CAACE,WAAD,CAA9C;EAEA,OAAOE,YAAY,KAAKE,mBAAjB,IAAwCE,uBAA/C;AACH"}
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export interface UpdateInnerContentsWidth {
3
+ (index: number, width: number): void;
4
+ }
5
+ declare const useTabInnerContentsWidth: (tabElements: React.ReactNode) => [number[], UpdateInnerContentsWidth];
6
+ export default useTabInnerContentsWidth;
@@ -1,3 +1,3 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type TabCoordinate from './TabCoordinate';
3
- export declare function isEveryTabCoordinatesDefined(coordinates: TabCoordinate[], tabElements: ReactNode): boolean;
3
+ export declare function isEveryTabCoordinatesDefined(coordinates: (TabCoordinate | number)[], tabElements: ReactNode): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fountain-ui/core",
3
- "version": "2.0.0-beta.76",
3
+ "version": "2.0.0-beta.77",
4
4
  "author": "Fountain-UI Team",
5
5
  "description": "React components that implement Tappytoon's Fountain Design.",
6
6
  "license": "MIT",
@@ -67,5 +67,5 @@
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  },
70
- "gitHead": "cc48805efae8ceeab7e10b5e39dba30136d3a6e4"
70
+ "gitHead": "3edf58805967bc1a5f73ed1d5833fa5a55f59504"
71
71
  }
package/src/Tabs/Tabs.tsx CHANGED
@@ -10,6 +10,7 @@ import TabIndicator from './TabIndicator';
10
10
  import ScrollableTabsView from './ScrollableTabsView';
11
11
  import IndexAwareTab from './IndexAwareTab';
12
12
  import useTabCoordinates from './useTabCoordinates';
13
+ import useTabInnerContentsWidth from './useTabInnerContentsWidth';
13
14
  import useIndexStore from './useIndexStore';
14
15
  import InternalContext from './InternalContext';
15
16
  import { isEveryTabCoordinatesDefined } from './utils';
@@ -80,10 +81,10 @@ const Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {
80
81
  const styles = useStyles();
81
82
 
82
83
  const [outerCoordinates, updateCoordinate] = useTabCoordinates(children);
83
- const [innerCoordinates, updateInnerCoordinate] = useTabCoordinates(children);
84
+ const [innerContentsWidthList, updateInnerContentsWidth] = useTabInnerContentsWidth(children);
84
85
 
85
86
  const canRenderIndicator = indicatorSize === 'fit-content'
86
- ? isEveryTabCoordinatesDefined(innerCoordinates, children)
87
+ ? isEveryTabCoordinatesDefined(innerContentsWidthList, children)
87
88
  : isEveryTabCoordinatesDefined(outerCoordinates, children);
88
89
 
89
90
  const indexStore = useIndexStore(sharedIndex);
@@ -93,15 +94,19 @@ const Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {
93
94
  return outerCoordinates;
94
95
  }
95
96
 
96
- return innerCoordinates.map((coordinate, idx) => {
97
- const { x1, x2 } = coordinate;
98
- const { x1: outerX1 } = outerCoordinates[idx];
97
+ return innerContentsWidthList.map((innerContentWidth, idx) => {
98
+ const { x1: outerX1, x2: outerX2 } = outerCoordinates[idx];
99
+
100
+ const tabWidth = outerX2 - outerX1;
101
+ const distanceFromParent = (tabWidth - innerContentWidth) / 2;
102
+ const indicatorStartCoordinate = outerX1 + distanceFromParent;
103
+
99
104
  return {
100
- x1: x1 + outerX1,
101
- x2: x2 + outerX1,
102
- }
105
+ x1: indicatorStartCoordinate,
106
+ x2: indicatorStartCoordinate + innerContentWidth,
107
+ };
103
108
  });
104
- }, [outerCoordinates, innerCoordinates, variant]);
109
+ }, [outerCoordinates, innerContentsWidthList, variant]);
105
110
 
106
111
  useEffect(() => {
107
112
  return indexStore.subscribe(newIndex => {
@@ -116,9 +121,9 @@ const Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {
116
121
  }
117
122
 
118
123
  const onTabInnerLayout = (event: LayoutChangeEvent) => {
119
- const { x, width } = event.nativeEvent.layout;
124
+ const { width } = event.nativeEvent.layout;
120
125
 
121
- updateInnerCoordinate(index, x, width);
126
+ updateInnerContentsWidth(index, width);
122
127
  };
123
128
 
124
129
  const onLayout = (event: LayoutChangeEvent) => {
@@ -0,0 +1,26 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { isEveryTabCoordinatesDefined } from './utils';
3
+
4
+ export interface UpdateInnerContentsWidth {
5
+ (index: number, width: number): void;
6
+ }
7
+
8
+ const useTabInnerContentsWidth = (tabElements: React.ReactNode): [number[], UpdateInnerContentsWidth] => {
9
+ const [innerContentsWidthList, setInnerContentsWidth] = useState<number[]>([]);
10
+
11
+ const cacheRef = useRef<number[]>([]);
12
+
13
+ const updateInnerContentsWidth: UpdateInnerContentsWidth = (index, width) => {
14
+ cacheRef.current[index] = width;
15
+
16
+ if (isEveryTabCoordinatesDefined(cacheRef.current, tabElements)) {
17
+ setInnerContentsWidth([...cacheRef.current]);
18
+
19
+ cacheRef.current = [];
20
+ }
21
+ };
22
+
23
+ return [innerContentsWidthList, updateInnerContentsWidth];
24
+ };
25
+
26
+ export default useTabInnerContentsWidth;
package/src/Tabs/utils.ts CHANGED
@@ -4,7 +4,7 @@ import { isEveryDefined } from '@fountain-ui/utils';
4
4
  import type TabCoordinate from './TabCoordinate';
5
5
 
6
6
 
7
- export function isEveryTabCoordinatesDefined(coordinates: TabCoordinate[], tabElements: ReactNode): boolean {
7
+ export function isEveryTabCoordinatesDefined(coordinates: (TabCoordinate | number)[], tabElements: ReactNode): boolean {
8
8
  const numberOfTabs = Children.count(tabElements);
9
9
  const numberOfCoordinates = coordinates.length;
10
10