@fountain-ui/core 2.0.0-beta.15 → 2.0.0-beta.18

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.
Files changed (111) hide show
  1. package/build/commonjs/Tabs/IndexAwareTab.js +13 -7
  2. package/build/commonjs/Tabs/IndexAwareTab.js.map +1 -1
  3. package/build/commonjs/Tabs/InternalContext.js +17 -0
  4. package/build/commonjs/Tabs/InternalContext.js.map +1 -0
  5. package/build/commonjs/Tabs/ScrollableTabsView.js +34 -0
  6. package/build/commonjs/Tabs/ScrollableTabsView.js.map +1 -0
  7. package/build/commonjs/Tabs/TabIndicator.js +46 -19
  8. package/build/commonjs/Tabs/TabIndicator.js.map +1 -1
  9. package/build/commonjs/Tabs/TabIndicatorProps.js.map +1 -1
  10. package/build/commonjs/Tabs/Tabs.js +23 -21
  11. package/build/commonjs/Tabs/Tabs.js.map +1 -1
  12. package/build/commonjs/Tabs/TabsProps.js.map +1 -1
  13. package/build/commonjs/Tabs/index.js.map +1 -1
  14. package/build/commonjs/Tabs/types.js +2 -0
  15. package/build/commonjs/Tabs/types.js.map +1 -0
  16. package/build/commonjs/Tabs/useIndexStore.js +35 -0
  17. package/build/commonjs/Tabs/useIndexStore.js.map +1 -0
  18. package/build/commonjs/Tabs/useScrollViewReaction.js +23 -27
  19. package/build/commonjs/Tabs/useScrollViewReaction.js.map +1 -1
  20. package/build/commonjs/hooks/index.js +8 -0
  21. package/build/commonjs/hooks/index.js.map +1 -1
  22. package/build/commonjs/hooks/useCollapsibleAppBar.js +1 -1
  23. package/build/commonjs/hooks/useCollapsibleAppBar.js.map +1 -1
  24. package/build/commonjs/hooks/useSyncAnimatedValue.js +37 -0
  25. package/build/commonjs/hooks/useSyncAnimatedValue.js.map +1 -0
  26. package/build/commonjs/index.js +14 -0
  27. package/build/commonjs/index.js.map +1 -1
  28. package/build/commonjs/store/MockStore.js +23 -0
  29. package/build/commonjs/store/MockStore.js.map +1 -0
  30. package/build/commonjs/store/SimpleStore.js +45 -0
  31. package/build/commonjs/store/SimpleStore.js.map +1 -0
  32. package/build/commonjs/store/index.js +24 -0
  33. package/build/commonjs/store/index.js.map +1 -0
  34. package/build/commonjs/store/types.js +2 -0
  35. package/build/commonjs/store/types.js.map +1 -0
  36. package/build/commonjs/types/index.js.map +1 -1
  37. package/build/module/Tabs/IndexAwareTab.js +12 -8
  38. package/build/module/Tabs/IndexAwareTab.js.map +1 -1
  39. package/build/module/Tabs/InternalContext.js +7 -0
  40. package/build/module/Tabs/InternalContext.js.map +1 -0
  41. package/build/module/Tabs/ScrollableTabsView.js +21 -0
  42. package/build/module/Tabs/ScrollableTabsView.js.map +1 -0
  43. package/build/module/Tabs/TabIndicator.js +44 -17
  44. package/build/module/Tabs/TabIndicator.js.map +1 -1
  45. package/build/module/Tabs/TabIndicatorProps.js.map +1 -1
  46. package/build/module/Tabs/Tabs.js +21 -21
  47. package/build/module/Tabs/Tabs.js.map +1 -1
  48. package/build/module/Tabs/TabsProps.js.map +1 -1
  49. package/build/module/Tabs/index.js.map +1 -1
  50. package/build/module/Tabs/types.js +2 -0
  51. package/build/module/Tabs/types.js.map +1 -0
  52. package/build/module/Tabs/useIndexStore.js +25 -0
  53. package/build/module/Tabs/useIndexStore.js.map +1 -0
  54. package/build/module/Tabs/useScrollViewReaction.js +23 -28
  55. package/build/module/Tabs/useScrollViewReaction.js.map +1 -1
  56. package/build/module/hooks/index.js +1 -0
  57. package/build/module/hooks/index.js.map +1 -1
  58. package/build/module/hooks/useCollapsibleAppBar.js +1 -1
  59. package/build/module/hooks/useCollapsibleAppBar.js.map +1 -1
  60. package/build/module/hooks/useSyncAnimatedValue.js +27 -0
  61. package/build/module/hooks/useSyncAnimatedValue.js.map +1 -0
  62. package/build/module/index.js +1 -0
  63. package/build/module/index.js.map +1 -1
  64. package/build/module/store/MockStore.js +14 -0
  65. package/build/module/store/MockStore.js.map +1 -0
  66. package/build/module/store/SimpleStore.js +36 -0
  67. package/build/module/store/SimpleStore.js.map +1 -0
  68. package/build/module/store/index.js +3 -0
  69. package/build/module/store/index.js.map +1 -0
  70. package/build/module/store/types.js +2 -0
  71. package/build/module/store/types.js.map +1 -0
  72. package/build/module/types/index.js.map +1 -1
  73. package/build/typescript/Tabs/IndexAwareTab.d.ts +0 -2
  74. package/build/typescript/Tabs/InternalContext.d.ts +7 -0
  75. package/build/typescript/Tabs/ScrollableTabsView.d.ts +6 -0
  76. package/build/typescript/Tabs/TabIndicatorProps.d.ts +4 -5
  77. package/build/typescript/Tabs/Tabs.d.ts +1 -1
  78. package/build/typescript/Tabs/TabsProps.d.ts +3 -16
  79. package/build/typescript/Tabs/index.d.ts +2 -1
  80. package/build/typescript/Tabs/types.d.ts +9 -0
  81. package/build/typescript/Tabs/useIndexStore.d.ts +3 -0
  82. package/build/typescript/Tabs/useScrollViewReaction.d.ts +1 -2
  83. package/build/typescript/hooks/index.d.ts +1 -0
  84. package/build/typescript/hooks/useSyncAnimatedValue.d.ts +6 -0
  85. package/build/typescript/index.d.ts +1 -0
  86. package/build/typescript/store/MockStore.d.ts +6 -0
  87. package/build/typescript/store/SimpleStore.d.ts +9 -0
  88. package/build/typescript/store/index.d.ts +3 -0
  89. package/build/typescript/store/types.d.ts +8 -0
  90. package/build/typescript/types/index.d.ts +6 -0
  91. package/package.json +4 -4
  92. package/src/Tabs/IndexAwareTab.tsx +10 -13
  93. package/src/Tabs/InternalContext.ts +13 -0
  94. package/src/Tabs/ScrollableTabsView.tsx +26 -0
  95. package/src/Tabs/TabIndicator.tsx +37 -21
  96. package/src/Tabs/TabIndicatorProps.ts +4 -5
  97. package/src/Tabs/Tabs.tsx +43 -44
  98. package/src/Tabs/TabsProps.ts +4 -28
  99. package/src/Tabs/index.ts +2 -1
  100. package/src/Tabs/types.ts +18 -0
  101. package/src/Tabs/useIndexStore.ts +31 -0
  102. package/src/Tabs/useScrollViewReaction.ts +15 -26
  103. package/src/hooks/index.ts +1 -0
  104. package/src/hooks/useCollapsibleAppBar.ts +1 -1
  105. package/src/hooks/useSyncAnimatedValue.ts +37 -0
  106. package/src/index.ts +2 -0
  107. package/src/store/MockStore.ts +17 -0
  108. package/src/store/SimpleStore.ts +36 -0
  109. package/src/store/index.ts +3 -0
  110. package/src/store/types.ts +9 -0
  111. package/src/types/index.ts +7 -0
