@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.
- package/build/commonjs/Tabs/IndexAwareTab.js +13 -7
- package/build/commonjs/Tabs/IndexAwareTab.js.map +1 -1
- package/build/commonjs/Tabs/InternalContext.js +17 -0
- package/build/commonjs/Tabs/InternalContext.js.map +1 -0
- package/build/commonjs/Tabs/ScrollableTabsView.js +34 -0
- package/build/commonjs/Tabs/ScrollableTabsView.js.map +1 -0
- package/build/commonjs/Tabs/TabIndicator.js +46 -19
- package/build/commonjs/Tabs/TabIndicator.js.map +1 -1
- package/build/commonjs/Tabs/TabIndicatorProps.js.map +1 -1
- package/build/commonjs/Tabs/Tabs.js +23 -21
- package/build/commonjs/Tabs/Tabs.js.map +1 -1
- package/build/commonjs/Tabs/TabsProps.js.map +1 -1
- package/build/commonjs/Tabs/index.js.map +1 -1
- package/build/commonjs/Tabs/types.js +2 -0
- package/build/commonjs/Tabs/types.js.map +1 -0
- package/build/commonjs/Tabs/useIndexStore.js +35 -0
- package/build/commonjs/Tabs/useIndexStore.js.map +1 -0
- package/build/commonjs/Tabs/useScrollViewReaction.js +23 -27
- package/build/commonjs/Tabs/useScrollViewReaction.js.map +1 -1
- package/build/commonjs/hooks/index.js +8 -0
- package/build/commonjs/hooks/index.js.map +1 -1
- package/build/commonjs/hooks/useCollapsibleAppBar.js +1 -1
- package/build/commonjs/hooks/useCollapsibleAppBar.js.map +1 -1
- package/build/commonjs/hooks/useSyncAnimatedValue.js +37 -0
- package/build/commonjs/hooks/useSyncAnimatedValue.js.map +1 -0
- package/build/commonjs/index.js +14 -0
- package/build/commonjs/index.js.map +1 -1
- package/build/commonjs/store/MockStore.js +23 -0
- package/build/commonjs/store/MockStore.js.map +1 -0
- package/build/commonjs/store/SimpleStore.js +45 -0
- package/build/commonjs/store/SimpleStore.js.map +1 -0
- package/build/commonjs/store/index.js +24 -0
- package/build/commonjs/store/index.js.map +1 -0
- package/build/commonjs/store/types.js +2 -0
- package/build/commonjs/store/types.js.map +1 -0
- package/build/commonjs/types/index.js.map +1 -1
- package/build/module/Tabs/IndexAwareTab.js +12 -8
- package/build/module/Tabs/IndexAwareTab.js.map +1 -1
- package/build/module/Tabs/InternalContext.js +7 -0
- package/build/module/Tabs/InternalContext.js.map +1 -0
- package/build/module/Tabs/ScrollableTabsView.js +21 -0
- package/build/module/Tabs/ScrollableTabsView.js.map +1 -0
- package/build/module/Tabs/TabIndicator.js +44 -17
- package/build/module/Tabs/TabIndicator.js.map +1 -1
- package/build/module/Tabs/TabIndicatorProps.js.map +1 -1
- package/build/module/Tabs/Tabs.js +21 -21
- package/build/module/Tabs/Tabs.js.map +1 -1
- package/build/module/Tabs/TabsProps.js.map +1 -1
- package/build/module/Tabs/index.js.map +1 -1
- package/build/module/Tabs/types.js +2 -0
- package/build/module/Tabs/types.js.map +1 -0
- package/build/module/Tabs/useIndexStore.js +25 -0
- package/build/module/Tabs/useIndexStore.js.map +1 -0
- package/build/module/Tabs/useScrollViewReaction.js +23 -28
- package/build/module/Tabs/useScrollViewReaction.js.map +1 -1
- package/build/module/hooks/index.js +1 -0
- package/build/module/hooks/index.js.map +1 -1
- package/build/module/hooks/useCollapsibleAppBar.js +1 -1
- package/build/module/hooks/useCollapsibleAppBar.js.map +1 -1
- package/build/module/hooks/useSyncAnimatedValue.js +27 -0
- package/build/module/hooks/useSyncAnimatedValue.js.map +1 -0
- package/build/module/index.js +1 -0
- package/build/module/index.js.map +1 -1
- package/build/module/store/MockStore.js +14 -0
- package/build/module/store/MockStore.js.map +1 -0
- package/build/module/store/SimpleStore.js +36 -0
- package/build/module/store/SimpleStore.js.map +1 -0
- package/build/module/store/index.js +3 -0
- package/build/module/store/index.js.map +1 -0
- package/build/module/store/types.js +2 -0
- package/build/module/store/types.js.map +1 -0
- package/build/module/types/index.js.map +1 -1
- package/build/typescript/Tabs/IndexAwareTab.d.ts +0 -2
- package/build/typescript/Tabs/InternalContext.d.ts +7 -0
- package/build/typescript/Tabs/ScrollableTabsView.d.ts +6 -0
- package/build/typescript/Tabs/TabIndicatorProps.d.ts +4 -5
- package/build/typescript/Tabs/Tabs.d.ts +1 -1
- package/build/typescript/Tabs/TabsProps.d.ts +3 -16
- package/build/typescript/Tabs/index.d.ts +2 -1
- package/build/typescript/Tabs/types.d.ts +9 -0
- package/build/typescript/Tabs/useIndexStore.d.ts +3 -0
- package/build/typescript/Tabs/useScrollViewReaction.d.ts +1 -2
- package/build/typescript/hooks/index.d.ts +1 -0
- package/build/typescript/hooks/useSyncAnimatedValue.d.ts +6 -0
- package/build/typescript/index.d.ts +1 -0
- package/build/typescript/store/MockStore.d.ts +6 -0
- package/build/typescript/store/SimpleStore.d.ts +9 -0
- package/build/typescript/store/index.d.ts +3 -0
- package/build/typescript/store/types.d.ts +8 -0
- package/build/typescript/types/index.d.ts +6 -0
- package/package.json +4 -4
- package/src/Tabs/IndexAwareTab.tsx +10 -13
- package/src/Tabs/InternalContext.ts +13 -0
- package/src/Tabs/ScrollableTabsView.tsx +26 -0
- package/src/Tabs/TabIndicator.tsx +37 -21
- package/src/Tabs/TabIndicatorProps.ts +4 -5
- package/src/Tabs/Tabs.tsx +43 -44
- package/src/Tabs/TabsProps.ts +4 -28
- package/src/Tabs/index.ts +2 -1
- package/src/Tabs/types.ts +18 -0
- package/src/Tabs/useIndexStore.ts +31 -0
- package/src/Tabs/useScrollViewReaction.ts +15 -26
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useCollapsibleAppBar.ts +1 -1
- package/src/hooks/useSyncAnimatedValue.ts +37 -0
- package/src/index.ts +2 -0
- package/src/store/MockStore.ts +17 -0
- package/src/store/SimpleStore.ts +36 -0
- package/src/store/index.ts +3 -0
- package/src/store/types.ts +9 -0
- 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
|
|
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)(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
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","
|
|
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 =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
|
-
var
|
|
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
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
61
|
-
const index = sharedIndex.value;
|
|
66
|
+
const computeAnimationValues = (0, _react.useCallback)(currentIndex => {
|
|
62
67
|
const {
|
|
63
68
|
x1,
|
|
64
69
|
x2
|
|
65
|
-
} = coordinates[
|
|
70
|
+
} = coordinates[currentIndex] ?? _TabCoordinate.defaultCoordinate;
|
|
66
71
|
const tabWidth = x2 - x1;
|
|
67
|
-
const
|
|
72
|
+
const nextTranslateX = x1 + (tabWidth - INDICATOR_WIDTH) / 2;
|
|
68
73
|
const inset = scrollable ? SCROLLABLE_TABS_INSET : 0;
|
|
69
|
-
const
|
|
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
|
|
102
|
+
translateX
|
|
73
103
|
}, {
|
|
74
|
-
scaleX
|
|
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","
|
|
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,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,CAAC7B,IADJ,EAEHU,QAAQ,GAAGmB,MAAM,CAACnB,QAAV,GAAqB4C,SAF1B,EAGH;MAAEC,SAAS,EAAE,CAAC;QAAEX;MAAF,CAAD,EAAiB;QAAEI;MAAF,CAAjB;IAAb,CAHG,EAIHrB,KAJG;EADX,GAOQC,UAPR,EADJ;AAWH;;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["TabIndicatorProps.ts"],"sourcesContent":["import type { ViewProps } from 'react-native';\nimport type {
|
|
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
|
|
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,
|
|
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.
|
|
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
|
-
|
|
127
|
-
|
|
125
|
+
initialIndex: sharedIndex.initialValue,
|
|
126
|
+
scrollable: scrollable
|
|
128
127
|
}) : null;
|
|
129
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
130
|
-
|
|
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(
|
|
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","
|
|
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,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;EACvE,MAAM;IACFC,QADE;IAEFC,YAAY,GAAG,CAFb;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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 {
|
|
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
|
|
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 @@
|
|
|
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
|
|
10
|
+
var _InternalContext = _interopRequireDefault(require("./InternalContext"));
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
function useScrollViewReaction(
|
|
15
|
-
const scrollViewRef = (0,
|
|
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
|
-
|
|
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,
|
|
39
|
-
const
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);
|
|
45
|
-
}
|
|
47
|
+
return 0;
|
|
48
|
+
};
|
|
46
49
|
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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","
|
|
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":"
|
|
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"}
|