@fountain-ui/core 2.0.0-beta.13 → 2.0.0-beta.14
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/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 +18 -12
- package/build/commonjs/Tabs/TabIndicator.js.map +1 -1
- package/build/commonjs/Tabs/TabIndicatorProps.js.map +1 -1
- package/build/commonjs/Tabs/Tabs.js +41 -61
- 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 +54 -0
- package/build/commonjs/Tabs/useScrollViewReaction.js.map +1 -0
- 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 +18 -13
- package/build/module/Tabs/TabIndicator.js.map +1 -1
- package/build/module/Tabs/TabIndicatorProps.js.map +1 -1
- package/build/module/Tabs/Tabs.js +40 -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 +44 -0
- package/build/module/Tabs/useScrollViewReaction.js.map +1 -0
- 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 +19 -11
- package/build/typescript/Tabs/index.d.ts +1 -1
- package/build/typescript/Tabs/useScrollViewReaction.d.ts +9 -0
- package/package.json +2 -2
- package/src/Tab/Tab.tsx +5 -5
- package/src/Tabs/IndexAwareTab.tsx +30 -0
- package/src/Tabs/TabIndicator.tsx +17 -13
- package/src/Tabs/TabIndicatorProps.ts +2 -2
- package/src/Tabs/Tabs.tsx +47 -62
- package/src/Tabs/TabsProps.ts +22 -12
- package/src/Tabs/index.ts +1 -1
- package/src/Tabs/useScrollViewReaction.ts +55 -0
- 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
|
@@ -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,MAAMW,KAAK,GAAG,IAAAC,gBAAA,GAAd;EAEA,MAAMC,QAAQ,GAAGL,OAAO,KAAK,mB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G,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"}
|
|
@@ -36,29 +36,35 @@ const useStyles = function () {
|
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const ANIMATION_CONFIG = {
|
|
40
|
+
duration: 200,
|
|
41
|
+
easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.exp)
|
|
42
|
+
};
|
|
43
|
+
|
|
39
44
|
function TabIndicator(props) {
|
|
40
45
|
const {
|
|
41
46
|
coordinates,
|
|
42
47
|
disabled,
|
|
43
48
|
scrollable,
|
|
44
|
-
|
|
49
|
+
sharedIndex,
|
|
45
50
|
style,
|
|
46
51
|
...otherProps
|
|
47
52
|
} = props;
|
|
48
53
|
const styles = useStyles();
|
|
49
54
|
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
55
|
+
const index = sharedIndex.value;
|
|
56
|
+
const {
|
|
57
|
+
x1,
|
|
58
|
+
x2
|
|
59
|
+
} = coordinates[index] ?? _TabCoordinate.defaultCoordinate;
|
|
60
|
+
const tabWidth = x2 - x1;
|
|
61
|
+
const singleInset = scrollable ? 12 : 0;
|
|
62
|
+
const totalInset = singleInset * 2;
|
|
63
|
+
const nextLeft = x1 + singleInset;
|
|
64
|
+
const nextWidth = tabWidth - totalInset;
|
|
59
65
|
return {
|
|
60
|
-
left:
|
|
61
|
-
width:
|
|
66
|
+
left: (0, _reactNativeReanimated.withTiming)(nextLeft, ANIMATION_CONFIG),
|
|
67
|
+
width: (0, _reactNativeReanimated.withTiming)(nextWidth, ANIMATION_CONFIG)
|
|
62
68
|
};
|
|
63
69
|
}, [coordinates, scrollable]);
|
|
64
70
|
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","TabIndicator","props","coordinates","scrollable","
|
|
1
|
+
{"version":3,"names":["useStyles","theme","useTheme","root","backgroundColor","palette","secondary","main","bottom","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","singleInset","totalInset","nextLeft","nextWidth","left","withTiming","width","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 useStyles: UseStyles<TabIndicatorStyles> = function (): TabIndicatorStyles {\n const theme = useTheme();\n\n return {\n root: {\n backgroundColor: theme.palette.secondary.main,\n bottom: 0,\n height: 4,\n position: 'absolute',\n },\n disabled: {\n height: 0,\n },\n };\n};\n\nconst ANIMATION_CONFIG: Readonly<WithTimingConfig> = {\n duration: 200,\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 singleInset = scrollable ? 12 : 0;\n const totalInset = singleInset * 2;\n\n const nextLeft = x1 + singleInset;\n const nextWidth = tabWidth - totalInset;\n\n return {\n left: withTiming(nextLeft, ANIMATION_CONFIG),\n width: withTiming(nextWidth, ANIMATION_CONFIG),\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,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,MAAM,EAAE,CAFN;MAGFC,MAAM,EAAE,CAHN;MAIFC,QAAQ,EAAE;IAJR,CADH;IAOHC,QAAQ,EAAE;MACNF,MAAM,EAAE;IADF;EAPP,CAAP;AAWH,CAdD;;AAgBA,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,GAAGzB,SAAS,EAAxB;EAEA,MAAM0B,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,WAAW,GAAGb,UAAU,GAAG,EAAH,GAAQ,CAAtC;IACA,MAAMc,UAAU,GAAGD,WAAW,GAAG,CAAjC;IAEA,MAAME,QAAQ,GAAGN,EAAE,GAAGI,WAAtB;IACA,MAAMG,SAAS,GAAGJ,QAAQ,GAAGE,UAA7B;IAEA,OAAO;MACHG,IAAI,EAAE,IAAAC,iCAAA,EAAWH,QAAX,EAAqBxB,gBAArB,CADH;MAEH4B,KAAK,EAAE,IAAAD,iCAAA,EAAWF,SAAX,EAAsBzB,gBAAtB;IAFJ,CAAP;EAIH,CAjBqB,EAiBnB,CAACQ,WAAD,EAAcC,UAAd,CAjBmB,CAAtB;EAmBA,oBACI,6BAAC,8BAAD,CAAU,IAAV;IACI,KAAK,EAAE,CACHI,MAAM,CAACtB,IADJ,EAEHQ,QAAQ,GAAGc,MAAM,CAACd,QAAV,GAAqB8B,SAF1B,EAGHf,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,40 @@ 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
|
-
variant = 'primary'
|
|
63
|
-
...otherProps
|
|
56
|
+
variant = 'primary'
|
|
64
57
|
} = props;
|
|
58
|
+
const sharedIndex = (0, _reactNativeReanimated.useSharedValue)(initialIndex);
|
|
59
|
+
|
|
60
|
+
const getCurrentIndex = () => sharedIndex.value;
|
|
61
|
+
|
|
62
|
+
const setTab = newIndex => {
|
|
63
|
+
sharedIndex.value = newIndex;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
(0, _react.useImperativeHandle)(ref, () => ({
|
|
67
|
+
getCurrentIndex,
|
|
68
|
+
setTab
|
|
69
|
+
}), [sharedIndex]);
|
|
65
70
|
const styles = useStyles();
|
|
66
|
-
const [containerWidth, handleLayout] = (0, _useTabsWidth.default)();
|
|
67
|
-
const scrollViewRef = (0, _react.useRef)(null);
|
|
68
71
|
const {
|
|
69
72
|
coordinates,
|
|
70
73
|
updateCoordinate
|
|
71
74
|
} = (0, _useTabCoordinates.default)(children);
|
|
72
|
-
const
|
|
73
|
-
|
|
75
|
+
const {
|
|
76
|
+
scrollViewRef,
|
|
77
|
+
onLayout
|
|
78
|
+
} = (0, _useScrollViewReaction.default)(sharedIndex, coordinates);
|
|
74
79
|
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
80
|
|
|
104
81
|
const tabElements = _react.default.Children.map(children, (child, index) => {
|
|
105
82
|
const onLayout = event => {
|
|
@@ -119,36 +96,39 @@ function Tabs(props) {
|
|
|
119
96
|
const onPress = () => {
|
|
120
97
|
var _child$props$onPress, _child$props;
|
|
121
98
|
|
|
99
|
+
setTab(index);
|
|
122
100
|
onChange === null || onChange === void 0 ? void 0 : onChange(index); // @ts-ignore
|
|
123
101
|
|
|
124
102
|
(_child$props$onPress = (_child$props = child.props).onPress) === null || _child$props$onPress === void 0 ? void 0 : _child$props$onPress.call(_child$props);
|
|
125
|
-
};
|
|
103
|
+
}; // @ts-ignore
|
|
126
104
|
|
|
127
|
-
const selected = index === indexProp;
|
|
128
|
-
const enableIndicatorPlaceholder = disableIndicator ? false : isReadyToRenderIndicator ? false : selected; //@ts-ignore
|
|
129
105
|
|
|
130
|
-
|
|
131
|
-
enableIndicator:
|
|
106
|
+
const tabElement = /*#__PURE__*/(0, _react.cloneElement)(child, {
|
|
107
|
+
enableIndicator: !disableIndicator && isReadyToRenderIndicator,
|
|
132
108
|
onLayout,
|
|
133
109
|
onPress,
|
|
134
110
|
onMouseDown,
|
|
135
111
|
variant,
|
|
136
|
-
selected,
|
|
137
112
|
style: scrollable ? undefined : styles.fixedTab
|
|
138
113
|
});
|
|
114
|
+
return /*#__PURE__*/_react.default.createElement(_IndexAwareTab.default, {
|
|
115
|
+
children: tabElement,
|
|
116
|
+
index: index,
|
|
117
|
+
sharedIndex: sharedIndex
|
|
118
|
+
});
|
|
139
119
|
});
|
|
140
120
|
|
|
141
|
-
const
|
|
121
|
+
const tabIndicator = /*#__PURE__*/_react.default.createElement(_TabIndicator.default, {
|
|
142
122
|
coordinates: coordinates,
|
|
143
123
|
disabled: disableIndicator,
|
|
144
124
|
scrollable: scrollable,
|
|
145
|
-
|
|
125
|
+
sharedIndex: sharedIndex
|
|
146
126
|
});
|
|
147
127
|
|
|
148
|
-
return /*#__PURE__*/_react.default.createElement(_reactNative.View,
|
|
149
|
-
onLayout:
|
|
128
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
129
|
+
onLayout: onLayout,
|
|
150
130
|
style: (0, _styles.css)([styles.root, scrollable ? undefined : styles.fixedRoot, style])
|
|
151
|
-
},
|
|
131
|
+
}, scrollable ? /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, {
|
|
152
132
|
automaticallyAdjustContentInsets: false,
|
|
153
133
|
bounces: false,
|
|
154
134
|
contentContainerStyle: styles.scrollableContainer,
|
|
@@ -160,8 +140,8 @@ function Tabs(props) {
|
|
|
160
140
|
showsVerticalScrollIndicator: false,
|
|
161
141
|
keyboardDismissMode: keyboardDismissMode,
|
|
162
142
|
keyboardShouldPersistTaps: keyboardShouldPersistTaps
|
|
163
|
-
}, tabElements,
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
;
|
|
143
|
+
}, tabElements, tabIndicator) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, tabElements, tabIndicator));
|
|
144
|
+
});
|
|
145
|
+
var _default = Tabs;
|
|
146
|
+
exports.default = _default;
|
|
167
147
|
//# 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,mBAAmB,GAAG,MAJpB;IAKFC,yBAAyB,GAAG,OAL1B;IAMFC,QANE;IAOFC,UAAU,GAAG,KAPX;IAQFC,WA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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","sharedIndex","useSharedValue","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 } = props;\n\n const sharedIndex = useSharedValue<number>(initialIndex);\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 = (\n <TabIndicator\n coordinates={coordinates}\n disabled={disableIndicator}\n scrollable={scrollable}\n sharedIndex={sharedIndex}\n />\n );\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;;AACA;;AAEA;;AAGA;;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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AGPkB,KAHO,CAAJ;EAFX,GAQKD,UAAU,gBACP,6BAAC,uBAAD;IACI,gCAAgC,EAAE,KADtC;IAEI,OAAO,EAAE,KAFb;IAGI,qBAAqB,EAAEU,MAAM,CAACvB,mBAHlC;IAII,sBAAsB,EAAE,IAJ5B;IAKI,UAAU,EAAE,IALhB;IAMI,GAAG,EAAE2B,aANT;IAOI,YAAY,EAAE,KAPlB;IAQI,8BAA8B,EAAE,KARpC;IASI,4BAA4B,EAAE,KATlC;IAUI,mBAAmB,EAAEjB,mBAVzB;IAWI,yBAAyB,EAAEC;EAX/B,GAaKqB,WAbL,EAcKmB,YAdL,CADO,gBAkBP,6BAAC,cAAD,CAAO,QAAP,QACKnB,WADL,EAEKmB,YAFL,CA1BR,CADJ;AAkCH,CAzHY,CAAb;eA2HehD,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 { 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 * 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"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useScrollViewReaction;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
11
|
+
|
|
12
|
+
function useScrollViewReaction(sharedIndex, coordinates) {
|
|
13
|
+
const scrollViewRef = (0, _react.useRef)(null);
|
|
14
|
+
const lastScrolledPositionRef = (0, _react.useRef)(NaN);
|
|
15
|
+
|
|
16
|
+
const scrollTo = scrollPosition => {
|
|
17
|
+
const scrollView = scrollViewRef.current;
|
|
18
|
+
|
|
19
|
+
if (scrollView && Number.isFinite(scrollPosition)) {
|
|
20
|
+
scrollView.scrollTo({
|
|
21
|
+
x: scrollPosition,
|
|
22
|
+
y: 0,
|
|
23
|
+
animated: true
|
|
24
|
+
});
|
|
25
|
+
lastScrolledPositionRef.current = scrollPosition;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const onLayout = (0, _react.useCallback)(() => {
|
|
30
|
+
scrollTo(lastScrolledPositionRef.current);
|
|
31
|
+
}, []);
|
|
32
|
+
(0, _reactNativeReanimated.useAnimatedReaction)(() => {
|
|
33
|
+
const prevIndex = sharedIndex.value - 1;
|
|
34
|
+
const prevCoordinate = coordinates[prevIndex];
|
|
35
|
+
|
|
36
|
+
if (prevCoordinate) {
|
|
37
|
+
const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;
|
|
38
|
+
return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return 0;
|
|
42
|
+
}, (scrollPosition, prevScrollPosition) => {
|
|
43
|
+
if (scrollPosition !== prevScrollPosition) {
|
|
44
|
+
(0, _reactNativeReanimated.runOnJS)(scrollTo)(scrollPosition);
|
|
45
|
+
}
|
|
46
|
+
}, [coordinates]);
|
|
47
|
+
return {
|
|
48
|
+
scrollViewRef,
|
|
49
|
+
onLayout
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
;
|
|
54
|
+
//# sourceMappingURL=useScrollViewReaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useScrollViewReaction","sharedIndex","coordinates","scrollViewRef","useRef","lastScrolledPositionRef","NaN","scrollTo","scrollPosition","scrollView","current","Number","isFinite","x","y","animated","onLayout","useCallback","useAnimatedReaction","prevIndex","value","prevCoordinate","prevTabWidth","x2","x1","Math","floor","prevScrollPosition","runOnJS"],"sources":["useScrollViewReaction.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useCallback, useRef } from 'react';\nimport type { ScrollView, ViewProps } from 'react-native';\nimport { runOnJS, SharedValue, useAnimatedReaction } from 'react-native-reanimated';\nimport type TabCoordinate from './TabCoordinate';\n\nexport interface UseScrollViewReaction {\n scrollViewRef: MutableRefObject<ScrollView | null>;\n onLayout: ViewProps['onLayout'];\n}\n\nexport default function useScrollViewReaction(\n sharedIndex: SharedValue<number>,\n coordinates: TabCoordinate[],\n): UseScrollViewReaction {\n const scrollViewRef = useRef<ScrollView | null>(null);\n\n const lastScrolledPositionRef = useRef<number>(NaN);\n\n const scrollTo = (scrollPosition: number) => {\n const scrollView = scrollViewRef.current;\n\n if (scrollView && Number.isFinite(scrollPosition)) {\n scrollView.scrollTo({ x: scrollPosition, y: 0, animated: true });\n\n lastScrolledPositionRef.current = scrollPosition;\n }\n };\n\n const onLayout = useCallback(() => {\n scrollTo(lastScrolledPositionRef.current);\n }, []);\n\n useAnimatedReaction(\n () => {\n const prevIndex = sharedIndex.value - 1;\n const prevCoordinate = coordinates[prevIndex];\n\n if (prevCoordinate) {\n const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;\n return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);\n }\n\n return 0;\n },\n (scrollPosition, prevScrollPosition) => {\n if (scrollPosition !== prevScrollPosition) {\n runOnJS(scrollTo)(scrollPosition);\n }\n },\n [coordinates],\n );\n\n return { scrollViewRef, onLayout };\n};\n"],"mappings":";;;;;;;AACA;;AAEA;;AAQe,SAASA,qBAAT,CACXC,WADW,EAEXC,WAFW,EAGU;EACrB,MAAMC,aAAa,GAAG,IAAAC,aAAA,EAA0B,IAA1B,CAAtB;EAEA,MAAMC,uBAAuB,GAAG,IAAAD,aAAA,EAAeE,GAAf,CAAhC;;EAEA,MAAMC,QAAQ,GAAIC,cAAD,IAA4B;IACzC,MAAMC,UAAU,GAAGN,aAAa,CAACO,OAAjC;;IAEA,IAAID,UAAU,IAAIE,MAAM,CAACC,QAAP,CAAgBJ,cAAhB,CAAlB,EAAmD;MAC/CC,UAAU,CAACF,QAAX,CAAoB;QAAEM,CAAC,EAAEL,cAAL;QAAqBM,CAAC,EAAE,CAAxB;QAA2BC,QAAQ,EAAE;MAArC,CAApB;MAEAV,uBAAuB,CAACK,OAAxB,GAAkCF,cAAlC;IACH;EACJ,CARD;;EAUA,MAAMQ,QAAQ,GAAG,IAAAC,kBAAA,EAAY,MAAM;IAC/BV,QAAQ,CAACF,uBAAuB,CAACK,OAAzB,CAAR;EACH,CAFgB,EAEd,EAFc,CAAjB;EAIA,IAAAQ,0CAAA,EACI,MAAM;IACF,MAAMC,SAAS,GAAGlB,WAAW,CAACmB,KAAZ,GAAoB,CAAtC;IACA,MAAMC,cAAc,GAAGnB,WAAW,CAACiB,SAAD,CAAlC;;IAEA,IAAIE,cAAJ,EAAoB;MAChB,MAAMC,YAAY,GAAGD,cAAc,CAACE,EAAf,GAAoBF,cAAc,CAACG,EAAxD;MACA,OAAOC,IAAI,CAACC,KAAL,CAAWL,cAAc,CAACG,EAAf,GAAoBF,YAAY,GAAG,CAA9C,CAAP;IACH;;IAED,OAAO,CAAP;EACH,CAXL,EAYI,CAACd,cAAD,EAAiBmB,kBAAjB,KAAwC;IACpC,IAAInB,cAAc,KAAKmB,kBAAvB,EAA2C;MACvC,IAAAC,8BAAA,EAAQrB,QAAR,EAAkBC,cAAlB;IACH;EACJ,CAhBL,EAiBI,CAACN,WAAD,CAjBJ;EAoBA,OAAO;IAAEC,aAAF;IAAiBa;EAAjB,CAAP;AACH;;AAAA"}
|
package/build/module/Tab/Tab.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
|
|
3
|
-
import React from 'react';
|
|
3
|
+
import React, { cloneElement } from 'react';
|
|
4
4
|
import { Platform, Text } from 'react-native';
|
|
5
5
|
import Badge from '../Badge';
|
|
6
6
|
import TabBase from '../TabBase';
|
|
@@ -26,9 +26,9 @@ export default function Tab(props) {
|
|
|
26
26
|
const {
|
|
27
27
|
badgeVisible = false,
|
|
28
28
|
children,
|
|
29
|
-
enableIndicator,
|
|
29
|
+
enableIndicator = false,
|
|
30
30
|
icon: defaultIcon,
|
|
31
|
-
selected,
|
|
31
|
+
selected = false,
|
|
32
32
|
selectedIcon,
|
|
33
33
|
variant = 'primary',
|
|
34
34
|
style,
|
|
@@ -44,7 +44,7 @@ export default function Tab(props) {
|
|
|
44
44
|
});
|
|
45
45
|
const pressEffect = selected ? 'none' : 'opacity';
|
|
46
46
|
const icon = selected ? selectedIcon || defaultIcon : defaultIcon;
|
|
47
|
-
const iconElement = icon ? /*#__PURE__*/
|
|
47
|
+
const iconElement = icon ? /*#__PURE__*/cloneElement(icon, {
|
|
48
48
|
fill: color
|
|
49
49
|
}) : null;
|
|
50
50
|
return /*#__PURE__*/React.createElement(TabBase, _extends({
|
|
@@ -57,7 +57,7 @@ export default function Tab(props) {
|
|
|
57
57
|
}), /*#__PURE__*/React.createElement(Text, {
|
|
58
58
|
children: children,
|
|
59
59
|
style: css(fontStyle)
|
|
60
|
-
}), enableIndicator ? /*#__PURE__*/React.createElement(TabIndicator, null) : null);
|
|
60
|
+
}), enableIndicator && selected ? /*#__PURE__*/React.createElement(TabIndicator, null) : null);
|
|
61
61
|
}
|
|
62
62
|
;
|
|
63
63
|
//# sourceMappingURL=Tab.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Platform","Text","Badge","TabBase","createFontStyle","css","StyleSheet","useTheme","TabIndicator","styles","create","root","OS","minWidth","primary","minHeight","secondary","bottomNavigation","Tab","props","badgeVisible","children","enableIndicator","icon","defaultIcon","selected","selectedIcon","variant","style","otherProps","theme","vertical","color","palette","text","hint","tabBaseStyle","fontStyle","selector","typo","h2","button2","flag","pressEffect","iconElement","
|
|
1
|
+
{"version":3,"names":["React","cloneElement","Platform","Text","Badge","TabBase","createFontStyle","css","StyleSheet","useTheme","TabIndicator","styles","create","root","OS","minWidth","primary","minHeight","secondary","bottomNavigation","Tab","props","badgeVisible","children","enableIndicator","icon","defaultIcon","selected","selectedIcon","variant","style","otherProps","theme","vertical","color","palette","text","hint","tabBaseStyle","fontStyle","selector","typo","h2","button2","flag","pressEffect","iconElement","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,OAAOA,KAAP,IAAgBC,YAAhB,QAAoC,OAApC;AACA,SAASC,QAAT,EAAmBC,IAAnB,QAA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AJtC,EAKrBW,KALqB,CAAD,CAAxB;EAQA,MAAMS,SAAS,GAAGjC,eAAe,CAAC0B,KAAD,EAAQ;IACrCQ,QAAQ,EAAGC,IAAD,IAAUZ,OAAO,KAAK,SAAZ,GACdY,IAAI,CAACC,EADS,GAEbb,OAAO,KAAK,WAAZ,GAA0BY,IAAI,CAACE,OAA/B,GAAyCF,IAAI,CAACG,IAHhB;IAIrCV;EAJqC,CAAR,CAAjC;EAOA,MAAMW,WAAW,GAAGlB,QAAQ,GAAG,MAAH,GAAY,SAAxC;EAEA,MAAMF,IAAI,GAAGE,QAAQ,GAAIC,YAAY,IAAIF,WAApB,GAAmCA,WAAxD;EACA,MAAMoB,WAAW,GAAGrB,IAAI,gBAAGxB,YAAY,CAACwB,IAAD,EAAO;IAAEsB,IAAI,EAAEb;EAAR,CAAP,CAAf,GAAyC,IAAjE;EAEA,oBACI,oBAAC,OAAD;IACI,WAAW,EAAEW,WADjB;IAEI,KAAK,EAAEP,YAFX;IAGI,QAAQ,EAAEL;EAHd,GAIQF,UAJR,gBAMI,oBAAC,KAAD;IACI,QAAQ,EAAEe,WADd;IAEI,SAAS,EAAE,CAACxB;EAFhB,EANJ,eAWI,oBAAC,IAAD;IACI,QAAQ,EAAEC,QADd;IAEI,KAAK,EAAEhB,GAAG,CAACgC,SAAD;EAFd,EAXJ,EAgBMf,eAAe,IAAIG,QAApB,gBAAgC,oBAAC,YAAD,OAAhC,GAAkD,IAhBvD,CADJ;AAoBH;AAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { cloneElement, useState } from 'react';
|
|
2
|
+
import { runOnJS, useAnimatedReaction } from 'react-native-reanimated';
|
|
3
|
+
export default function IndexAwareTab(props) {
|
|
4
|
+
const {
|
|
5
|
+
children,
|
|
6
|
+
index,
|
|
7
|
+
sharedIndex
|
|
8
|
+
} = props;
|
|
9
|
+
const [selected, setSelected] = useState(index === sharedIndex.value);
|
|
10
|
+
useAnimatedReaction(() => index === sharedIndex.value, result => {
|
|
11
|
+
runOnJS(setSelected)(result);
|
|
12
|
+
}, [index]);
|
|
13
|
+
return /*#__PURE__*/cloneElement(children, {
|
|
14
|
+
selected
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
;
|
|
18
|
+
//# sourceMappingURL=IndexAwareTab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["cloneElement","useState","runOnJS","useAnimatedReaction","IndexAwareTab","props","children","index","sharedIndex","selected","setSelected","value","result"],"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,SAAgBA,YAAhB,EAA8BC,QAA9B,QAA8C,OAA9C;AAEA,SAASC,OAAT,EAAkBC,mBAAlB,QAA6C,yBAA7C;AAQA,eAAe,SAASC,aAAT,CAAuBC,KAAvB,EAAkD;EAC7D,MAAM;IACFC,QADE;IAEFC,KAFE;IAGFC;EAHE,IAIFH,KAJJ;EAMA,MAAM,CAACI,QAAD,EAAWC,WAAX,IAA0BT,QAAQ,CAACM,KAAK,KAAKC,WAAW,CAACG,KAAvB,CAAxC;EAEAR,mBAAmB,CACf,MAAMI,KAAK,KAAKC,WAAW,CAACG,KADb,EAEdC,MAAD,IAAY;IACRV,OAAO,CAACQ,WAAD,CAAP,CAAqBE,MAArB;EACH,CAJc,EAKf,CAACL,KAAD,CALe,CAAnB;EAQA,oBAAOP,YAAY,CAACM,QAAD,EAAW;IAAEG;EAAF,CAAX,CAAnB;AACH;AAAA"}
|