@@ -7,18 +7,24 @@ exports.default = IndexAwareTab;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
- var _reactNativeReanimated = require("react-native-reanimated");
10
+ var _InternalContext = _interopRequireDefault(require("./InternalContext"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
13
 
12
14
  function IndexAwareTab(props) {
13
15
  const {
14
16
  children,
15
- index,
16
- sharedIndex
17
+ index
17
18
  } = props;
18
- const [selected, setSelected] = (0, _react.useState)(index === sharedIndex.value);
19
- (0, _reactNativeReanimated.useAnimatedReaction)(() => index === sharedIndex.value, result => {
20
- (0, _reactNativeReanimated.runOnJS)(setSelected)(result);
21
- }, [index]);
19
+ const [selected, setSelected] = (0, _react.useState)(false);
20
+ const {
21
+ indexStore
22
+ } = (0, _react.useContext)(_InternalContext.default);
23
+ (0, _react.useEffect)(() => {
24
+ return indexStore.subscribe(currentIndex => {
25
+ setSelected(currentIndex === index);
26
+ });
27
+ }, [indexStore, index]);
22
28
  return /*#__PURE__*/(0, _react.cloneElement)(children, {
23
29
  selected
24
30
  });
@@ -1 +1 @@
1
- {"version":3,"names":["IndexAwareTab","props","children","index","sharedIndex","selected","setSelected","useState","value","useAnimatedReaction","result","runOnJS","cloneElement"],"sources":["IndexAwareTab.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { cloneElement, useState } from 'react';\nimport type { SharedValue } from 'react-native-reanimated';\nimport { runOnJS, useAnimatedReaction } from 'react-native-reanimated';\n\nexport interface IndexAwareTabProps {\n children: ReactElement;\n index: number;\n sharedIndex: SharedValue<number>;\n}\n\nexport default function IndexAwareTab(props: IndexAwareTabProps) {\n const {\n children,\n index,\n sharedIndex,\n } = props;\n\n const [selected, setSelected] = useState(index === sharedIndex.value);\n\n useAnimatedReaction(\n () => index === sharedIndex.value,\n (result) => {\n runOnJS(setSelected)(result);\n },\n [index],\n );\n\n return cloneElement(children, { selected });\n};\n"],"mappings":";;;;;;;AACA;;AAEA;;AAQe,SAASA,aAAT,CAAuBC,KAAvB,EAAkD;EAC7D,MAAM;IACFC,QADE;IAEFC,KAFE;IAGFC;EAHE,IAIFH,KAJJ;EAMA,MAAM,CAACI,QAAD,EAAWC,WAAX,IAA0B,IAAAC,eAAA,EAASJ,KAAK,KAAKC,WAAW,CAACI,KAA/B,CAAhC;EAEA,IAAAC,0CAAA,EACI,MAAMN,KAAK,KAAKC,WAAW,CAACI,KADhC,EAEKE,MAAD,IAAY;IACR,IAAAC,8BAAA,EAAQL,WAAR,EAAqBI,MAArB;EACH,CAJL,EAKI,CAACP,KAAD,CALJ;EAQA,oBAAO,IAAAS,mBAAA,EAAaV,QAAb,EAAuB;IAAEG;EAAF,CAAvB,CAAP;AACH;;AAAA"}
1
+ {"version":3,"names":["IndexAwareTab","props","children","index","selected","setSelected","useState","indexStore","useContext","InternalContext","useEffect","subscribe","currentIndex","cloneElement"],"sources":["IndexAwareTab.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { cloneElement, useContext, useEffect, useState } from 'react';\nimport InternalContext from './InternalContext';\n\nexport interface IndexAwareTabProps {\n children: ReactElement;\n index: number;\n}\n\nexport default function IndexAwareTab(props: IndexAwareTabProps) {\n const {\n children,\n index,\n } = props;\n\n const [selected, setSelected] = useState(false);\n\n const { indexStore } = useContext(InternalContext);\n\n useEffect(() => {\n return indexStore.subscribe((currentIndex) => {\n setSelected(currentIndex === index);\n });\n }, [indexStore, index]);\n\n return cloneElement(children, { selected });\n};\n"],"mappings":";;;;;;;AACA;;AACA;;;;AAOe,SAASA,aAAT,CAAuBC,KAAvB,EAAkD;EAC7D,MAAM;IACFC,QADE;IAEFC;EAFE,IAGFF,KAHJ;EAKA,MAAM,CAACG,QAAD,EAAWC,WAAX,IAA0B,IAAAC,eAAA,EAAS,KAAT,CAAhC;EAEA,MAAM;IAAEC;EAAF,IAAiB,IAAAC,iBAAA,EAAWC,wBAAX,CAAvB;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACZ,OAAOH,UAAU,CAACI,SAAX,CAAsBC,YAAD,IAAkB;MAC1CP,WAAW,CAACO,YAAY,KAAKT,KAAlB,CAAX;IACH,CAFM,CAAP;EAGH,CAJD,EAIG,CAACI,UAAD,EAAaJ,KAAb,CAJH;EAMA,oBAAO,IAAAU,mBAAA,EAAaX,QAAb,EAAuB;IAAEE;EAAF,CAAvB,CAAP;AACH;;AAAA"}
@@ -0,0 +1,17 @@
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 _store = require("../store");
11
+
12
+ const InternalContext = /*#__PURE__*/(0, _react.createContext)({
13
+ indexStore: new _store.MockStore()
14
+ });
15
+ var _default = InternalContext;
16
+ exports.default = _default;
17
+ //# sourceMappingURL=InternalContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["InternalContext","createContext","indexStore","MockStore"],"sources":["InternalContext.ts"],"sourcesContent":["import { createContext } from 'react';\nimport type { MonoStore } from '../store';\nimport { MockStore } from '../store';\n\nexport interface InternalContextValue {\n indexStore: MonoStore<number>;\n}\n\nconst InternalContext = createContext<InternalContextValue>({\n indexStore: new MockStore(),\n});\n\nexport default InternalContext;\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAMA,MAAMA,eAAe,gBAAG,IAAAC,oBAAA,EAAoC;EACxDC,UAAU,EAAE,IAAIC,gBAAJ;AAD4C,CAApC,CAAxB;eAIeH,e"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = ScrollableTabsView;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _reactNative = require("react-native");
11
+
12
+ var _useScrollViewReaction = _interopRequireDefault(require("./useScrollViewReaction"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
17
+
18
+ function ScrollableTabsView(props) {
19
+ const {
20
+ coordinates,
21
+ ...scrollViewProps
22
+ } = props;
23
+ const {
24
+ scrollViewRef,
25
+ onLayout
26
+ } = (0, _useScrollViewReaction.default)(coordinates);
27
+ return /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, _extends({
28
+ ref: scrollViewRef,
29
+ onLayout: onLayout
30
+ }, scrollViewProps));
31
+ }
32
+
33
+ ;
34
+ //# sourceMappingURL=ScrollableTabsView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ScrollableTabsView","props","coordinates","scrollViewProps","scrollViewRef","onLayout","useScrollViewReaction"],"sources":["ScrollableTabsView.tsx"],"sourcesContent":["import React from 'react';\nimport type { ScrollViewProps } from 'react-native';\nimport { ScrollView } from 'react-native';\nimport TabCoordinate from './TabCoordinate';\nimport useScrollViewReaction from './useScrollViewReaction';\n\nexport interface ScrollableTabsViewProps extends ScrollViewProps {\n coordinates: TabCoordinate[];\n}\n\nexport default function ScrollableTabsView(props: ScrollableTabsViewProps) {\n const {\n coordinates,\n ...scrollViewProps\n } = props;\n\n const { scrollViewRef, onLayout } = useScrollViewReaction(coordinates);\n\n return (\n <ScrollView\n ref={scrollViewRef}\n onLayout={onLayout}\n {...scrollViewProps}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;;;;;AAMe,SAASA,kBAAT,CAA4BC,KAA5B,EAA4D;EACvE,MAAM;IACFC,WADE;IAEF,GAAGC;EAFD,IAGFF,KAHJ;EAKA,MAAM;IAAEG,aAAF;IAAiBC;EAAjB,IAA8B,IAAAC,8BAAA,EAAsBJ,WAAtB,CAApC;EAEA,oBACI,6BAAC,uBAAD;IACI,GAAG,EAAEE,aADT;IAEI,QAAQ,EAAEC;EAFd,GAGQF,eAHR,EADJ;AAOH;;AAAA"}
@@ -5,20 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = TabIndicator;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
- var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
10
+ var _reactNative = require("react-native");
11
11
 
12
12
  var _styles = require("../styles");
13
13
 
14
14
  var _TabCoordinate = require("./TabCoordinate");
15
15
 
16
+ var _InternalContext = _interopRequireDefault(require("./InternalContext"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
16
20
  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); }
17
21
 
18
22
  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; }
19
23
 
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
24
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
25
 
24
26
  const INDICATOR_WIDTH = 10;
@@ -42,41 +44,66 @@ const useStyles = function () {
42
44
  };
43
45
  };
44
46
 
45
- const ANIMATION_CONFIG = {
46
- duration: 300,
47
- easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.exp)
47
+ const startAnimation = (value, toValue) => {
48
+ _reactNative.Animated.timing(value, {
49
+ toValue: toValue,
50
+ duration: 300,
51
+ easing: _reactNative.Easing.bezier(0.25, 1, 0.5, 1),
52
+ useNativeDriver: true
53
+ }).start();
48
54
  };
49
55
 
50
56
  function TabIndicator(props) {
51
57
  const {
52
58
  coordinates,
53
59
  disabled,
60
+ initialIndex,
54
61
  scrollable,
55
- sharedIndex,
56
62
  style,
57
63
  ...otherProps
58
64
  } = props;
59
65
  const styles = useStyles();
60
- const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
61
- const index = sharedIndex.value;
66
+ const computeAnimationValues = (0, _react.useCallback)(currentIndex => {
62
67
  const {
63
68
  x1,
64
69
  x2
65
- } = coordinates[index] ?? _TabCoordinate.defaultCoordinate;
70
+ } = coordinates[currentIndex] ?? _TabCoordinate.defaultCoordinate;
66
71
  const tabWidth = x2 - x1;
67
- const translateX = x1 + (tabWidth - INDICATOR_WIDTH) / 2;
72
+ const nextTranslateX = x1 + (tabWidth - INDICATOR_WIDTH) / 2;
68
73
  const inset = scrollable ? SCROLLABLE_TABS_INSET : 0;
69
- const scaleX = (tabWidth - inset) / INDICATOR_WIDTH;
74
+ const nextScaleX = (tabWidth - inset) / INDICATOR_WIDTH;
70
75
  return {
76
+ tx: nextTranslateX,
77
+ sx: nextScaleX
78
+ };
79
+ }, [coordinates, scrollable]);
80
+ const {
81
+ tx: initialTx,
82
+ sx: initialSx
83
+ } = computeAnimationValues(initialIndex);
84
+ const translateX = (0, _react.useRef)(new _reactNative.Animated.Value(initialTx)).current;
85
+ const scaleX = (0, _react.useRef)(new _reactNative.Animated.Value(initialSx)).current;
86
+ const {
87
+ indexStore
88
+ } = (0, _react.useContext)(_InternalContext.default);
89
+ (0, _react.useEffect)(() => {
90
+ return indexStore.subscribe(currentIndex => {
91
+ const {
92
+ tx,
93
+ sx
94
+ } = computeAnimationValues(currentIndex);
95
+ startAnimation(translateX, tx);
96
+ startAnimation(scaleX, sx);
97
+ });
98
+ }, [indexStore, computeAnimationValues]);
99
+ return /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, _extends({
100
+ style: [styles.root, disabled ? styles.disabled : undefined, {
71
101
  transform: [{
72
- translateX: (0, _reactNativeReanimated.withTiming)(translateX, ANIMATION_CONFIG)
102
+ translateX
73
103
  }, {
74
- scaleX: (0, _reactNativeReanimated.withTiming)(scaleX, ANIMATION_CONFIG)
104
+ scaleX
75
105
  }]
76
- };
77
- }, [coordinates, scrollable]);
78
- return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, _extends({
79
- style: [styles.root, disabled ? styles.disabled : undefined, animatedStyle, style]
106
+ }, style]
80
107
  }, otherProps));
