@fountain-ui/core 2.0.0-beta.13 → 2.0.0-beta.16
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/ButtonBase/ButtonBase.js +3 -2
- package/build/commonjs/ButtonBase/ButtonBase.js.map +1 -1
- package/build/commonjs/CircularProgress/CircularProgress.js +15 -11
- package/build/commonjs/CircularProgress/CircularProgress.js.map +1 -1
- package/build/commonjs/Tab/Tab.js +9 -5
- package/build/commonjs/Tab/Tab.js.map +1 -1
- package/build/commonjs/Tabs/IndexAwareTab.js +28 -0
- package/build/commonjs/Tabs/IndexAwareTab.js.map +1 -0
- package/build/commonjs/Tabs/TabIndicator.js +27 -13
- package/build/commonjs/Tabs/TabIndicator.js.map +1 -1
- package/build/commonjs/Tabs/TabIndicatorProps.js.map +1 -1
- package/build/commonjs/Tabs/Tabs.js +43 -62
- 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/useScrollViewReaction.js +65 -0
- package/build/commonjs/Tabs/useScrollViewReaction.js.map +1 -0
- package/build/commonjs/hooks/useValidWindowDimensions/index.ios.js +14 -7
- package/build/commonjs/hooks/useValidWindowDimensions/index.ios.js.map +1 -1
- package/build/module/ButtonBase/ButtonBase.js +3 -2
- package/build/module/ButtonBase/ButtonBase.js.map +1 -1
- package/build/module/CircularProgress/CircularProgress.js +15 -11
- package/build/module/CircularProgress/CircularProgress.js.map +1 -1
- package/build/module/Tab/Tab.js +5 -5
- package/build/module/Tab/Tab.js.map +1 -1
- package/build/module/Tabs/IndexAwareTab.js +18 -0
- package/build/module/Tabs/IndexAwareTab.js.map +1 -0
- package/build/module/Tabs/TabIndicator.js +26 -14
- package/build/module/Tabs/TabIndicator.js.map +1 -1
- package/build/module/Tabs/TabIndicatorProps.js.map +1 -1
- package/build/module/Tabs/Tabs.js +42 -60
- 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/useScrollViewReaction.js +54 -0
- package/build/module/Tabs/useScrollViewReaction.js.map +1 -0
- package/build/module/hooks/useValidWindowDimensions/index.ios.js +15 -9
- package/build/module/hooks/useValidWindowDimensions/index.ios.js.map +1 -1
- package/build/typescript/CircularProgress/CircularProgress.d.ts +1 -1
- package/build/typescript/Tabs/IndexAwareTab.d.ts +9 -0
- package/build/typescript/Tabs/TabIndicatorProps.d.ts +2 -2
- package/build/typescript/Tabs/Tabs.d.ts +4 -1
- package/build/typescript/Tabs/TabsProps.d.ts +22 -9
- package/build/typescript/Tabs/index.d.ts +1 -1
- package/build/typescript/Tabs/useScrollViewReaction.d.ts +9 -0
- package/build/typescript/hooks/useValidWindowDimensions/index.ios.d.ts +2 -1
- package/package.json +2 -2
- package/src/ButtonBase/ButtonBase.tsx +6 -2
- package/src/CircularProgress/CircularProgress.tsx +23 -15
- package/src/Tab/Tab.tsx +5 -5
- package/src/Tabs/IndexAwareTab.tsx +30 -0
- package/src/Tabs/TabIndicator.tsx +26 -14
- package/src/Tabs/TabIndicatorProps.ts +2 -2
- package/src/Tabs/Tabs.tsx +50 -62
- package/src/Tabs/TabsProps.ts +25 -9
- package/src/Tabs/index.ts +1 -1
- package/src/Tabs/useScrollViewReaction.ts +63 -0
- package/src/hooks/useValidWindowDimensions/index.ios.ts +16 -10
- package/build/commonjs/Tabs/useTabsWidth.js +0 -26
- package/build/commonjs/Tabs/useTabsWidth.js.map +0 -1
- package/build/module/Tabs/useTabsWidth.js +0 -18
- package/build/module/Tabs/useTabsWidth.js.map +0 -1
- package/build/typescript/Tabs/useTabsWidth.d.ts +0 -2
- package/src/Tabs/useTabsWidth.ts +0 -20
|
@@ -29,7 +29,7 @@ const ORIGINAL_SCALE = 1;
|
|
|
29
29
|
const MINIFIED_SCALE = .96; // at "node_modules/react-native/Libraries/Pressability.js"
|
|
30
30
|
// const DEFAULT_MIN_PRESS_DURATION = 130;
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const SCALE_EFFECT_PRESS_IN_DELAY = 130;
|
|
33
33
|
|
|
34
34
|
const startTimingAnimationWithDefaults = (value, toValue) => {
|
|
35
35
|
_reactNative.Animated.timing(value, {
|
|
@@ -92,13 +92,14 @@ function ButtonBase(props) {
|
|
|
92
92
|
scale
|
|
93
93
|
}]
|
|
94
94
|
};
|
|
95
|
+
const pressDelay = pressEffect === 'scale' ? SCALE_EFFECT_PRESS_IN_DELAY : 0;
|
|
95
96
|
return /*#__PURE__*/_react.default.createElement(_animated.AnimatedPressable, _extends({
|
|
96
97
|
disabled: disabled,
|
|
97
98
|
onPress: handlePress,
|
|
98
99
|
onPressIn: handlePressIn,
|
|
99
100
|
onPressOut: handlePressOut,
|
|
100
101
|
style: [animatedStyle, styleProp],
|
|
101
|
-
unstable_pressDelay:
|
|
102
|
+
unstable_pressDelay: pressDelay
|
|
102
103
|
}, otherProps), typeof children !== 'function' ? _ref => {
|
|
103
104
|
let {
|
|
104
105
|
hovered
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ORIGINAL_OPACITY","DISABLED_OPACITY","ACTIVE_OPACITY","ORIGINAL_SCALE","MINIFIED_SCALE","
|
|
1
|
+
{"version":3,"names":["ORIGINAL_OPACITY","DISABLED_OPACITY","ACTIVE_OPACITY","ORIGINAL_SCALE","MINIFIED_SCALE","SCALE_EFFECT_PRESS_IN_DELAY","startTimingAnimationWithDefaults","value","toValue","Animated","timing","duration","useNativeDriver","start","ButtonBase","props","children","disabled","disableThrottle","onPress","pressEffect","style","styleProp","throttleMillis","otherProps","handlePress","useThrottle","periodMillis","callback","opacity","useRef","Value","current","scale","useEffect","setValue","startScaleAnimation","useCallback","pressIn","isHover","startOpacityAnimation","startPressAnimation","handlePressIn","handlePressOut","animatedStyle","transform","pressDelay","hovered","undefined"],"sources":["ButtonBase.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef } from 'react';\nimport { Animated } from 'react-native';\nimport { useThrottle } from '../hooks';\nimport { AnimatedPressable } from '../animated';\nimport type ButtonBaseProps from './ButtonBaseProps';\n\ninterface StartPressAnimation {\n (pressIn: boolean, isHover: boolean): void;\n}\n\nexport const ORIGINAL_OPACITY = 1;\nexport const DISABLED_OPACITY = .3;\nconst ACTIVE_OPACITY = .65;\n\nconst ORIGINAL_SCALE = 1;\nconst MINIFIED_SCALE = .96;\n\n// at \"node_modules/react-native/Libraries/Pressability.js\"\n// const DEFAULT_MIN_PRESS_DURATION = 130;\nconst SCALE_EFFECT_PRESS_IN_DELAY = 130;\n\ntype TimingAnimationValue = Animated.Value | Animated.ValueXY;\ntype TimingAnimationToValue = Animated.TimingAnimationConfig['toValue'];\n\nconst startTimingAnimationWithDefaults = (\n value: TimingAnimationValue,\n toValue: TimingAnimationToValue,\n) => {\n Animated.timing(value, {\n toValue,\n duration: 150,\n useNativeDriver: true,\n }).start();\n};\n\nexport default function ButtonBase(props: ButtonBaseProps) {\n const {\n children,\n disabled = false,\n disableThrottle = false,\n onPress,\n pressEffect = 'opacity',\n style: styleProp,\n throttleMillis = 650,\n ...otherProps\n } = props;\n\n const handlePress = useThrottle({\n periodMillis: disableThrottle ? 0 : throttleMillis,\n callback: onPress,\n });\n\n const opacity = useRef<Animated.Value>(new Animated.Value(ORIGINAL_OPACITY)).current;\n const scale = useRef<Animated.Value>(new Animated.Value(ORIGINAL_SCALE)).current;\n\n useEffect(() => {\n opacity.setValue(disabled ? DISABLED_OPACITY : ORIGINAL_OPACITY);\n }, [disabled]);\n\n const startScaleAnimation = useCallback<StartPressAnimation>((pressIn, isHover) => {\n if (!isHover) {\n startTimingAnimationWithDefaults(\n scale,\n pressIn ? MINIFIED_SCALE : ORIGINAL_SCALE,\n );\n }\n }, []);\n\n const startOpacityAnimation = useCallback<StartPressAnimation>((pressIn) => {\n if (pressIn) {\n opacity.setValue(ACTIVE_OPACITY);\n } else {\n startTimingAnimationWithDefaults(opacity, ORIGINAL_OPACITY);\n }\n }, []);\n\n const startPressAnimation = useCallback<StartPressAnimation>((pressIn, isHover = false) => {\n if (pressEffect === 'scale') {\n startScaleAnimation(pressIn, isHover);\n } else if (pressEffect === 'opacity') {\n startOpacityAnimation(pressIn, isHover);\n }\n }, [pressEffect]);\n\n const handlePressIn = useCallback(() => {\n startPressAnimation(true, false);\n }, [startPressAnimation]);\n\n const handlePressOut = useCallback(() => {\n startPressAnimation(false, false);\n }, [startPressAnimation]);\n\n const animatedStyle = {\n opacity,\n transform: [{ scale }],\n };\n\n const pressDelay = pressEffect === 'scale'\n ? SCALE_EFFECT_PRESS_IN_DELAY\n : 0;\n\n return (\n <AnimatedPressable\n disabled={disabled}\n onPress={handlePress}\n onPressIn={handlePressIn}\n onPressOut={handlePressOut}\n style={[\n animatedStyle,\n styleProp,\n ]}\n unstable_pressDelay={pressDelay}\n {...otherProps}\n >\n {typeof children !== 'function' ? (\n ({ hovered }) => {\n if (hovered !== undefined && !disabled) {\n startPressAnimation(hovered, true);\n }\n\n return children;\n }\n ) : children}\n </AnimatedPressable>\n );\n};\n"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;AAOO,MAAMA,gBAAgB,GAAG,CAAzB;;AACA,MAAMC,gBAAgB,GAAG,EAAzB;;AACP,MAAMC,cAAc,GAAG,GAAvB;AAEA,MAAMC,cAAc,GAAG,CAAvB;AACA,MAAMC,cAAc,GAAG,GAAvB,C,CAEA;AACA;;AACA,MAAMC,2BAA2B,GAAG,GAApC;;AAKA,MAAMC,gCAAgC,GAAG,CACrCC,KADqC,EAErCC,OAFqC,KAGpC;EACDC,qBAAA,CAASC,MAAT,CAAgBH,KAAhB,EAAuB;IACnBC,OADmB;IAEnBG,QAAQ,EAAE,GAFS;IAGnBC,eAAe,EAAE;EAHE,CAAvB,EAIGC,KAJH;AAKH,CATD;;AAWe,SAASC,UAAT,CAAoBC,KAApB,EAA4C;EACvD,M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
|
@@ -7,7 +7,7 @@ exports.default = CircularProgress;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
11
|
|
|
12
12
|
var _icons = require("../internal/icons");
|
|
13
13
|
|
|
@@ -15,10 +15,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
15
15
|
|
|
16
16
|
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; }
|
|
17
17
|
|
|
18
|
-
const ANIMATION_CONFIG = {
|
|
19
|
-
duration: 900,
|
|
20
|
-
easing: _reactNativeReanimated.Easing.linear
|
|
21
|
-
};
|
|
22
18
|
const MIN_ROTATE_DEGREE = 0;
|
|
23
19
|
const MAX_ROTATE_DEGREE = 360;
|
|
24
20
|
|
|
@@ -36,16 +32,24 @@ function CircularProgress(props) {
|
|
|
36
32
|
style: styleProp
|
|
37
33
|
} = props;
|
|
38
34
|
const styles = useStyles();
|
|
39
|
-
const rotate = (0,
|
|
40
|
-
const animatedStyle =
|
|
35
|
+
const rotate = (0, _react.useRef)(new _reactNative.Animated.Value(MIN_ROTATE_DEGREE)).current;
|
|
36
|
+
const animatedStyle = {
|
|
41
37
|
transform: [{
|
|
42
|
-
rotate:
|
|
38
|
+
rotate: rotate.interpolate({
|
|
39
|
+
inputRange: [MIN_ROTATE_DEGREE, MAX_ROTATE_DEGREE],
|
|
40
|
+
outputRange: [`${MIN_ROTATE_DEGREE}deg`, `${MAX_ROTATE_DEGREE}deg`]
|
|
41
|
+
})
|
|
43
42
|
}]
|
|
44
|
-
}
|
|
43
|
+
};
|
|
45
44
|
(0, _react.useEffect)(() => {
|
|
46
|
-
|
|
45
|
+
_reactNative.Animated.loop(_reactNative.Animated.timing(rotate, {
|
|
46
|
+
toValue: MAX_ROTATE_DEGREE,
|
|
47
|
+
duration: 900,
|
|
48
|
+
easing: _reactNative.Easing.linear,
|
|
49
|
+
useNativeDriver: true
|
|
50
|
+
})).start();
|
|
47
51
|
}, []);
|
|
48
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
52
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
|
|
49
53
|
children: /*#__PURE__*/_react.default.createElement(_icons.CircularProgress, null),
|
|
50
54
|
style: [animatedStyle, styles.root, styleProp]
|
|
51
55
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["MIN_ROTATE_DEGREE","MAX_ROTATE_DEGREE","useStyles","root","alignItems","justifyContent","CircularProgress","props","style","styleProp","styles","rotate","useRef","Animated","Value","current","animatedStyle","transform","interpolate","inputRange","outputRange","useEffect","loop","timing","toValue","duration","easing","Easing","linear","useNativeDriver","start"],"sources":["CircularProgress.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport type { ViewProps } from 'react-native';\nimport { Animated, Easing } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { CircularProgress as CircularProgressIcon } from '../internal/icons';\nimport { OverridableComponentProps } from '../types';\n\ntype CircularProgressStyles = NamedStylesStringUnion<'root'>;\n\nconst MIN_ROTATE_DEGREE = 0;\nconst MAX_ROTATE_DEGREE = 360;\n\nconst useStyles: UseStyles<CircularProgressStyles> = function (): CircularProgressStyles {\n return {\n root: {\n alignItems: 'center',\n justifyContent: 'center',\n },\n };\n};\n\nexport default function CircularProgress(props: OverridableComponentProps<ViewProps>) {\n const { style: styleProp } = props;\n\n const styles = useStyles();\n\n const rotate = useRef(new Animated.Value(MIN_ROTATE_DEGREE)).current;\n\n const animatedStyle = {\n transform: [{\n rotate: rotate.interpolate({\n inputRange: [MIN_ROTATE_DEGREE, MAX_ROTATE_DEGREE],\n outputRange: [`${MIN_ROTATE_DEGREE}deg`, `${MAX_ROTATE_DEGREE}deg`],\n }),\n }],\n };\n\n useEffect(() => {\n Animated.loop(\n Animated.timing(\n rotate,\n {\n toValue: MAX_ROTATE_DEGREE,\n duration: 900,\n easing: Easing.linear,\n useNativeDriver: true,\n },\n ),\n ).start();\n }, []);\n\n return (\n <Animated.View\n children={<CircularProgressIcon/>}\n style={[\n animatedStyle,\n styles.root,\n styleProp,\n ]}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;;;;;AAKA,MAAMA,iBAAiB,GAAG,CAA1B;AACA,MAAMC,iBAAiB,GAAG,GAA1B;;AAEA,MAAMC,SAA4C,GAAG,YAAoC;EACrF,OAAO;IACHC,IAAI,EAAE;MACFC,UAAU,EAAE,QADV;MAEFC,cAAc,EAAE;IAFd;EADH,CAAP;AAMH,CAPD;;AASe,SAASC,gBAAT,CAA0BC,KAA1B,EAAuE;EAClF,MAAM;IAAEC,KAAK,EAAEC;EAAT,IAAuBF,KAA7B;EAEA,MAAMG,MAAM,GAAGR,SAAS,EAAxB;EAEA,MAAMS,MAAM,GAAG,IAAAC,aAAA,EAAO,IAAIC,qBAAA,CAASC,KAAb,CAAmBd,iBAAnB,CAAP,EAA8Ce,OAA7D;EAEA,MAAMC,aAAa,GAAG;IAClBC,SAAS,EAAE,CAAC;MACRN,MAAM,EAAEA,MAAM,CAACO,WAAP,CAAmB;QACvBC,UAAU,EAAE,CAACnB,iBAAD,EAAoBC,iBAApB,CADW;QAEvBmB,WAAW,EAAE,CAAE,GAAEpB,iBAAkB,KAAtB,EAA6B,GAAEC,iBAAkB,KAAjD;MAFU,CAAnB;IADA,CAAD;EADO,CAAtB;EASA,IAAAoB,gBAAA,EAAU,MAAM;IACZR,qBAAA,CAASS,IAAT,CACIT,qBAAA,CAASU,MAAT,CACIZ,MADJ,EAEI;MACIa,OAAO,EAAEvB,iBADb;MAEIwB,QAAQ,EAAE,GAFd;MAGIC,MAAM,EAAEC,mBAAA,CAAOC,MAHnB;MAIIC,eAAe,EAAE;IAJrB,CAFJ,CADJ,EAUEC,KAVF;EAWH,CAZD,EAYG,EAZH;EAcA,oBACI,6BAAC,qBAAD,CAAU,IAAV;IACI,QAAQ,eAAE,6BAAC,uBAAD,OADd;IAEI,KAAK,EAAE,CACHd,aADG,EAEHN,MAAM,CAACP,IAFJ,EAGHM,SAHG;EAFX,EADJ;AAUH;;AAAA"}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = Tab;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
11
|
|
|
@@ -19,6 +19,10 @@ var _TabIndicator = _interopRequireDefault(require("./TabIndicator"));
|
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
22
|
+
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); }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
22
26
|
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
27
|
|
|
24
28
|
const styles = _styles.StyleSheet.create({
|
|
@@ -42,9 +46,9 @@ function Tab(props) {
|
|
|
42
46
|
const {
|
|
43
47
|
badgeVisible = false,
|
|
44
48
|
children,
|
|
45
|
-
enableIndicator,
|
|
49
|
+
enableIndicator = false,
|
|
46
50
|
icon: defaultIcon,
|
|
47
|
-
selected,
|
|
51
|
+
selected = false,
|
|
48
52
|
selectedIcon,
|
|
49
53
|
variant = 'primary',
|
|
50
54
|
style,
|
|
@@ -60,7 +64,7 @@ function Tab(props) {
|
|
|
60
64
|
});
|
|
61
65
|
const pressEffect = selected ? 'none' : 'opacity';
|
|
62
66
|
const icon = selected ? selectedIcon || defaultIcon : defaultIcon;
|
|
63
|
-
const iconElement = icon ? /*#__PURE__*/_react.
|
|
67
|
+
const iconElement = icon ? /*#__PURE__*/(0, _react.cloneElement)(icon, {
|
|
64
68
|
fill: color
|
|
65
69
|
}) : null;
|
|
66
70
|
return /*#__PURE__*/_react.default.createElement(_TabBase.default, _extends({
|
|
@@ -73,7 +77,7 @@ function Tab(props) {
|
|
|
73
77
|
}), /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
74
78
|
children: children,
|
|
75
79
|
style: (0, _styles.css)(fontStyle)
|
|
76
|
-
}), enableIndicator ? /*#__PURE__*/_react.default.createElement(_TabIndicator.default, null) : null);
|
|
80
|
+
}), enableIndicator && selected ? /*#__PURE__*/_react.default.createElement(_TabIndicator.default, null) : null);
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["styles","StyleSheet","create","root","Platform","OS","minWidth","primary","minHeight","secondary","bottomNavigation","Tab","props","badgeVisible","children","enableIndicator","icon","defaultIcon","selected","selectedIcon","variant","style","otherProps","theme","useTheme","vertical","color","palette","text","hint","tabBaseStyle","css","fontStyle","createFontStyle","selector","typo","h2","button2","flag","pressEffect","iconElement","
|
|
1
|
+
{"version":3,"names":["styles","StyleSheet","create","root","Platform","OS","minWidth","primary","minHeight","secondary","bottomNavigation","Tab","props","badgeVisible","children","enableIndicator","icon","defaultIcon","selected","selectedIcon","variant","style","otherProps","theme","useTheme","vertical","color","palette","text","hint","tabBaseStyle","css","fontStyle","createFontStyle","selector","typo","h2","button2","flag","pressEffect","iconElement","cloneElement","fill"],"sources":["Tab.tsx"],"sourcesContent":["import React, { cloneElement } from 'react';\nimport { Platform, Text } from 'react-native';\nimport Badge from '../Badge';\nimport TabBase from '../TabBase';\nimport type TabProps from './TabProps';\nimport { createFontStyle, css, StyleSheet, useTheme } from '../styles';\nimport TabIndicator from './TabIndicator';\n\nconst styles = StyleSheet.create({\n root: {\n // TODO: Remove redundant platform checking\n ...(Platform.OS === 'web' ? { minWidth: 'auto' } : {}),\n },\n primary: {\n minHeight: 48,\n },\n secondary: {\n minHeight: 48,\n },\n bottomNavigation: {\n minHeight: 56,\n },\n});\n\nexport default function Tab(props: TabProps) {\n const {\n badgeVisible = false,\n children,\n enableIndicator = false,\n icon: defaultIcon,\n selected = false,\n selectedIcon,\n variant = 'primary',\n style,\n ...otherProps\n } = props;\n\n const theme = useTheme();\n\n const vertical = variant === 'bottom-navigation';\n\n const color = selected ? theme.palette.text.primary : theme.palette.text.hint;\n\n const tabBaseStyle = css([\n styles.root,\n variant === 'primary'\n ? styles.primary\n : (variant === 'secondary' ? styles.secondary : styles.bottomNavigation),\n style,\n ]);\n\n const fontStyle = createFontStyle(theme, {\n selector: (typo) => variant === 'primary'\n ? typo.h2\n : (variant === 'secondary' ? typo.button2 : typo.flag),\n color,\n });\n\n const pressEffect = selected ? 'none' : 'opacity';\n\n const icon = selected ? (selectedIcon || defaultIcon) : defaultIcon;\n const iconElement = icon ? cloneElement(icon, { fill: color }) : null;\n\n return (\n <TabBase\n pressEffect={pressEffect}\n style={tabBaseStyle}\n vertical={vertical}\n {...otherProps}\n >\n <Badge\n children={iconElement}\n invisible={!badgeVisible}\n />\n\n <Text\n children={children}\n style={css(fontStyle)}\n />\n\n {(enableIndicator && selected) ? <TabIndicator/> : null}\n </TabBase>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;;;;;AAEA,MAAMA,MAAM,GAAGC,kBAAA,CAAWC,MAAX,CAAkB;EAC7BC,IAAI,EAAE,EACF;IACA,IAAIC,qBAAA,CAASC,EAAT,KAAgB,KAAhB,GAAwB;MAAEC,QAAQ,EAAE;IAAZ,CAAxB,GAA+C,EAAnD;EAFE,CADuB;EAK7BC,OAAO,EAAE;IACLC,SAAS,EAAE;EADN,CALoB;EAQ7BC,SAAS,EAAE;IACPD,SAAS,EAAE;EADJ,CARkB;EAW7BE,gBAAgB,EAAE;IACdF,SAAS,EAAE;EADG;AAXW,CAAlB,CAAf;;AAgBe,SAASG,GAAT,CAAaC,KAAb,EAA8B;EACzC,MAAM;IACFC,YAAY,GAAG,KADb;IAEFC,QAFE;IAGFC,eAAe,GAAG,KAHhB;IAIFC,IAAI,EAAEC,WAJJ;IAKFC,QAAQ,GAAG,KALT;IAMFC,YANE;IAOFC,OAAO,GAAG,SAPR;IAQFC,KARE;IASF,GAAGC;EATD,IAUFV,KAVJ;EAYA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d;IAEI,KAAK,EAAE,IAAAiB,WAAA,EAAIC,SAAJ;EAFX,EAXJ,EAgBMjB,eAAe,IAAIG,QAApB,gBAAgC,6BAAC,qBAAD,OAAhC,GAAkD,IAhBvD,CADJ;AAoBH;;AAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = IndexAwareTab;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
11
|
+
|
|
12
|
+
function IndexAwareTab(props) {
|
|
13
|
+
const {
|
|
14
|
+
children,
|
|
15
|
+
index,
|
|
16
|
+
sharedIndex
|
|
17
|
+
} = 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]);
|
|
22
|
+
return /*#__PURE__*/(0, _react.cloneElement)(children, {
|
|
23
|
+
selected
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
;
|
|
28
|
+
//# sourceMappingURL=IndexAwareTab.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -21,13 +21,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
21
|
|
|
22
22
|
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
23
|
|
|
24
|
+
const INDICATOR_WIDTH = 10;
|
|
25
|
+
const INDICATOR_HEIGHT = 4;
|
|
26
|
+
const SCROLLABLE_TABS_INSET = 12 * 2;
|
|
27
|
+
|
|
24
28
|
const useStyles = function () {
|
|
25
29
|
const theme = (0, _styles.useTheme)();
|
|
26
30
|
return {
|
|
27
31
|
root: {
|
|
28
32
|
backgroundColor: theme.palette.secondary.main,
|
|
33
|
+
left: 0,
|
|
29
34
|
bottom: 0,
|
|
30
|
-
|
|
35
|
+
width: INDICATOR_WIDTH,
|
|
36
|
+
height: INDICATOR_HEIGHT,
|
|
31
37
|
position: 'absolute'
|
|
32
38
|
},
|
|
33
39
|
disabled: {
|
|
@@ -36,29 +42,37 @@ const useStyles = function () {
|
|
|
36
42
|
};
|
|
37
43
|
};
|
|
38
44
|
|
|
45
|
+
const ANIMATION_CONFIG = {
|
|
46
|
+
duration: 300,
|
|
47
|
+
easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.exp)
|
|
48
|
+
};
|
|
49
|
+
|
|
39
50
|
function TabIndicator(props) {
|
|
40
51
|
const {
|
|
41
52
|
coordinates,
|
|
42
53
|
disabled,
|
|
43
54
|
scrollable,
|
|
44
|
-
|
|
55
|
+
sharedIndex,
|
|
45
56
|
style,
|
|
46
57
|
...otherProps
|
|
47
58
|
} = props;
|
|
48
59
|
const styles = useStyles();
|
|
49
60
|
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
61
|
+
const index = sharedIndex.value;
|
|
62
|
+
const {
|
|
63
|
+
x1,
|
|
64
|
+
x2
|
|
65
|
+
} = coordinates[index] ?? _TabCoordinate.defaultCoordinate;
|
|
66
|
+
const tabWidth = x2 - x1;
|
|
67
|
+
const translateX = x1 + (tabWidth - INDICATOR_WIDTH) / 2;
|
|
68
|
+
const inset = scrollable ? SCROLLABLE_TABS_INSET : 0;
|
|
69
|
+
const scaleX = (tabWidth - inset) / INDICATOR_WIDTH;
|
|
59
70
|
return {
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
transform: [{
|
|
72
|
+
translateX: (0, _reactNativeReanimated.withTiming)(translateX, ANIMATION_CONFIG)
|
|
73
|
+
}, {
|
|
74
|
+
scaleX: (0, _reactNativeReanimated.withTiming)(scaleX, ANIMATION_CONFIG)
|
|
75
|
+
}]
|
|
62
76
|
};
|
|
63
77
|
}, [coordinates, scrollable]);
|
|
64
78
|
return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, _extends({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useStyles","theme","useTheme","root","backgroundColor","palette","secondary","main","bottom","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","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,EAAxB;AACA,MAAMC,gBAAgB,GAAG,CAAzB;AAEA,MAAMC,qBAAqB,GAAG,KAAK,CAAnC;;AAEA,MAAMC,SAAwC,GAAG,YAAgC;EAC7E,MAAMC,KAAK,GAAG,IAAAC,gBAAA,GAAd;EAEA,OAAO;IACHC,IAAI,EAAE;MACFC,eAAe,EAAEH,KAAK,CAACI,OAAN,CAAcC,SAAd,CAAwBC,IADvC;MAEFC,IAAI,EAAE,CAFJ;MAGFC,MAAM,EAAE,CAHN;MAIFC,KAAK,EAAEb,eAJL;MAKFc,MAAM,EAAEb,gBALN;MAMFc,QAAQ,EAAE;IANR,CADH;IASHC,QAAQ,EAAE;MACNF,MAAM,EAAE;IADF;EATP,CAAP;AAaH,CAhBD;;AAkBA,MAAMG,gBAA4C,GAAG;EACjDC,QAAQ,EAAE,GADuC;EAEjDC,MAAM,EAAEC,6BAAA,CAAOC,GAAP,CAAWD,6BAAA,CAAOE,GAAlB;AAFyC,CAArD;;AAKe,SAASC,YAAT,CAAsBC,KAAtB,EAAgD;EAC3D,MAAM;IACFC,WADE;IAEFT,QAFE;IAGFU,UAHE;IAIFC,WAJE;IAKFC,KALE;IAMF,GAAGC;EAND,IAOFL,KAPJ;EASA,MAAMM,MAAM,GAAG3B,SAAS,EAAxB;EAEA,MAAM4B,aAAa,GAAG,IAAAC,uCAAA,EAAiB,MAAM;IACzC,MAAMC,KAAK,GAAGN,WAAW,CAACO,KAA1B;IAEA,MAAM;MAAEC,EAAF;MAAMC;IAAN,IAAaX,WAAW,CAACQ,KAAD,CAAX,IAAsBI,gCAAzC;IAEA,MAAMC,QAAQ,GAAGF,EAAE,GAAGD,EAAtB;IAEA,MAAMI,UAAU,GAAGJ,EAAE,GAAG,CAACG,QAAQ,GAAGtC,eAAZ,IAA+B,CAAvD;IAEA,MAAMwC,KAAK,GAAGd,UAAU,GAAGxB,qBAAH,GAA2B,CAAnD;IACA,MAAMuC,MAAM,GAAG,CAACH,QAAQ,GAAGE,KAAZ,IAAqBxC,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 +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 *
|
|
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":""}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
@@ -15,18 +15,18 @@ var _styles = require("../styles");
|
|
|
15
15
|
|
|
16
16
|
var _TabIndicator = _interopRequireDefault(require("./TabIndicator"));
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _IndexAwareTab = _interopRequireDefault(require("./IndexAwareTab"));
|
|
19
19
|
|
|
20
20
|
var _useTabCoordinates = _interopRequireDefault(require("./useTabCoordinates"));
|
|
21
21
|
|
|
22
|
+
var _useScrollViewReaction = _interopRequireDefault(require("./useScrollViewReaction"));
|
|
23
|
+
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
25
|
|
|
24
26
|
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); }
|
|
25
27
|
|
|
26
28
|
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; }
|
|
27
29
|
|
|
28
|
-
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); }
|
|
29
|
-
|
|
30
30
|
const useStyles = function () {
|
|
31
31
|
const theme = (0, _styles.useTheme)();
|
|
32
32
|
return {
|
|
@@ -43,63 +43,42 @@ const useStyles = function () {
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const
|
|
47
|
-
duration: 200,
|
|
48
|
-
easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.exp)
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
function Tabs(props) {
|
|
46
|
+
const Tabs = /*#__PURE__*/(0, _react.forwardRef)(function Tabs(props, ref) {
|
|
52
47
|
const {
|
|
53
48
|
children,
|
|
54
|
-
|
|
49
|
+
initialIndex = 0,
|
|
55
50
|
disableIndicator = false,
|
|
56
51
|
keyboardDismissMode = 'none',
|
|
57
52
|
keyboardShouldPersistTaps = 'never',
|
|
58
53
|
onChange,
|
|
59
54
|
scrollable = false,
|
|
60
|
-
scrollValue: scrollValueProp,
|
|
61
55
|
style,
|
|
62
56
|
variant = 'primary',
|
|
63
|
-
|
|
57
|
+
UNSTABLE_sharedIndex
|
|
64
58
|
} = props;
|
|
59
|
+
const fallbackSharedIndex = (0, _reactNativeReanimated.useSharedValue)(initialIndex);
|
|
60
|
+
const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;
|
|
61
|
+
|
|
62
|
+
const getCurrentIndex = () => sharedIndex.value;
|
|
63
|
+
|
|
64
|
+
const setTab = newIndex => {
|
|
65
|
+
sharedIndex.value = newIndex;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
(0, _react.useImperativeHandle)(ref, () => ({
|
|
69
|
+
getCurrentIndex,
|
|
70
|
+
setTab
|
|
71
|
+
}), [sharedIndex]);
|
|
65
72
|
const styles = useStyles();
|
|
66
|
-
const [containerWidth, handleLayout] = (0, _useTabsWidth.default)();
|
|
67
|
-
const scrollViewRef = (0, _react.useRef)(null);
|
|
68
73
|
const {
|
|
69
74
|
coordinates,
|
|
70
75
|
updateCoordinate
|
|
71
76
|
} = (0, _useTabCoordinates.default)(children);
|
|
72
|
-
const
|
|
73
|
-
|
|
77
|
+
const {
|
|
78
|
+
scrollViewRef,
|
|
79
|
+
onLayout
|
|
80
|
+
} = (0, _useScrollViewReaction.default)(sharedIndex, coordinates);
|
|
74
81
|
const isReadyToRenderIndicator = coordinates.length > 0;
|
|
75
|
-
(0, _react.useEffect)(() => {
|
|
76
|
-
const animateTab = index => {
|
|
77
|
-
scrollValue.value = (0, _reactNativeReanimated.withTiming)(index, ANIMATION_CONFIG);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
animateTab(indexProp);
|
|
81
|
-
}, [indexProp, scrollValue]);
|
|
82
|
-
const scrollPosition = (0, _react.useMemo)(() => {
|
|
83
|
-
const coordinate = coordinates[indexProp - 1];
|
|
84
|
-
|
|
85
|
-
if (coordinate) {
|
|
86
|
-
const tabWidth = coordinate.x2 - coordinate.x1;
|
|
87
|
-
return Math.floor(coordinate.x1 + tabWidth / 2);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return 0;
|
|
91
|
-
}, [indexProp, coordinates]);
|
|
92
|
-
(0, _react.useEffect)(() => {
|
|
93
|
-
const scrollView = scrollViewRef.current;
|
|
94
|
-
|
|
95
|
-
if (scrollView) {
|
|
96
|
-
scrollView.scrollTo({
|
|
97
|
-
x: scrollPosition,
|
|
98
|
-
y: 0,
|
|
99
|
-
animated: true
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}, [scrollPosition, containerWidth]);
|
|
103
82
|
|
|
104
83
|
const tabElements = _react.default.Children.map(children, (child, index) => {
|
|
105
84
|
const onLayout = event => {
|
|
@@ -119,36 +98,38 @@ function Tabs(props) {
|
|
|
119
98
|
const onPress = () => {
|
|
120
99
|
var _child$props$onPress, _child$props;
|
|
121
100
|
|
|
101
|
+
setTab(index);
|
|
122
102
|
onChange === null || onChange === void 0 ? void 0 : onChange(index); // @ts-ignore
|
|
123
103
|
|
|
124
104
|
(_child$props$onPress = (_child$props = child.props).onPress) === null || _child$props$onPress === void 0 ? void 0 : _child$props$onPress.call(_child$props);
|
|
125
|
-
};
|
|
105
|
+
}; // @ts-ignore
|
|
126
106
|
|
|
127
|
-
const selected = index === indexProp;
|
|
128
|
-
const enableIndicatorPlaceholder = disableIndicator ? false : isReadyToRenderIndicator ? false : selected; //@ts-ignore
|
|
129
107
|
|
|
130
|
-
|
|
131
|
-
enableIndicator:
|
|
108
|
+
const tabElement = /*#__PURE__*/(0, _react.cloneElement)(child, {
|
|
109
|
+
enableIndicator: !disableIndicator && !isReadyToRenderIndicator,
|
|
132
110
|
onLayout,
|
|
133
111
|
onPress,
|
|
134
112
|
onMouseDown,
|
|
135
113
|
variant,
|
|
136
|
-
selected,
|
|
137
114
|
style: scrollable ? undefined : styles.fixedTab
|
|
138
115
|
});
|
|
116
|
+
return /*#__PURE__*/_react.default.createElement(_IndexAwareTab.default, {
|
|
117
|
+
children: tabElement,
|
|
118
|
+
index: index,
|
|
119
|
+
sharedIndex: sharedIndex
|
|
120
|
+
});
|
|
139
121
|
});
|
|
140
122
|
|
|
141
|
-
const
|
|
123
|
+
const tabIndicator = isReadyToRenderIndicator ? /*#__PURE__*/_react.default.createElement(_TabIndicator.default, {
|
|
142
124
|
coordinates: coordinates,
|
|
143
125
|
disabled: disableIndicator,
|
|
144
126
|
scrollable: scrollable,
|
|
145
|
-
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
onLayout: handleLayout,
|
|
127
|
+
sharedIndex: sharedIndex
|
|
128
|
+
}) : null;
|
|
129
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
130
|
+
onLayout: onLayout,
|
|
150
131
|
style: (0, _styles.css)([styles.root, scrollable ? undefined : styles.fixedRoot, style])
|
|
151
|
-
},
|
|
132
|
+
}, scrollable ? /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
|
|
152
133
|
automaticallyAdjustContentInsets: false,
|
|
153
134
|
bounces: false,
|
|
154
135
|
contentContainerStyle: styles.scrollableContainer,
|
|
@@ -160,8 +141,8 @@ function Tabs(props) {
|
|
|
160
141
|
showsVerticalScrollIndicator: false,
|
|
161
142
|
keyboardDismissMode: keyboardDismissMode,
|
|
162
143
|
keyboardShouldPersistTaps: keyboardShouldPersistTaps
|
|
163
|
-
}, tabElements,
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
;
|
|
144
|
+
}, tabElements, tabIndicator) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, tabElements, tabIndicator));
|
|
145
|
+
});
|
|
146
|
+
var _default = Tabs;
|
|
147
|
+
exports.default = _default;
|
|
167
148
|
//# sourceMappingURL=Tabs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useStyles","theme","useTheme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","ANIMATION_CONFIG","duration","easing","Easing","out","exp","Tabs","props","children","index","indexProp","disableIndicator","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","scrollValue","scrollValueProp","style","variant","otherProps","styles","containerWidth","handleLayout","useTabsWidth","scrollViewRef","useRef","coordinates","updateCoordinate","useTabCoordinates","internalScrollValue","useSharedValue","isReadyToRenderIndicator","length","useEffect","animateTab","value","withTiming","scrollPosition","useMemo","coordinate","tabWidth","x2","x1","Math","floor","scrollView","current","scrollTo","x","y","animated","tabElements","React","Children","map","child","onLayout","event","width","nativeEvent","layout","onMouseDown","e","preventDefault","onPress","selected","enableIndicatorPlaceholder","cloneElement","enableIndicator","undefined","indicator","css"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, useEffect, useMemo, useRef } from 'react';\nimport { GestureResponderEvent, LayoutChangeEvent, ScrollView, View } from 'react-native';\nimport type { WithTimingConfig } from 'react-native-reanimated';\nimport { Easing, useSharedValue, withTiming } from 'react-native-reanimated';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport type TabsProps from './TabsProps';\nimport TabIndicator from './TabIndicator';\nimport useTabsWidth from './useTabsWidth';\nimport useTabCoordinates from './useTabCoordinates';\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 ANIMATION_CONFIG: Readonly<WithTimingConfig> = {\n duration: 200,\n easing: Easing.out(Easing.exp),\n};\n\nexport default function Tabs(props: TabsProps) {\n const {\n children,\n index: indexProp,\n disableIndicator = false,\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n scrollValue: scrollValueProp,\n style,\n variant = 'primary',\n ...otherProps\n } = props;\n\n const styles = useStyles();\n\n const [containerWidth, handleLayout] = useTabsWidth();\n\n const scrollViewRef = useRef<ScrollView | null>(null);\n\n const { coordinates, updateCoordinate } = useTabCoordinates(children);\n\n const internalScrollValue = useSharedValue(0);\n const scrollValue = scrollValueProp ?? internalScrollValue;\n\n const isReadyToRenderIndicator = coordinates.length > 0;\n\n useEffect(() => {\n const animateTab = (index: number) => {\n scrollValue.value = withTiming(index, ANIMATION_CONFIG);\n };\n\n animateTab(indexProp);\n }, [indexProp, scrollValue]);\n\n const scrollPosition = useMemo<number>(() => {\n const coordinate = coordinates[indexProp - 1];\n\n if (coordinate) {\n const tabWidth = coordinate.x2 - coordinate.x1;\n return Math.floor(coordinate.x1 + tabWidth / 2);\n }\n\n return 0;\n }, [indexProp, coordinates]);\n\n useEffect(() => {\n const scrollView = scrollViewRef.current;\n\n if (scrollView) {\n scrollView.scrollTo({ x: scrollPosition, y: 0, animated: true });\n }\n }, [scrollPosition, containerWidth]);\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 onChange?.(index);\n // @ts-ignore\n child.props.onPress?.();\n };\n\n const selected = index === indexProp;\n const enableIndicatorPlaceholder = disableIndicator\n ? false\n : (isReadyToRenderIndicator ? false : selected);\n\n //@ts-ignore\n return cloneElement(child, {\n enableIndicator: enableIndicatorPlaceholder,\n onLayout,\n onPress,\n onMouseDown,\n variant,\n selected,\n style: scrollable ? undefined : styles.fixedTab,\n });\n });\n\n const indicator = (\n <TabIndicator\n coordinates={coordinates}\n disabled={disableIndicator}\n scrollable={scrollable}\n scrollValue={scrollValue}\n />\n );\n\n return (\n <View\n onLayout={handleLayout}\n style={css([\n styles.root,\n scrollable ? undefined : styles.fixedRoot,\n style,\n ])}\n {...otherProps}\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 {indicator}\n </ScrollView>\n ) : (\n <React.Fragment>\n {tabElements}\n {indicator}\n </React.Fragment>\n )}\n </View>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AAEA;;AAEA;;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,gBAA4C,GAAG;EACjDC,QAAQ,EAAE,GADuC;EAEjDC,MAAM,EAAEC,6BAAA,CAAOC,GAAP,CAAWD,6BAAA,CAAOE,GAAlB;AAFyC,CAArD;;AAKe,SAASC,IAAT,CAAcC,KAAd,EAAgC;EAC3C,MAAM;IACFC,QADE;IAEFC,KAAK,EAAEC,SAFL;IAGFC,gBAAgB,GAAG,KAHjB;IAIFC,mB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AKvB3C,OALuB;MAMvB+C,QANuB;MAOvBhD,KAAK,EAAEH,UAAU,GAAGuD,SAAH,GAAejD,MAAM,CAAC1B;IAPhB,CAApB,CAAP;EASH,CAlCmB,CAApB;;EAoCA,MAAM4E,SAAS,gBACX,6BAAC,qBAAD;IACI,WAAW,EAAE5C,WADjB;IAEI,QAAQ,EAAEhB,gBAFd;IAGI,UAAU,EAAEI,UAHhB;IAII,WAAW,EAAEC;EAJjB,EADJ;;EASA,oBACI,6BAAC,iBAAD;IACI,QAAQ,EAAEO,YADd;IAEI,KAAK,EAAE,IAAAiD,WAAA,EAAI,CACPnD,MAAM,CAAC7B,IADA,EAEPuB,UAAU,GAAGuD,SAAH,GAAejD,MAAM,CAAC5B,SAFzB,EAGPyB,KAHO,CAAJ;EAFX,GAOQE,UAPR,GASKL,UAAU,gBACP,6BAAC,uBAAD;IACI,gCAAgC,EAAE,KADtC;IAEI,OAAO,EAAE,KAFb;IAGI,qBAAqB,EAAEM,MAAM,CAACxB,mBAHlC;IAII,sBAAsB,EAAE,IAJ5B;IAKI,UAAU,EAAE,IALhB;IAMI,GAAG,EAAE4B,aANT;IAOI,YAAY,EAAE,KAPlB;IAQI,8BAA8B,EAAE,KARpC;IASI,4BAA4B,EAAE,KATlC;IAUI,mBAAmB,EAAEb,mBAVzB;IAWI,yBAAyB,EAAEC;EAX/B,GAaKuC,WAbL,EAcKmB,SAdL,CADO,gBAkBP,6BAAC,cAAD,CAAO,QAAP,QACKnB,WADL,EAEKmB,SAFL,CA3BR,CADJ;AAmCH;;AAAA"}
|
|
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>\n );\n});\n\nexport default Tabs;\n"],"mappings":";;;;;;;AAAA;;AAEA;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BAAwB,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 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["TabsProps.ts"],"sourcesContent":["import
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Tabs';\nexport type { default as TabsProps } from './TabsProps'
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default } from './Tabs';\nexport type { default as TabsProps, TabsInstance } from './TabsProps';\n"],"mappings":";;;;;;;;;;;;AAAA"}
|