81
108
  }
82
109
 
@@ -1 +1 @@
1
- {"version":3,"names":["INDICATOR_WIDTH","INDICATOR_HEIGHT","SCROLLABLE_TABS_INSET","useStyles","theme","useTheme","root","backgroundColor","palette","secondary","main","left","bottom","width","height","position","disabled","ANIMATION_CONFIG","duration","easing","Easing","out","exp","TabIndicator","props","coordinates","scrollable","sharedIndex","style","otherProps","styles","animatedStyle","useAnimatedStyle","index","value","x1","x2","defaultCoordinate","tabWidth","translateX","inset","scaleX","transform","withTiming","undefined"],"sources":["TabIndicator.tsx"],"sourcesContent":["import React from 'react';\nimport type { WithTimingConfig } from 'react-native-reanimated';\nimport Animated, { Easing, useAnimatedStyle, withTiming } from 'react-native-reanimated';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { useTheme } from '../styles';\nimport type TabIndicatorProps from './TabIndicatorProps';\nimport { defaultCoordinate } from './TabCoordinate';\n\ntype TabIndicatorStyles = NamedStylesStringUnion<'root' | 'disabled'>;\n\nconst INDICATOR_WIDTH = 10;\nconst INDICATOR_HEIGHT = 4;\n\nconst SCROLLABLE_TABS_INSET = 12 * 2;\n\nconst useStyles: UseStyles<TabIndicatorStyles> = function (): TabIndicatorStyles {\n const theme = useTheme();\n\n return {\n root: {\n backgroundColor: theme.palette.secondary.main,\n left: 0,\n bottom: 0,\n width: INDICATOR_WIDTH,\n height: INDICATOR_HEIGHT,\n position: 'absolute',\n },\n disabled: {\n height: 0,\n },\n };\n};\n\nconst ANIMATION_CONFIG: Readonly<WithTimingConfig> = {\n duration: 300,\n easing: Easing.out(Easing.exp),\n};\n\nexport default function TabIndicator(props: TabIndicatorProps) {\n const {\n coordinates,\n disabled,\n scrollable,\n sharedIndex,\n style,\n ...otherProps\n } = props;\n\n const styles = useStyles();\n\n const animatedStyle = useAnimatedStyle(() => {\n const index = sharedIndex.value;\n\n const { x1, x2 } = coordinates[index] ?? defaultCoordinate;\n\n const tabWidth = x2 - x1;\n\n const translateX = x1 + (tabWidth - INDICATOR_WIDTH) / 2;\n\n const inset = scrollable ? SCROLLABLE_TABS_INSET : 0;\n const scaleX = (tabWidth - inset) / INDICATOR_WIDTH;\n\n return {\n transform: [\n { translateX: withTiming(translateX, ANIMATION_CONFIG) },\n { scaleX: withTiming(scaleX, ANIMATION_CONFIG) },\n ],\n };\n }, [coordinates, scrollable]);\n\n return (\n <Animated.View\n style={[\n styles.root,\n disabled ? styles.disabled : undefined,\n animatedStyle,\n style,\n ]}\n {...otherProps}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AAEA;;;;;;;;;;AAIA,MAAMA,eAAe,GAAG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BxC,eAApC;IAEA,OAAO;MACH0C,SAAS,EAAE,CACP;QAAEH,UAAU,EAAE,IAAAI,iCAAA,EAAWJ,UAAX,EAAuBtB,gBAAvB;MAAd,CADO,EAEP;QAAEwB,MAAM,EAAE,IAAAE,iCAAA,EAAWF,MAAX,EAAmBxB,gBAAnB;MAAV,CAFO;IADR,CAAP;EAMH,CAlBqB,EAkBnB,CAACQ,WAAD,EAAcC,UAAd,CAlBmB,CAAtB;EAoBA,oBACI,6BAAC,8BAAD,CAAU,IAAV;IACI,KAAK,EAAE,CACHI,MAAM,CAACxB,IADJ,EAEHU,QAAQ,GAAGc,MAAM,CAACd,QAAV,GAAqB4B,SAF1B,EAGHb,aAHG,EAIHH,KAJG;EADX,GAOQC,UAPR,EADJ;AAWH;;AAAA"}
1
+ {"version":3,"names":["INDICATOR_WIDTH","INDICATOR_HEIGHT","SCROLLABLE_TABS_INSET","useStyles","theme","useTheme","root","backgroundColor","palette","secondary","main","left","bottom","width","height","position","disabled","startAnimation","value","toValue","Animated","timing","duration","easing","Easing","bezier","useNativeDriver","start","TabIndicator","props","coordinates","initialIndex","scrollable","style","otherProps","styles","computeAnimationValues","useCallback","currentIndex","x1","x2","defaultCoordinate","tabWidth","nextTranslateX","inset","nextScaleX","tx","sx","initialTx","initialSx","translateX","useRef","Value","current","scaleX","indexStore","useContext","InternalContext","useEffect","subscribe","undefined","transform"],"sources":["TabIndicator.tsx"],"sourcesContent":["import React, { useCallback, useContext, useEffect, useRef } from 'react';\nimport { Animated, Easing } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { useTheme } from '../styles';\nimport type TabIndicatorProps from './TabIndicatorProps';\nimport { defaultCoordinate } from './TabCoordinate';\nimport InternalContext from './InternalContext';\n\ntype TabIndicatorStyles = NamedStylesStringUnion<'root' | 'disabled'>;\n\nconst INDICATOR_WIDTH = 10;\nconst INDICATOR_HEIGHT = 4;\n\nconst SCROLLABLE_TABS_INSET = 12 * 2;\n\nconst useStyles: UseStyles<TabIndicatorStyles> = function (): TabIndicatorStyles {\n const theme = useTheme();\n\n return {\n root: {\n backgroundColor: theme.palette.secondary.main,\n left: 0,\n bottom: 0,\n width: INDICATOR_WIDTH,\n height: INDICATOR_HEIGHT,\n position: 'absolute',\n },\n disabled: {\n height: 0,\n },\n };\n};\n\nconst startAnimation = (value: Animated.Value, toValue: number) => {\n Animated.timing(value, {\n toValue: toValue,\n duration: 300,\n easing: Easing.bezier(0.25, 1, 0.5, 1),\n useNativeDriver: true,\n }).start();\n};\n\nexport default function TabIndicator(props: TabIndicatorProps) {\n const {\n coordinates,\n disabled,\n initialIndex,\n scrollable,\n style,\n ...otherProps\n } = props;\n\n const styles = useStyles();\n\n const computeAnimationValues = useCallback((currentIndex: number) => {\n const { x1, x2 } = coordinates[currentIndex] ?? defaultCoordinate;\n\n const tabWidth = x2 - x1;\n\n const nextTranslateX = x1 + (tabWidth - INDICATOR_WIDTH) / 2;\n\n const inset = scrollable ? SCROLLABLE_TABS_INSET : 0;\n const nextScaleX = (tabWidth - inset) / INDICATOR_WIDTH;\n\n return { tx: nextTranslateX, sx: nextScaleX };\n }, [coordinates, scrollable]);\n\n const {\n tx: initialTx,\n sx: initialSx,\n } = computeAnimationValues(initialIndex);\n\n const translateX = useRef(new Animated.Value(initialTx)).current;\n const scaleX = useRef(new Animated.Value(initialSx)).current;\n\n const { indexStore } = useContext(InternalContext);\n\n useEffect(() => {\n return indexStore.subscribe(currentIndex => {\n const { tx, sx } = computeAnimationValues(currentIndex);\n\n startAnimation(translateX, tx);\n startAnimation(scaleX, sx);\n });\n }, [indexStore, computeAnimationValues]);\n\n return (\n <Animated.View\n style={[\n styles.root,\n disabled ? styles.disabled : undefined,\n { transform: [{ translateX }, { scaleX }] },\n style,\n ]}\n {...otherProps}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AAEA;;AACA;;;;;;;;;;AAIA,MAAMA,eAAe,GAAG,EAAxB;AACA,MAAMC,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QC,UAPR,EADJ;AAWH;;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["TabIndicatorProps.ts"],"sourcesContent":["import type { ViewProps } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport type { OverridableComponentProps } from '../types';\nimport type TabCoordinate from './TabCoordinate';\n\nexport default interface TabIndicatorProps extends OverridableComponentProps<ViewProps, {\n /**\n * Tab item coordinates.\n */\n coordinates: TabCoordinate[];\n\n /**\n * If `true`, the indicator is disabled.\n */\n disabled: boolean;\n\n /**\n * If `true`, the tab will be able to scroll.\n */\n scrollable: boolean;\n\n /**\n * Shared index value for using animated interpolation.\n */\n sharedIndex: SharedValue<number>;\n}> {}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["TabIndicatorProps.ts"],"sourcesContent":["import type { ViewProps } from 'react-native';\nimport type { OverridableComponentProps } from '../types';\nimport type TabCoordinate from './TabCoordinate';\n\nexport default interface TabIndicatorProps extends OverridableComponentProps<ViewProps, {\n /**\n * Tab item coordinates.\n */\n coordinates: TabCoordinate[];\n\n /**\n * If `true`, the indicator is disabled.\n */\n disabled: boolean;\n\n /**\n * Initial index.\n */\n initialIndex: number;\n\n /**\n * If `true`, the tab will be able to scroll.\n */\n scrollable: boolean;\n}> {}\n"],"mappings":""}
@@ -9,17 +9,21 @@ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _reactNative = require("react-native");
11
11
 
12
- var _reactNativeReanimated = require("react-native-reanimated");
13
-
14
12
  var _styles = require("../styles");
15
13
 
14
+ var _hooks = require("../hooks");
15
+
16
16
  var _TabIndicator = _interopRequireDefault(require("./TabIndicator"));
17
17
 
18
+ var _ScrollableTabsView = _interopRequireDefault(require("./ScrollableTabsView"));
19
+
18
20
  var _IndexAwareTab = _interopRequireDefault(require("./IndexAwareTab"));
19
21
 
20
22
  var _useTabCoordinates = _interopRequireDefault(require("./useTabCoordinates"));
21
23
 
22
- var _useScrollViewReaction = _interopRequireDefault(require("./useScrollViewReaction"));
24
+ var _useIndexStore = _interopRequireDefault(require("./useIndexStore"));
25
+
26
+ var _InternalContext = _interopRequireDefault(require("./InternalContext"));
23
27
 
24
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
29
 
@@ -56,17 +60,16 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(function Tabs(props, ref) {
56
60
  variant = 'primary',
57
61
  UNSTABLE_sharedIndex
58
62
  } = props;
59
- const fallbackSharedIndex = (0, _reactNativeReanimated.useSharedValue)(initialIndex);
63
+ const fallbackSharedIndex = (0, _hooks.useSyncAnimatedValue)({
64
+ initialValue: initialIndex
65
+ });
60
66
  const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;
61
67
 
62
- const getCurrentIndex = () => sharedIndex.value;
63
-
64
68
  const setTab = newIndex => {
65
- sharedIndex.value = newIndex;
69
+ sharedIndex.animatedValue.setValue(newIndex);
66
70
  };
67
71
 
68
72
  (0, _react.useImperativeHandle)(ref, () => ({
69
- getCurrentIndex,
70
73
  setTab
71
74
  }), [sharedIndex]);
72
75
  const styles = useStyles();
@@ -74,10 +77,7 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(function Tabs(props, ref) {
74
77
  coordinates,
75
78
  updateCoordinate
76
79
  } = (0, _useTabCoordinates.default)(children);
77
- const {
78
- scrollViewRef,
79
- onLayout
80
- } = (0, _useScrollViewReaction.default)(sharedIndex, coordinates);
80
+ const indexStore = (0, _useIndexStore.default)(sharedIndex);
81
81
  const isReadyToRenderIndicator = coordinates.length > 0;
82
82
 
83
83
  const tabElements = _react.default.Children.map(children, (child, index) => {
@@ -115,33 +115,35 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(function Tabs(props, ref) {
115
115
  });
116
116
  return /*#__PURE__*/_react.default.createElement(_IndexAwareTab.default, {
117
117
  children: tabElement,
118
- index: index,
119
- sharedIndex: sharedIndex
118
+ index: index
120
119
  });
121
120
  });
122
121
 
123
122
  const tabIndicator = isReadyToRenderIndicator ? /*#__PURE__*/_react.default.createElement(_TabIndicator.default, {
124
123
  coordinates: coordinates,
125
124
  disabled: disableIndicator,
126
- scrollable: scrollable,
127
- sharedIndex: sharedIndex
125
+ initialIndex: sharedIndex.initialValue,
126
+ scrollable: scrollable
128
127
  }) : null;
129
- return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
130
- onLayout: onLayout,
128
+ return /*#__PURE__*/_react.default.createElement(_InternalContext.default.Provider, {
129
+ value: {
130
+ indexStore
131
+ }
132
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
131
133
  style: (0, _styles.css)([styles.root, scrollable ? undefined : styles.fixedRoot, style])
132
- }, scrollable ? /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
134
+ }, scrollable ? /*#__PURE__*/_react.default.createElement(_ScrollableTabsView.default, {
133
135
  automaticallyAdjustContentInsets: false,
134
136
  bounces: false,
135
137
  contentContainerStyle: styles.scrollableContainer,
138
+ coordinates: coordinates,
136
139
  directionalLockEnabled: true,
137
140
  horizontal: true,
138
- ref: scrollViewRef,
139
141
  scrollsToTop: false,
140
142
  showsHorizontalScrollIndicator: false,
141
143
  showsVerticalScrollIndicator: false,
142
144
  keyboardDismissMode: keyboardDismissMode,
143
145
  keyboardShouldPersistTaps: keyboardShouldPersistTaps
144
- }, tabElements, tabIndicator) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, tabElements, tabIndicator));
146
+ }, tabElements, tabIndicator) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, tabElements, tabIndicator)));
145
147
  });
146
148
  var _default = Tabs;
147
149
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["useStyles","theme","useTheme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","forwardRef","props","ref","children","initialIndex","disableIndicator","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","fallbackSharedIndex","useSharedValue","sharedIndex","getCurrentIndex","value","setTab","newIndex","useImperativeHandle","styles","coordinates","updateCoordinate","useTabCoordinates","scrollViewRef","onLayout","useScrollViewReaction","isReadyToRenderIndicator","length","tabElements","React","Children","map","child","index","event","x","width","nativeEvent","layout","onMouseDown","e","preventDefault","onPress","tabElement","cloneElement","enableIndicator","undefined","tabIndicator","css"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useImperativeHandle } from 'react';\nimport type { GestureResponderEvent, LayoutChangeEvent } from 'react-native';\nimport { ScrollView, View } from 'react-native';\nimport { useSharedValue } from 'react-native-reanimated';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport type TabsProps from './TabsProps';\nimport type { TabsInstance } from './TabsProps';\nimport TabIndicator from './TabIndicator';\nimport IndexAwareTab from './IndexAwareTab';\nimport useTabCoordinates from './useTabCoordinates';\nimport useScrollViewReaction from './useScrollViewReaction';\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 initialIndex = 0,\n disableIndicator = false,\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSharedValue<number>(initialIndex);\n\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n\n const getCurrentIndex = (): number => sharedIndex.value;\n\n const setTab = (newIndex: number) => {\n sharedIndex.value = newIndex;\n };\n\n useImperativeHandle(\n ref,\n () => ({\n getCurrentIndex,\n setTab,\n }),\n [sharedIndex],\n );\n\n const styles = useStyles();\n\n const { coordinates, updateCoordinate } = useTabCoordinates(children);\n\n const { scrollViewRef, onLayout } = useScrollViewReaction(sharedIndex, coordinates);\n\n const isReadyToRenderIndicator = coordinates.length > 0;\n\n const tabElements = React.Children.map(children, (child, index) => {\n const onLayout = (event: LayoutChangeEvent) => {\n const { x, width } = event.nativeEvent.layout;\n\n updateCoordinate(index, x, width);\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 onChange?.(index);\n // @ts-ignore\n child.props.onPress?.();\n };\n\n // @ts-ignore\n const tabElement = cloneElement(child, {\n enableIndicator: !disableIndicator && !isReadyToRenderIndicator,\n onLayout,\n onPress,\n onMouseDown,\n variant,\n style: scrollable ? undefined : styles.fixedTab,\n });\n\n return (\n <IndexAwareTab\n children={tabElement}\n index={index}\n sharedIndex={sharedIndex}\n />\n );\n });\n\n const tabIndicator = isReadyToRenderIndicator ? (\n <TabIndicator\n coordinates={coordinates}\n disabled={disableIndicator}\n scrollable={scrollable}\n sharedIndex={sharedIndex}\n />\n ) : null;\n\n return (\n <View\n onLayout={onLayout}\n style={css([\n styles.root,\n scrollable ? undefined : styles.fixedRoot,\n style,\n ])}\n >\n {scrollable ? (\n <ScrollView\n automaticallyAdjustContentInsets={false}\n bounces={false}\n contentContainerStyle={styles.scrollableContainer}\n directionalLockEnabled={true}\n horizontal={true}\n ref={scrollViewRef}\n scrollsToTop={false}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={false}\n keyboardDismissMode={keyboardDismissMode}\n keyboardShouldPersistTaps={keyboardShouldPersistTaps}\n >\n {tabElements}\n {tabIndicator}\n </ScrollView>\n ) : (\n <React.Fragment>\n {tabElements}\n {tabIndicator}\n </React.Fragment>\n )}\n </View>\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EAOH,CAtCmB,CAApB;;EAwCA,MAAMkC,YAAY,GAAGrB,wBAAwB,gBACzC,6BAAC,qBAAD;IACI,WAAW,EAAEN,WADjB;IAEI,QAAQ,EAAEjB,gBAFd;IAGI,UAAU,EAAEI,UAHhB;IAII,WAAW,EAAEM;EAJjB,EADyC,GAOzC,IAPJ;EASA,oBACI,6BAAC,iBAAD;IACI,QAAQ,EAAEW,QADd;IAEI,KAAK,EAAE,IAAAwB,WAAA,EAAI,CACP7B,MAAM,CAAC9B,IADA,EAEPkB,UAAU,GAAGuC,SAAH,GAAe3B,MAAM,CAAC7B,SAFzB,EAGPkB,KAHO,CAAJ;EAFX,GAQKD,UAAU,gBACP,6BAAC,uBAAD;IACI,gCAAgC,EAAE,KADtC;IAEI,OAAO,EAAE,KAFb;IAGI,qBAAqB,EAAEY,MAAM,CAACzB,mBAHlC;IAII,sBAAsB,EAAE,IAJ5B;IAKI,UAAU,EAAE,IALhB;IAMI,GAAG,EAAE6B,aANT;IAOI,YAAY,EAAE,KAPlB;IAQI,8BAA8B,EAAE,KARpC;IASI,4BAA4B,EAAE,KATlC;IAUI,mBAAmB,EAAEnB,mBAVzB;IAWI,yBAAyB,EAAEC;EAX/B,GAaKuB,WAbL,EAcKmB,YAdL,CADO,gBAkBP,6BAAC,cAAD,CAAO,QAAP,QACKnB,WADL,EAEKmB,YAFL,CA1BR,CADJ;AAkCH,CA5HY,CAAb;eA8HelD,I"}
1
+ {"version":3,"names":["useStyles","theme","useTheme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","forwardRef","props","ref","children","initialIndex","disableIndicator","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","fallbackSharedIndex","useSyncAnimatedValue","initialValue","sharedIndex","setTab","newIndex","animatedValue","setValue","useImperativeHandle","styles","coordinates","updateCoordinate","useTabCoordinates","indexStore","useIndexStore","isReadyToRenderIndicator","length","tabElements","React","Children","map","child","index","onLayout","event","x","width","nativeEvent","layout","onMouseDown","e","preventDefault","onPress","tabElement","cloneElement","enableIndicator","undefined","tabIndicator","css"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useImperativeHandle } 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';\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 initialIndex = 0,\n disableIndicator = false,\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });\n\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n\n const setTab = (newIndex: number) => {\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 { coordinates, updateCoordinate } = useTabCoordinates(children);\n\n const indexStore = useIndexStore(sharedIndex);\n\n const isReadyToRenderIndicator = coordinates.length > 0;\n\n const tabElements = React.Children.map(children, (child, index) => {\n const onLayout = (event: LayoutChangeEvent) => {\n const { x, width } = event.nativeEvent.layout;\n\n updateCoordinate(index, x, width);\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 onChange?.(index);\n // @ts-ignore\n child.props.onPress?.();\n };\n\n // @ts-ignore\n const tabElement = cloneElement(child, {\n enableIndicator: !disableIndicator && !isReadyToRenderIndicator,\n onLayout,\n onPress,\n onMouseDown,\n variant,\n style: scrollable ? undefined : styles.fixedTab,\n });\n\n return (\n <IndexAwareTab\n children={tabElement}\n index={index}\n />\n );\n });\n\n const tabIndicator = isReadyToRenderIndicator ? (\n <TabIndicator\n coordinates={coordinates}\n disabled={disableIndicator}\n initialIndex={sharedIndex.initialValue}\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 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;;;;;;;;AAUA,MAAMA,S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IAPJ;EASA,oBACI,6BAAC,wBAAD,CAAiB,QAAjB;IAA0B,KAAK,EAAE;MAAEiB;IAAF;EAAjC,gBACI,6BAAC,iBAAD;IACI,KAAK,EAAE,IAAAyB,WAAA,EAAI,CACP7B,MAAM,CAAC/B,IADA,EAEPkB,UAAU,GAAGwC,SAAH,GAAe3B,MAAM,CAAC9B,SAFzB,EAGPkB,KAHO,CAAJ;EADX,GAOKD,UAAU,gBACP,6BAAC,2BAAD;IACI,gCAAgC,EAAE,KADtC;IAEI,OAAO,EAAE,KAFb;IAGI,qBAAqB,EAAEa,MAAM,CAAC1B,mBAHlC;IAII,WAAW,EAAE2B,WAJjB;IAKI,sBAAsB,EAAE,IAL5B;IAMI,UAAU,EAAE,IANhB;IAOI,YAAY,EAAE,KAPlB;IAQI,8BAA8B,EAAE,KARpC;IASI,4BAA4B,EAAE,KATlC;IAUI,mBAAmB,EAAEjB,mBAVzB;IAWI,yBAAyB,EAAEC;EAX/B,GAaKuB,WAbL,EAcKoB,YAdL,CADO,gBAkBP,6BAAC,cAAD,CAAO,QAAP,QACKpB,WADL,EAEKoB,YAFL,CAzBR,CADJ,CADJ;AAmCH,CAzHY,CAAb;eA2HenD,I"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["TabsProps.ts"],"sourcesContent":["import type { ReactNode, Ref } from 'react';\nimport type { ViewProps } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport type { TabVariant } from '../Tab';\nimport type { OverridableComponentProps } from '../types';\n\nexport type KeyboardDismissMode =\n 'none'\n | 'on-drag'\n | 'interactive'; // ios only\n\nexport type KeyboardShouldPersistTaps =\n 'never'\n | boolean\n | 'always'\n | 'handled'; // app only\n\nexport interface TabsInstance {\n /**\n * Get current tab index.\n */\n getCurrentIndex: () => number;\n\n /**\n * Function to scroll to a specific tab. Invalid index is ignored.\n * @param index\n */\n setTab: (index: number) => void;\n}\n\nexport default interface TabsProps extends OverridableComponentProps<ViewProps, {\n ref?: Ref<TabsInstance>;\n\n /**\n * Collection of Tab components.\n */\n children: ReactNode;\n\n /**\n * If `true`, the indicator is disabled.\n * @default false\n */\n disableIndicator?: boolean;\n\n /**\n * Index of initial tab that should be selected.\n * @default 0\n */\n initialIndex?: number;\n\n /**\n * keyboard dismissing condition of dragging.\n * @default 'none'\n */\n keyboardDismissMode?: KeyboardDismissMode,\n\n /**\n * keyboard persisting condition of tapping.\n * @default 'never'\n */\n keyboardShouldPersistTaps?: KeyboardShouldPersistTaps,\n\n /**\n * Callback fired when a tab is selected.\n */\n onChange?: (newIndex: number) => void;\n\n /**\n * If `true`, the component will be able to scroll.\n * @default false\n */\n scrollable?: boolean;\n\n /**\n * Unstable API.\n */\n UNSTABLE_sharedIndex?: SharedValue<number>;\n\n /**\n * The variant to use.\n * @default 'primary'\n */\n variant?: TabVariant;\n}> {}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["TabsProps.ts"],"sourcesContent":["import type { ReactNode, Ref } from 'react';\nimport type { Animated, ViewProps } from 'react-native';\nimport type { TabVariant } from '../Tab';\nimport type { OverridableComponentProps, SyncAnimatedValue } from '../types';\nimport type { KeyboardDismissMode, KeyboardShouldPersistTaps, TabsInstance } from './types';\n\nexport default interface TabsProps extends OverridableComponentProps<ViewProps, {\n ref?: Ref<TabsInstance>;\n\n /**\n * Collection of Tab components.\n */\n children: ReactNode;\n\n /**\n * If `true`, the indicator is disabled.\n * @default false\n */\n disableIndicator?: boolean;\n\n /**\n * Index of initial tab that should be selected.\n * @default 0\n */\n initialIndex?: number;\n\n /**\n * keyboard dismissing condition of dragging.\n * @default 'none'\n */\n keyboardDismissMode?: KeyboardDismissMode,\n\n /**\n * keyboard persisting condition of tapping.\n * @default 'never'\n */\n keyboardShouldPersistTaps?: KeyboardShouldPersistTaps,\n\n /**\n * Callback fired when a tab is selected.\n */\n onChange?: (newIndex: number) => void;\n\n /**\n * If `true`, the component will be able to scroll.\n * @default false\n */\n scrollable?: boolean;\n\n /**\n * Unstable API.\n */\n UNSTABLE_sharedIndex?: SyncAnimatedValue;\n\n /**\n * The variant to use.\n * @default 'primary'\n */\n variant?: TabVariant;\n}> {}\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Tabs';\nexport type { default as TabsProps, TabsInstance } from './TabsProps';\n"],"mappings":";;;;;;;;;;;;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Tabs';\nexport type { default as TabsProps } from './TabsProps';\nexport type { TabsInstance } from './types';\n"],"mappings":";;;;;;;;;;;;AAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export type KeyboardDismissMode =\n 'none'\n | 'on-drag'\n | 'interactive'; // ios only\n\nexport type KeyboardShouldPersistTaps =\n 'never'\n | boolean\n | 'always'\n | 'handled'; // app only\n\nexport interface TabsInstance {\n /**\n * Function to scroll to a specific tab. Invalid index is ignored.\n * @param index\n */\n setTab: (index: number) => void;\n}\n"],"mappings":""}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useIndexStore;
7
+
8
+ var _react = require("react");
9
+
10
+ var _store = require("../store");
11
+
12
+ function useIndexStore(value) {
13
+ const {
14
+ animatedValue,
15
+ initialValue
16
+ } = value;
17
+ const store = (0, _react.useRef)(new _store.SimpleStore(initialValue)).current;
18
+ (0, _react.useEffect)(() => {
19
+ const id = animatedValue.addListener(newIndex => {
20
+ store.dispatch(newIndex.value);
21
+ });
22
+ return () => {
23
+ animatedValue.removeListener(id);
24
+ };
25
+ }, [animatedValue]);
26
+ (0, _react.useEffect)(() => {
27
+ return () => {
28
+ store.removeAllListeners();
29
+ };
30
+ }, [store]);
31
+ return store;
32
+ }
33
+
34
+ ;
35
+ //# sourceMappingURL=useIndexStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useIndexStore","value","animatedValue","initialValue","store","useRef","SimpleStore","current","useEffect","id","addListener","newIndex","dispatch","removeListener","removeAllListeners"],"sources":["useIndexStore.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { MonoStore } from '../store';\nimport { SimpleStore } from '../store';\nimport type { SyncAnimatedValue } from '../types';\n\nexport default function useIndexStore(value: SyncAnimatedValue): MonoStore<number> {\n const {\n animatedValue,\n initialValue,\n } = value;\n\n const store = useRef(new SimpleStore(initialValue)).current;\n\n useEffect(() => {\n const id = animatedValue.addListener((newIndex) => {\n store.dispatch(newIndex.value);\n });\n\n return () => {\n animatedValue.removeListener(id);\n };\n }, [animatedValue]);\n\n useEffect(() => {\n return () => {\n store.removeAllListeners();\n };\n }, [store]);\n\n return store;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAGe,SAASA,aAAT,CAAuBC,KAAvB,EAAoE;EAC/E,MAAM;IACFC,aADE;IAEFC;EAFE,IAGFF,KAHJ;EAKA,MAAMG,KAAK,GAAG,IAAAC,aAAA,EAAO,IAAIC,kBAAJ,CAAgBH,YAAhB,CAAP,EAAsCI,OAApD;EAEA,IAAAC,gBAAA,EAAU,MAAM;IACZ,MAAMC,EAAE,GAAGP,aAAa,CAACQ,WAAd,CAA2BC,QAAD,IAAc;MAC/CP,KAAK,CAACQ,QAAN,CAAeD,QAAQ,CAACV,KAAxB;IACH,CAFU,CAAX;IAIA,OAAO,MAAM;MACTC,aAAa,CAACW,cAAd,CAA6BJ,EAA7B;IACH,CAFD;EAGH,CARD,EAQG,CAACP,aAAD,CARH;EAUA,IAAAM,gBAAA,EAAU,MAAM;IACZ,OAAO,MAAM;MACTJ,KAAK,CAACU,kBAAN;IACH,CAFD;EAGH,CAJD,EAIG,CAACV,KAAD,CAJH;EAMA,OAAOA,KAAP;AACH;;AAAA"}
@@ -7,13 +7,16 @@ exports.default = useScrollViewReaction;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
- var _reactNative = require("react-native");
10
+ var _InternalContext = _interopRequireDefault(require("./InternalContext"));
11
11
 
12
- var _reactNativeReanimated = require("react-native-reanimated");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- function useScrollViewReaction(sharedIndex, coordinates) {
15
- const scrollViewRef = (0, _reactNativeReanimated.useAnimatedRef)();
14
+ function useScrollViewReaction(coordinates) {
15
+ const scrollViewRef = (0, _react.useRef)(null);
16
16
  const lastScrolledXRef = (0, _react.useRef)(NaN);
17
+ const {
18
+ indexStore
19
+ } = (0, _react.useContext)(_InternalContext.default);
17
20
 
18
21
  const scrollToX = x => {
19
22
  if (Number.isFinite(x)) {
@@ -24,37 +27,30 @@ function useScrollViewReaction(sharedIndex, coordinates) {
24
27
  y: 0,
25
28
  animated: true
26
29
  });
27
- didScrollToX(x);
30
+ lastScrolledXRef.current = x;
28
31
  }
29
32
  };
30
33
 
31
- const didScrollToX = x => {
32
- lastScrolledXRef.current = x;
33
- };
34
-
35
34
  const onLayout = (0, _react.useCallback)(() => {
36
35
  scrollToX(lastScrolledXRef.current);
37
36
  }, []);
38
- (0, _reactNativeReanimated.useAnimatedReaction)(() => {
39
- const prevIndex = sharedIndex.value - 1;
40
- const prevCoordinate = coordinates[prevIndex];
37
+ (0, _react.useEffect)(() => {
38
+ const computeNextScrollX = index => {
39
+ const prevIndex = index - 1;
40
+ const prevCoordinate = coordinates[prevIndex];
41
+
42
+ if (prevCoordinate) {
43
+ const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;
44
+ return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);
45
+ }
41
46
 
42
- if (prevCoordinate) {
43
- const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;
44
- return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);
45
- }
47
+ return 0;
48
+ };
46
49
 
47
- return 0;
48
- }, (x, prevX) => {
49
- if (x !== prevX) {
50
- if (_reactNative.Platform.OS === 'web') {
51
- (0, _reactNativeReanimated.runOnJS)(scrollToX)(x);
52
- } else {
53
- (0, _reactNativeReanimated.scrollTo)(scrollViewRef, x, 0, true);
54
- (0, _reactNativeReanimated.runOnJS)(didScrollToX)(x);
55
- }
56
- }
57
- }, [coordinates]);
50
+ return indexStore.subscribe(currentIndex => {
51
+ scrollToX(computeNextScrollX(currentIndex));
52
+ });
53
+ }, [indexStore, coordinates]);
58
54
  return {
59
55
  scrollViewRef,
60
56
  onLayout
@@ -1 +1 @@
1
- {"version":3,"names":["useScrollViewReaction","sharedIndex","coordinates","scrollViewRef","useAnimatedRef","lastScrolledXRef","useRef","NaN","scrollToX","x","Number","isFinite","current","scrollTo","y","animated","didScrollToX","onLayout","useCallback","useAnimatedReaction","prevIndex","value","prevCoordinate","prevTabWidth","x2","x1","Math","floor","prevX","Platform","OS","runOnJS"],"sources":["useScrollViewReaction.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useCallback, useRef } from 'react';\nimport type { ScrollView, ViewProps } from 'react-native';\nimport { Platform } from 'react-native';\nimport { runOnJS, scrollTo, SharedValue, useAnimatedReaction, useAnimatedRef } from 'react-native-reanimated';\nimport type TabCoordinate from './TabCoordinate';\n\nexport interface UseScrollViewReaction {\n scrollViewRef: MutableRefObject<ScrollView | null>;\n onLayout: ViewProps['onLayout'];\n}\n\nexport default function useScrollViewReaction(\n sharedIndex: SharedValue<number>,\n coordinates: TabCoordinate[],\n): UseScrollViewReaction {\n const scrollViewRef = useAnimatedRef<ScrollView>();\n\n const lastScrolledXRef = useRef<number>(NaN);\n\n const scrollToX = (x: number) => {\n if (Number.isFinite(x)) {\n scrollViewRef.current?.scrollTo({ x, y: 0, animated: true });\n\n didScrollToX(x);\n }\n };\n\n const didScrollToX = (x: number) => {\n lastScrolledXRef.current = x;\n };\n\n const onLayout = useCallback(() => {\n scrollToX(lastScrolledXRef.current);\n }, []);\n\n useAnimatedReaction(\n () => {\n const prevIndex = sharedIndex.value - 1;\n const prevCoordinate = coordinates[prevIndex];\n\n if (prevCoordinate) {\n const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;\n return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);\n }\n\n return 0;\n },\n (x, prevX) => {\n if (x !== prevX) {\n if (Platform.OS === 'web') {\n runOnJS(scrollToX)(x);\n } else {\n scrollTo(scrollViewRef, x, 0, true);\n runOnJS(didScrollToX)(x);\n }\n }\n },\n [coordinates],\n );\n\n return { scrollViewRef, onLayout };\n};\n"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AAQe,SAASA,qBAAT,CACXC,WADW,EAEXC,WAFW,EAGU;EACrB,MAAMC,aAAa,GAAG,IAAAC,qCAAA,GAAtB;EAEA,MAAMC,gBAAgB,GAAG,IAAAC,aAAA,EAAeC,GAAf,CAAzB;;EAEA,MAAMC,SAAS,GAAIC,CAAD,IAAe;IAC7B,IAAIC,MAAM,CAACC,QAAP,CAAgBF,CAAhB,CAAJ,EAAwB;MAAA;;MACpB,yBAAAN,aAAa,CAACS,OAAd,gFAAuBC,QAAvB,CAAgC;QAAEJ,CAAF;QAAKK,CAAC,EAAE,CAAR;QAAWC,QAAQ,EAAE;MAArB,CAAhC;MAEAC,YAAY,CAACP,CAAD,CAAZ;IACH;EACJ,CAND;;EAQA,MAAMO,YAAY,GAAIP,CAAD,IAAe;IAChCJ,gBAAgB,CAACO,OAAjB,GAA2BH,CAA3B;EACH,CAFD;;EAIA,MAAMQ,QAAQ,GAAG,IAAAC,kBAAA,EAAY,MAAM;IAC/BV,SAAS,CAACH,gBAAgB,CAACO,OAAlB,CAAT;EACH,CAFgB,EAEd,EAFc,CAAjB;EAIA,IAAAO,0CAAA,EACI,MAAM;IACF,MAAMC,SAAS,GAAGnB,WAAW,CAACoB,KAAZ,GAAoB,CAAtC;IACA,MAAMC,cAAc,GAAGpB,WAAW,CAACkB,SAAD,CAAlC;;IAEA,IAAIE,cAAJ,EAAoB;MAChB,MAAMC,YAAY,GAAGD,cAAc,CAACE,EAAf,GAAoBF,cAAc,CAACG,EAAxD;MACA,OAAOC,IAAI,CAACC,KAAL,CAAWL,cAAc,CAACG,EAAf,GAAoBF,YAAY,GAAG,CAA9C,CAAP;IACH;;IAED,OAAO,CAAP;EACH,CAXL,EAYI,CAACd,CAAD,EAAImB,KAAJ,KAAc;IACV,IAAInB,CAAC,KAAKmB,KAAV,EAAiB;MACb,IAAIC,qBAAA,CAASC,EAAT,KAAgB,KAApB,EAA2B;QACvB,IAAAC,8BAAA,EAAQvB,SAAR,EAAmBC,CAAnB;MACH,CAFD,MAEO;QACH,IAAAI,+BAAA,EAASV,aAAT,EAAwBM,CAAxB,EAA2B,CAA3B,EAA8B,IAA9B;QACA,IAAAsB,8BAAA,EAAQf,YAAR,EAAsBP,CAAtB;MACH;IACJ;EACJ,CArBL,EAsBI,CAACP,WAAD,CAtBJ;EAyBA,OAAO;IAAEC,aAAF;IAAiBc;EAAjB,CAAP;AACH;;AAAA"}
1
+ {"version":3,"names":["useScrollViewReaction","coordinates","scrollViewRef","useRef","lastScrolledXRef","NaN","indexStore","useContext","InternalContext","scrollToX","x","Number","isFinite","current","scrollTo","y","animated","onLayout","useCallback","useEffect","computeNextScrollX","index","prevIndex","prevCoordinate","prevTabWidth","x2","x1","Math","floor","subscribe","currentIndex"],"sources":["useScrollViewReaction.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useCallback, useContext, useEffect, useRef } from 'react';\nimport type { ScrollView, ViewProps } from 'react-native';\nimport type TabCoordinate from './TabCoordinate';\nimport InternalContext from './InternalContext';\n\nexport interface UseScrollViewReaction {\n scrollViewRef: MutableRefObject<ScrollView | null>;\n onLayout: ViewProps['onLayout'];\n}\n\nexport default function useScrollViewReaction(\n coordinates: TabCoordinate[],\n): UseScrollViewReaction {\n const scrollViewRef = useRef<ScrollView | null>(null);\n\n const lastScrolledXRef = useRef<number>(NaN);\n\n const { indexStore } = useContext(InternalContext);\n\n const scrollToX = (x: number) => {\n if (Number.isFinite(x)) {\n scrollViewRef.current?.scrollTo({ x, y: 0, animated: true });\n\n lastScrolledXRef.current = x;\n }\n };\n\n const onLayout = useCallback(() => {\n scrollToX(lastScrolledXRef.current);\n }, []);\n\n useEffect(() => {\n const computeNextScrollX = (index: number) => {\n const prevIndex = index - 1;\n const prevCoordinate = coordinates[prevIndex];\n\n if (prevCoordinate) {\n const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;\n return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);\n }\n\n return 0;\n };\n\n return indexStore.subscribe(currentIndex => {\n scrollToX(computeNextScrollX(currentIndex));\n });\n }, [indexStore, coordinates]);\n\n return { scrollViewRef, onLayout };\n};\n"],"mappings":";;;;;;;AACA;;AAGA;;;;AAOe,SAASA,qBAAT,CACXC,WADW,EAEU;EACrB,MAAMC,aAAa,GAAG,IAAAC,aAAA,EAA0B,IAA1B,CAAtB;EAEA,MAAMC,gBAAgB,GAAG,IAAAD,aAAA,EAAeE,GAAf,CAAzB;EAEA,MAAM;IAAEC;EAAF,IAAiB,IAAAC,iBAAA,EAAWC,wBAAX,CAAvB;;EAEA,MAAMC,SAAS,GAAIC,CAAD,IAAe;IAC7B,IAAIC,MAAM,CAACC,QAAP,CAAgBF,CAAhB,CAAJ,EAAwB;MAAA;;MACpB,yBAAAR,aAAa,CAACW,OAAd,gFAAuBC,QAAvB,CAAgC;QAAEJ,CAAF;QAAKK,CAAC,EAAE,CAAR;QAAWC,QAAQ,EAAE;MAArB,CAAhC;MAEAZ,gBAAgB,CAACS,OAAjB,GAA2BH,CAA3B;IACH;EACJ,CAND;;EAQA,MAAMO,QAAQ,GAAG,IAAAC,kBAAA,EAAY,MAAM;IAC/BT,SAAS,CAACL,gBAAgB,CAACS,OAAlB,CAAT;EACH,CAFgB,EAEd,EAFc,CAAjB;EAIA,IAAAM,gBAAA,EAAU,MAAM;IACZ,MAAMC,kBAAkB,GAAIC,KAAD,IAAmB;MAC1C,MAAMC,SAAS,GAAGD,KAAK,GAAG,CAA1B;MACA,MAAME,cAAc,GAAGtB,WAAW,CAACqB,SAAD,CAAlC;;MAEA,IAAIC,cAAJ,EAAoB;QAChB,MAAMC,YAAY,GAAGD,cAAc,CAACE,EAAf,GAAoBF,cAAc,CAACG,EAAxD;QACA,OAAOC,IAAI,CAACC,KAAL,CAAWL,cAAc,CAACG,EAAf,GAAoBF,YAAY,GAAG,CAA9C,CAAP;MACH;;MAED,OAAO,CAAP;IACH,CAVD;;IAYA,OAAOlB,UAAU,CAACuB,SAAX,CAAqBC,YAAY,IAAI;MACxCrB,SAAS,CAACW,kBAAkB,CAACU,YAAD,CAAnB,CAAT;IACH,CAFM,CAAP;EAGH,CAhBD,EAgBG,CAACxB,UAAD,EAAaL,WAAb,CAhBH;EAkBA,OAAO;IAAEC,aAAF;IAAiBe;EAAjB,CAAP;AACH;;AAAA"}
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "useFadeInAppBar", {
33
33
  return _useFadeInAppBar.default;
34
34
  }
35
35
  });
36
+ Object.defineProperty(exports, "useSyncAnimatedValue", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _useSyncAnimatedValue.default;
40
+ }
41
+ });
36
42
  Object.defineProperty(exports, "useThrottle", {
37
43
  enumerable: true,
38
44
  get: function () {
@@ -56,6 +62,8 @@ var _useElevationStyle = _interopRequireDefault(require("./useElevationStyle"));
56
62
 
57
63
  var _useFadeInAppBar = _interopRequireDefault(require("./useFadeInAppBar"));
58
64
 
65
+ var _useSyncAnimatedValue = _interopRequireDefault(require("./useSyncAnimatedValue"));
66
+
59
67
  var _useThrottle = _interopRequireDefault(require("./useThrottle"));
60
68
 
61
69
  var _useValidWindowDimensions = _interopRequireDefault(require("./useValidWindowDimensions"));
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as useBreakpointUp } from './useBreakpointUp';\nexport { default as useCollapsibleAppBar } from './useCollapsibleAppBar';\nexport { default as useContentContainerStyle } from './useContentContainerStyle';\nexport { default as useElevationStyle } from './useElevationStyle';\nexport { default as useFadeInAppBar } from './useFadeInAppBar';\nexport { default as useThrottle } from './useThrottle';\nexport { default as useValidWindowDimensions } from './useValidWindowDimensions';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as useBreakpointUp } from './useBreakpointUp';\nexport { default as useCollapsibleAppBar } from './useCollapsibleAppBar';\nexport { default as useContentContainerStyle } from './useContentContainerStyle';\nexport { default as useElevationStyle } from './useElevationStyle';\nexport { default as useFadeInAppBar } from './useFadeInAppBar';\nexport { default as useSyncAnimatedValue } from './useSyncAnimatedValue';\nexport { default as useThrottle } from './useThrottle';\nexport { default as useValidWindowDimensions } from './useValidWindowDimensions';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA"}