@fountain-ui/core 2.0.0-beta.20 → 2.0.0-beta.23
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/Chip/Chip.js +2 -0
- package/build/commonjs/Chip/Chip.js.map +1 -1
- package/build/commonjs/Chip/ChipProps.js.map +1 -1
- package/build/commonjs/Tabs/ScrollableTabsView.js +2 -1
- package/build/commonjs/Tabs/ScrollableTabsView.js.map +1 -1
- package/build/commonjs/Tabs/Tabs.js +4 -2
- package/build/commonjs/Tabs/Tabs.js.map +1 -1
- package/build/commonjs/Tabs/useScrollViewReaction.js +20 -12
- package/build/commonjs/Tabs/useScrollViewReaction.js.map +1 -1
- package/build/commonjs/store/MockStore.js +5 -1
- package/build/commonjs/store/MockStore.js.map +1 -1
- package/build/commonjs/store/SimpleStore.js +20 -16
- package/build/commonjs/store/SimpleStore.js.map +1 -1
- package/build/commonjs/store/types.js.map +1 -1
- package/build/module/Chip/Chip.js +2 -0
- package/build/module/Chip/Chip.js.map +1 -1
- package/build/module/Chip/ChipProps.js.map +1 -1
- package/build/module/Tabs/ScrollableTabsView.js +2 -1
- package/build/module/Tabs/ScrollableTabsView.js.map +1 -1
- package/build/module/Tabs/Tabs.js +4 -2
- package/build/module/Tabs/Tabs.js.map +1 -1
- package/build/module/Tabs/useScrollViewReaction.js +20 -12
- package/build/module/Tabs/useScrollViewReaction.js.map +1 -1
- package/build/module/store/MockStore.js +5 -1
- package/build/module/store/MockStore.js.map +1 -1
- package/build/module/store/SimpleStore.js +20 -16
- package/build/module/store/SimpleStore.js.map +1 -1
- package/build/module/store/types.js.map +1 -1
- package/build/typescript/Chip/ChipProps.d.ts +4 -0
- package/build/typescript/Tabs/ScrollableTabsView.d.ts +1 -0
- package/build/typescript/Tabs/useScrollViewReaction.d.ts +1 -1
- package/build/typescript/store/MockStore.d.ts +4 -3
- package/build/typescript/store/SimpleStore.d.ts +6 -5
- package/build/typescript/store/types.d.ts +4 -3
- package/package.json +2 -2
- package/src/Chip/Chip.tsx +2 -0
- package/src/Chip/ChipProps.ts +5 -0
- package/src/Tabs/ScrollableTabsView.tsx +3 -1
- package/src/Tabs/Tabs.tsx +4 -3
- package/src/Tabs/useScrollViewReaction.ts +21 -11
- package/src/store/MockStore.ts +7 -3
- package/src/store/SimpleStore.ts +23 -19
- package/src/store/types.ts +4 -3
|
@@ -40,6 +40,7 @@ function Chip(props) {
|
|
|
40
40
|
const {
|
|
41
41
|
children,
|
|
42
42
|
endIcon: endIconProp,
|
|
43
|
+
numberOfLines,
|
|
43
44
|
onPress,
|
|
44
45
|
startIcon: startIconProp,
|
|
45
46
|
style: styleProp,
|
|
@@ -90,6 +91,7 @@ function Chip(props) {
|
|
|
90
91
|
style: chipStyle
|
|
91
92
|
}, otherProps), startIcon, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
92
93
|
children: children,
|
|
94
|
+
numberOfLines: numberOfLines,
|
|
93
95
|
style: textStyle
|
|
94
96
|
}), endIcon);
|
|
95
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ICON_SIZE","useStyles","theme","useTheme","root","alignItems","borderRadius","flexDirection","height","justifyContent","paddingLeft","spacing","paddingRight","Chip","props","children","endIcon","endIconProp","onPress","startIcon","startIconProp","style","styleProp","variant","otherProps","styles","fontColor","palette","tertiary","main","primary","variantStyleMap","outlined","backgroundColor","paper","default","borderColor","border","borderWidth","filled","grey","bold","chipStyle","css","fontStyle","createFontStyle","selector","typo","subtitle2","color","textMarginSize","textMarginStyle","marginLeft","marginRight","undefined","textStyle","textAlign","iconProps","width","fill","cloneElementSafely"],"sources":["Chip.tsx"],"sourcesContent":["import React from 'react';\nimport { Text } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { createFontStyle, css, useTheme } from '../styles';\nimport { cloneElementSafely } from '../utils';\nimport ButtonBase from '../ButtonBase';\nimport type ChipProps from './ChipProps';\n\ntype ChipStyles = NamedStylesStringUnion<'root'>;\n\nconst ICON_SIZE = 16;\n\nconst useStyles: UseStyles<ChipStyles> = function (): ChipStyles {\n const theme = useTheme();\n\n return {\n root: {\n alignItems: 'center',\n borderRadius: 20,\n flexDirection: 'row',\n height: 32,\n justifyContent: 'center',\n paddingLeft: theme.spacing(2),\n paddingRight: theme.spacing(2),\n },\n };\n};\n\nexport default function Chip(props: ChipProps) {\n const {\n children,\n endIcon: endIconProp,\n onPress,\n startIcon: startIconProp,\n style: styleProp,\n variant = 'outlined',\n ...otherProps\n } = props;\n\n const theme = useTheme();\n const styles = useStyles();\n\n const fontColor = variant === 'outlined'\n ? theme.palette.tertiary.main\n : theme.palette.primary.main;\n\n const variantStyleMap = {\n outlined: {\n backgroundColor: theme.palette.paper.default,\n borderColor: theme.palette.border,\n borderWidth: 2,\n },\n filled: {\n backgroundColor: theme.palette.paper.grey,\n },\n bold: {\n backgroundColor: theme.palette.paper.grey,\n borderColor: theme.palette.primary.main,\n borderWidth: 2,\n },\n };\n\n const chipStyle = css([\n styles.root,\n variantStyleMap[variant],\n styleProp,\n ]);\n\n const fontStyle = createFontStyle(theme, {\n selector: (typo) => typo.subtitle2,\n color: fontColor,\n });\n\n const textMarginSize = theme.spacing(1);\n const textMarginStyle = startIconProp\n ? { marginLeft: textMarginSize }\n : endIconProp\n ? { marginRight: textMarginSize }\n : undefined;\n\n const textStyle = css([\n fontStyle,\n textMarginStyle,\n { textAlign: 'center' },\n ]);\n\n const iconProps = {\n width: ICON_SIZE,\n height: ICON_SIZE,\n fill: fontColor,\n };\n\n const startIcon = cloneElementSafely(startIconProp, iconProps);\n const endIcon = cloneElementSafely(endIconProp, iconProps);\n\n return (\n <ButtonBase\n onPress={onPress}\n style={chipStyle}\n {...otherProps}\n >\n {startIcon}\n\n <Text\n children={children}\n style={textStyle}\n />\n\n {endIcon}\n </ButtonBase>\n );\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAKA,MAAMA,SAAS,GAAG,EAAlB;;AAEA,MAAMC,SAAgC,GAAG,YAAwB;EAC7D,MAAMC,KAAK,GAAG,IAAAC,gBAAA,GAAd;EAEA,OAAO;IACHC,IAAI,EAAE;MACFC,UAAU,EAAE,QADV;MAEFC,YAAY,EAAE,EAFZ;MAGFC,aAAa,EAAE,KAHb;MAIFC,MAAM,EAAE,EAJN;MAKFC,cAAc,EAAE,QALd;MAMFC,WAAW,EAAER,KAAK,CAACS,OAAN,CAAc,CAAd,CANX;MAOFC,YAAY,EAAEV,KAAK,CAACS,OAAN,CAAc,CAAd;IAPZ;EADH,CAAP;AAWH,CAdD;;AAgBe,SAASE,IAAT,CAAcC,KAAd,EAAgC;EAC3C,MAAM;IACFC,QADE;IAEFC,OAAO,EAAEC,WAFP;IAGFC,
|
|
1
|
+
{"version":3,"names":["ICON_SIZE","useStyles","theme","useTheme","root","alignItems","borderRadius","flexDirection","height","justifyContent","paddingLeft","spacing","paddingRight","Chip","props","children","endIcon","endIconProp","numberOfLines","onPress","startIcon","startIconProp","style","styleProp","variant","otherProps","styles","fontColor","palette","tertiary","main","primary","variantStyleMap","outlined","backgroundColor","paper","default","borderColor","border","borderWidth","filled","grey","bold","chipStyle","css","fontStyle","createFontStyle","selector","typo","subtitle2","color","textMarginSize","textMarginStyle","marginLeft","marginRight","undefined","textStyle","textAlign","iconProps","width","fill","cloneElementSafely"],"sources":["Chip.tsx"],"sourcesContent":["import React from 'react';\nimport { Text } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { createFontStyle, css, useTheme } from '../styles';\nimport { cloneElementSafely } from '../utils';\nimport ButtonBase from '../ButtonBase';\nimport type ChipProps from './ChipProps';\n\ntype ChipStyles = NamedStylesStringUnion<'root'>;\n\nconst ICON_SIZE = 16;\n\nconst useStyles: UseStyles<ChipStyles> = function (): ChipStyles {\n const theme = useTheme();\n\n return {\n root: {\n alignItems: 'center',\n borderRadius: 20,\n flexDirection: 'row',\n height: 32,\n justifyContent: 'center',\n paddingLeft: theme.spacing(2),\n paddingRight: theme.spacing(2),\n },\n };\n};\n\nexport default function Chip(props: ChipProps) {\n const {\n children,\n endIcon: endIconProp,\n numberOfLines,\n onPress,\n startIcon: startIconProp,\n style: styleProp,\n variant = 'outlined',\n ...otherProps\n } = props;\n\n const theme = useTheme();\n const styles = useStyles();\n\n const fontColor = variant === 'outlined'\n ? theme.palette.tertiary.main\n : theme.palette.primary.main;\n\n const variantStyleMap = {\n outlined: {\n backgroundColor: theme.palette.paper.default,\n borderColor: theme.palette.border,\n borderWidth: 2,\n },\n filled: {\n backgroundColor: theme.palette.paper.grey,\n },\n bold: {\n backgroundColor: theme.palette.paper.grey,\n borderColor: theme.palette.primary.main,\n borderWidth: 2,\n },\n };\n\n const chipStyle = css([\n styles.root,\n variantStyleMap[variant],\n styleProp,\n ]);\n\n const fontStyle = createFontStyle(theme, {\n selector: (typo) => typo.subtitle2,\n color: fontColor,\n });\n\n const textMarginSize = theme.spacing(1);\n const textMarginStyle = startIconProp\n ? { marginLeft: textMarginSize }\n : endIconProp\n ? { marginRight: textMarginSize }\n : undefined;\n\n const textStyle = css([\n fontStyle,\n textMarginStyle,\n { textAlign: 'center' },\n ]);\n\n const iconProps = {\n width: ICON_SIZE,\n height: ICON_SIZE,\n fill: fontColor,\n };\n\n const startIcon = cloneElementSafely(startIconProp, iconProps);\n const endIcon = cloneElementSafely(endIconProp, iconProps);\n\n return (\n <ButtonBase\n onPress={onPress}\n style={chipStyle}\n {...otherProps}\n >\n {startIcon}\n\n <Text\n children={children}\n numberOfLines={numberOfLines}\n style={textStyle}\n />\n\n {endIcon}\n </ButtonBase>\n );\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAKA,MAAMA,SAAS,GAAG,EAAlB;;AAEA,MAAMC,SAAgC,GAAG,YAAwB;EAC7D,MAAMC,KAAK,GAAG,IAAAC,gBAAA,GAAd;EAEA,OAAO;IACHC,IAAI,E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OverridableComponentProps } from '../types';\nimport type { ButtonBaseProps } from '../ButtonBase';\n\nexport type ChipVariant = 'outlined' | 'filled' | 'bold';\n\nexport default interface ChipProps extends OverridableComponentProps<ButtonBaseProps, {\n /**\n * Element placed after the children.\n */\n endIcon?: React.ReactElement;\n\n /**\n * The content of the component.\n */\n children: string;\n\n /**\n * Element placed before the children.\n */\n startIcon?: React.ReactElement;\n\n /**\n * The variant to use.\n * @default 'outlined'\n */\n variant?: ChipVariant;\n}> {}"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["ChipProps.ts"],"sourcesContent":["import React from 'react';\nimport { OverridableComponentProps } from '../types';\nimport type { ButtonBaseProps } from '../ButtonBase';\n\nexport type ChipVariant = 'outlined' | 'filled' | 'bold';\n\nexport default interface ChipProps extends OverridableComponentProps<ButtonBaseProps, {\n /**\n * Element placed after the children.\n */\n endIcon?: React.ReactElement;\n\n /**\n * The content of the component.\n */\n children: string;\n\n /**\n * Number of lines of children.\n */\n numberOfLines?: number;\n\n /**\n * Element placed before the children.\n */\n startIcon?: React.ReactElement;\n\n /**\n * The variant to use.\n * @default 'outlined'\n */\n variant?: ChipVariant;\n}> {}"],"mappings":""}
|
|
@@ -18,12 +18,13 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
18
18
|
function ScrollableTabsView(props) {
|
|
19
19
|
const {
|
|
20
20
|
coordinates,
|
|
21
|
+
initialIndex,
|
|
21
22
|
...scrollViewProps
|
|
22
23
|
} = props;
|
|
23
24
|
const {
|
|
24
25
|
scrollViewRef,
|
|
25
26
|
onLayout
|
|
26
|
-
} = (0, _useScrollViewReaction.default)(coordinates);
|
|
27
|
+
} = (0, _useScrollViewReaction.default)(initialIndex, coordinates);
|
|
27
28
|
return /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, _extends({
|
|
28
29
|
ref: scrollViewRef,
|
|
29
30
|
onLayout: onLayout
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ScrollableTabsView","props","coordinates","scrollViewProps","scrollViewRef","onLayout","useScrollViewReaction"],"sources":["ScrollableTabsView.tsx"],"sourcesContent":["import React from 'react';\nimport type { ScrollViewProps } from 'react-native';\nimport { ScrollView } from 'react-native';\nimport TabCoordinate from './TabCoordinate';\nimport useScrollViewReaction from './useScrollViewReaction';\n\nexport interface ScrollableTabsViewProps extends ScrollViewProps {\n coordinates: TabCoordinate[];\n}\n\nexport default function ScrollableTabsView(props: ScrollableTabsViewProps) {\n const {\n coordinates,\n ...scrollViewProps\n } = props;\n\n const { scrollViewRef, onLayout } = useScrollViewReaction(coordinates);\n\n return (\n <ScrollView\n ref={scrollViewRef}\n onLayout={onLayout}\n {...scrollViewProps}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;;;;;
|
|
1
|
+
{"version":3,"names":["ScrollableTabsView","props","coordinates","initialIndex","scrollViewProps","scrollViewRef","onLayout","useScrollViewReaction"],"sources":["ScrollableTabsView.tsx"],"sourcesContent":["import React from 'react';\nimport type { ScrollViewProps } from 'react-native';\nimport { ScrollView } from 'react-native';\nimport TabCoordinate from './TabCoordinate';\nimport useScrollViewReaction from './useScrollViewReaction';\n\nexport interface ScrollableTabsViewProps extends ScrollViewProps {\n initialIndex: number;\n coordinates: TabCoordinate[];\n}\n\nexport default function ScrollableTabsView(props: ScrollableTabsViewProps) {\n const {\n coordinates,\n initialIndex,\n ...scrollViewProps\n } = props;\n\n const { scrollViewRef, onLayout } = useScrollViewReaction(initialIndex, coordinates);\n\n return (\n <ScrollView\n ref={scrollViewRef}\n onLayout={onLayout}\n {...scrollViewProps}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;;;;;AAOe,SAASA,kBAAT,CAA4BC,KAA5B,EAA4D;EACvE,MAAM;IACFC,WADE;IAEFC,YAFE;IAGF,GAAGC;EAHD,IAIFH,KAJJ;EAMA,MAAM;IAAEI,aAAF;IAAiBC;EAAjB,IAA8B,IAAAC,8BAAA,EAAsBJ,YAAtB,EAAoCD,WAApC,CAApC;EAEA,oBACI,6BAAC,uBAAD;IACI,GAAG,EAAEG,aADT;IAEI,QAAQ,EAAEC;EAFd,GAGQF,eAHR,EADJ;AAOH;;AAAA"}
|
|
@@ -66,6 +66,7 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(function Tabs(props, ref) {
|
|
|
66
66
|
initialValue: initialIndex
|
|
67
67
|
});
|
|
68
68
|
const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;
|
|
69
|
+
const realInitialIndex = sharedIndex.initialValue;
|
|
69
70
|
|
|
70
71
|
const setTab = newIndex => {
|
|
71
72
|
sharedIndex.animatedValue.setValue(newIndex);
|
|
@@ -119,14 +120,14 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(function Tabs(props, ref) {
|
|
|
119
120
|
return /*#__PURE__*/_react.default.createElement(_IndexAwareTab.default, {
|
|
120
121
|
children: tabElement,
|
|
121
122
|
index: index,
|
|
122
|
-
initialIndex:
|
|
123
|
+
initialIndex: realInitialIndex
|
|
123
124
|
});
|
|
124
125
|
});
|
|
125
126
|
|
|
126
127
|
const tabIndicator = canRenderIndicator ? /*#__PURE__*/_react.default.createElement(_TabIndicator.default, {
|
|
127
128
|
coordinates: coordinates,
|
|
128
129
|
disabled: disableIndicator,
|
|
129
|
-
initialIndex:
|
|
130
|
+
initialIndex: realInitialIndex,
|
|
130
131
|
scrollable: scrollable
|
|
131
132
|
}) : null;
|
|
132
133
|
return /*#__PURE__*/_react.default.createElement(_InternalContext.default.Provider, {
|
|
@@ -142,6 +143,7 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(function Tabs(props, ref) {
|
|
|
142
143
|
coordinates: coordinates,
|
|
143
144
|
directionalLockEnabled: true,
|
|
144
145
|
horizontal: true,
|
|
146
|
+
initialIndex: realInitialIndex,
|
|
145
147
|
scrollsToTop: false,
|
|
146
148
|
showsHorizontalScrollIndicator: false,
|
|
147
149
|
showsVerticalScrollIndicator: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useStyles","theme","useTheme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","forwardRef","props","ref","children","initialIndex","disableIndicator","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","fallbackSharedIndex","useSyncAnimatedValue","initialValue","sharedIndex","setTab","newIndex","animatedValue","setValue","useImperativeHandle","styles","coordinates","updateCoordinate","useTabCoordinates","canRenderIndicator","isEveryTabCoordinatesDefined","indexStore","useIndexStore","useEffect","subscribe","tabElements","React","Children","map","child","index","onLayout","event","x","width","nativeEvent","layout","onMouseDown","e","preventDefault","onPress","tabElement","cloneElement","enableIndicator","undefined","tabIndicator","css"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useEffect, useImperativeHandle } from 'react';\nimport type { GestureResponderEvent, LayoutChangeEvent } from 'react-native';\nimport { View } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport { useSyncAnimatedValue } from '../hooks';\nimport type TabsProps from './TabsProps';\nimport type { TabsInstance } from './types';\nimport TabIndicator from './TabIndicator';\nimport ScrollableTabsView from './ScrollableTabsView';\nimport IndexAwareTab from './IndexAwareTab';\nimport useTabCoordinates from './useTabCoordinates';\nimport useIndexStore from './useIndexStore';\nimport InternalContext from './InternalContext';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\ntype TabsStyleKeys =\n | 'root'\n | 'fixedRoot'\n | 'fixedTab'\n | 'scrollableContainer';\n\ntype TabsStyles = NamedStylesStringUnion<TabsStyleKeys>;\n\nconst useStyles: UseStyles<TabsStyles> = function (): TabsStyles {\n const theme = useTheme();\n\n return {\n root: {},\n fixedRoot: {\n flexDirection: 'row',\n },\n fixedTab: {\n flex: 1,\n },\n scrollableContainer: {\n paddingHorizontal: theme.spacing(1),\n },\n };\n};\n\nconst Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {\n const {\n children,\n initialIndex = 0,\n disableIndicator = false,\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });\n
|
|
1
|
+
{"version":3,"names":["useStyles","theme","useTheme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","forwardRef","props","ref","children","initialIndex","disableIndicator","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","fallbackSharedIndex","useSyncAnimatedValue","initialValue","sharedIndex","realInitialIndex","setTab","newIndex","animatedValue","setValue","useImperativeHandle","styles","coordinates","updateCoordinate","useTabCoordinates","canRenderIndicator","isEveryTabCoordinatesDefined","indexStore","useIndexStore","useEffect","subscribe","tabElements","React","Children","map","child","index","onLayout","event","x","width","nativeEvent","layout","onMouseDown","e","preventDefault","onPress","tabElement","cloneElement","enableIndicator","undefined","tabIndicator","css"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useEffect, useImperativeHandle } from 'react';\nimport type { GestureResponderEvent, LayoutChangeEvent } from 'react-native';\nimport { View } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport { useSyncAnimatedValue } from '../hooks';\nimport type TabsProps from './TabsProps';\nimport type { TabsInstance } from './types';\nimport TabIndicator from './TabIndicator';\nimport ScrollableTabsView from './ScrollableTabsView';\nimport IndexAwareTab from './IndexAwareTab';\nimport useTabCoordinates from './useTabCoordinates';\nimport useIndexStore from './useIndexStore';\nimport InternalContext from './InternalContext';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\ntype TabsStyleKeys =\n | 'root'\n | 'fixedRoot'\n | 'fixedTab'\n | 'scrollableContainer';\n\ntype TabsStyles = NamedStylesStringUnion<TabsStyleKeys>;\n\nconst useStyles: UseStyles<TabsStyles> = function (): TabsStyles {\n const theme = useTheme();\n\n return {\n root: {},\n fixedRoot: {\n flexDirection: 'row',\n },\n fixedTab: {\n flex: 1,\n },\n scrollableContainer: {\n paddingHorizontal: theme.spacing(1),\n },\n };\n};\n\nconst Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {\n const {\n children,\n initialIndex = 0,\n disableIndicator = false,\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n const realInitialIndex = sharedIndex.initialValue;\n\n const setTab = (newIndex: number) => {\n sharedIndex.animatedValue.setValue(newIndex);\n };\n\n useImperativeHandle(\n ref,\n () => ({\n setTab,\n }),\n [sharedIndex],\n );\n\n const styles = useStyles();\n\n const [coordinates, updateCoordinate] = useTabCoordinates(children);\n\n const canRenderIndicator = isEveryTabCoordinatesDefined(coordinates, children);\n\n const indexStore = useIndexStore(sharedIndex);\n\n useEffect(() => {\n return indexStore.subscribe(newIndex => {\n onChange?.(newIndex);\n });\n }, [indexStore, onChange]);\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 // @ts-ignore\n child.props.onPress?.();\n };\n\n // @ts-ignore\n const tabElement = cloneElement(child, {\n enableIndicator: !disableIndicator && !canRenderIndicator,\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 initialIndex={realInitialIndex}\n />\n );\n });\n\n const tabIndicator = canRenderIndicator ? (\n <TabIndicator\n coordinates={coordinates}\n disabled={disableIndicator}\n initialIndex={realInitialIndex}\n scrollable={scrollable}\n />\n ) : null;\n\n return (\n <InternalContext.Provider value={{ indexStore }}>\n <View\n style={css([\n styles.root,\n scrollable ? undefined : styles.fixedRoot,\n style,\n ])}\n >\n {scrollable ? (\n <ScrollableTabsView\n automaticallyAdjustContentInsets={false}\n bounces={false}\n contentContainerStyle={styles.scrollableContainer}\n coordinates={coordinates}\n directionalLockEnabled={true}\n horizontal={true}\n initialIndex={realInitialIndex}\n scrollsToTop={false}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={false}\n keyboardDismissMode={keyboardDismissMode}\n keyboardShouldPersistTaps={keyboardShouldPersistTaps}\n >\n {tabElements}\n {tabIndicator}\n </ScrollableTabsView>\n ) : (\n <React.Fragment>\n {tabElements}\n {tabIndicator}\n </React.Fragment>\n )}\n </View>\n </InternalContext.Provider>\n );\n});\n\nexport default Tabs;\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAUA,MAAMA,SAAgC,GAAG,YAAwB;EAC7D,MAAMC,KAAK,GAAG,IAAAC,gBAAA,GAAd;EAEA,OAAO;IACHC,IAAI,EAAE,EADH;IAEHC,SAAS,EAAE;MACPC,aAAa,EAAE;IADR,CAFR;IAKHC,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA,CALP;IAQHC,mBAAmB,EAAE;MACjBC,iBAAiB,EAAER,KAAK,CAACS,OAAN,CAAc,CAAd;IADF;EARlB,CAAP;AAYH,CAfD;;AAiBA,MAAMC,IAAI,gBAAG,IAAAC,iBAAA,EAAoC,SAASD,IAAT,CAAcE,KAAd,EAAqBC,GAArB,EAA0B;EACvE,MAAM;IACFC,QADE;IAEFC,YAAY,GAAG,CA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AM,CAAC/B,SAFzB,EAGPkB,KAHO,CAAJ;EADX,GAOKD,UAAU,gBACP,6BAAC,2BAAD;IACI,gCAAgC,EAAE,KADtC;IAEI,OAAO,EAAE,KAFb;IAGI,qBAAqB,EAAEc,MAAM,CAAC3B,mBAHlC;IAII,WAAW,EAAE4B,WAJjB;IAKI,sBAAsB,EAAE,IAL5B;IAMI,UAAU,EAAE,IANhB;IAOI,YAAY,EAAEP,gBAPlB;IAQI,YAAY,EAAE,KARlB;IASI,8BAA8B,EAAE,KATpC;IAUI,4BAA4B,EAAE,KAVlC;IAWI,mBAAmB,EAAEX,mBAXzB;IAYI,yBAAyB,EAAEC;EAZ/B,GAcK0B,WAdL,EAeKoB,YAfL,CADO,gBAmBP,6BAAC,cAAD,CAAO,QAAP,QACKpB,WADL,EAEKoB,YAFL,CA1BR,CADJ,CADJ;AAoCH,CAhIY,CAAb;eAkIetD,I"}
|
|
@@ -11,7 +11,7 @@ var _InternalContext = _interopRequireDefault(require("./InternalContext"));
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
function useScrollViewReaction(coordinates) {
|
|
14
|
+
function useScrollViewReaction(initialIndex, coordinates) {
|
|
15
15
|
const scrollViewRef = (0, _react.useRef)(null);
|
|
16
16
|
const lastScrolledXRef = (0, _react.useRef)(NaN);
|
|
17
17
|
const {
|
|
@@ -34,23 +34,31 @@ function useScrollViewReaction(coordinates) {
|
|
|
34
34
|
const onLayout = (0, _react.useCallback)(() => {
|
|
35
35
|
scrollToX(lastScrolledXRef.current);
|
|
36
36
|
}, []);
|
|
37
|
-
(0, _react.
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
const prevCoordinate = coordinates[prevIndex];
|
|
37
|
+
const computeNextScrollX = (0, _react.useCallback)(index => {
|
|
38
|
+
const prevIndex = index - 1;
|
|
39
|
+
const prevCoordinate = coordinates[prevIndex];
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
if (prevCoordinate) {
|
|
42
|
+
const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;
|
|
43
|
+
return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);
|
|
44
|
+
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
return 0;
|
|
47
|
+
}, [coordinates]);
|
|
48
|
+
(0, _react.useEffect)(() => {
|
|
49
|
+
if (Number.isNaN(lastScrolledXRef.current)) {
|
|
50
|
+
const x = computeNextScrollX(initialIndex);
|
|
49
51
|
|
|
52
|
+
if (x > 0) {
|
|
53
|
+
scrollToX(x);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, [initialIndex, computeNextScrollX]);
|
|
57
|
+
(0, _react.useEffect)(() => {
|
|
50
58
|
return indexStore.subscribe(currentIndex => {
|
|
51
59
|
scrollToX(computeNextScrollX(currentIndex));
|
|
52
60
|
});
|
|
53
|
-
}, [indexStore,
|
|
61
|
+
}, [indexStore, computeNextScrollX]);
|
|
54
62
|
return {
|
|
55
63
|
scrollViewRef,
|
|
56
64
|
onLayout
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useScrollViewReaction","coordinates","scrollViewRef","useRef","lastScrolledXRef","NaN","indexStore","useContext","InternalContext","scrollToX","x","Number","isFinite","current","scrollTo","y","animated","onLayout","useCallback","
|
|
1
|
+
{"version":3,"names":["useScrollViewReaction","initialIndex","coordinates","scrollViewRef","useRef","lastScrolledXRef","NaN","indexStore","useContext","InternalContext","scrollToX","x","Number","isFinite","current","scrollTo","y","animated","onLayout","useCallback","computeNextScrollX","index","prevIndex","prevCoordinate","prevTabWidth","x2","x1","Math","floor","useEffect","isNaN","subscribe","currentIndex"],"sources":["useScrollViewReaction.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useCallback, useContext, useEffect, useRef } from 'react';\nimport type { ScrollView, ViewProps } from 'react-native';\nimport type TabCoordinate from './TabCoordinate';\nimport InternalContext from './InternalContext';\n\nexport interface UseScrollViewReaction {\n scrollViewRef: MutableRefObject<ScrollView | null>;\n onLayout: ViewProps['onLayout'];\n}\n\nexport default function useScrollViewReaction(\n initialIndex: number,\n coordinates: TabCoordinate[],\n): UseScrollViewReaction {\n const scrollViewRef = useRef<ScrollView | null>(null);\n\n const lastScrolledXRef = useRef<number>(NaN);\n\n const { indexStore } = useContext(InternalContext);\n\n const scrollToX = (x: number) => {\n if (Number.isFinite(x)) {\n scrollViewRef.current?.scrollTo({ x, y: 0, animated: true });\n\n lastScrolledXRef.current = x;\n }\n };\n\n const onLayout = useCallback(() => {\n scrollToX(lastScrolledXRef.current);\n }, []);\n\n const computeNextScrollX = useCallback((index: number): number => {\n const prevIndex = index - 1;\n const prevCoordinate = coordinates[prevIndex];\n\n if (prevCoordinate) {\n const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;\n return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);\n }\n\n return 0;\n }, [coordinates]);\n\n useEffect(() => {\n if (Number.isNaN(lastScrolledXRef.current)) {\n const x = computeNextScrollX(initialIndex);\n if (x > 0) {\n scrollToX(x);\n }\n }\n }, [initialIndex, computeNextScrollX]);\n\n useEffect(() => {\n return indexStore.subscribe(currentIndex => {\n scrollToX(computeNextScrollX(currentIndex));\n });\n }, [indexStore, computeNextScrollX]);\n\n return { scrollViewRef, onLayout };\n};\n"],"mappings":";;;;;;;AACA;;AAGA;;;;AAOe,SAASA,qBAAT,CACXC,YADW,EAEXC,WAFW,EAGU;EACrB,MAAMC,aAAa,GAAG,IAAAC,aAAA,EAA0B,IAA1B,CAAtB;EAEA,MAAMC,gBAAgB,GAAG,IAAAD,aAAA,EAAeE,GAAf,CAAzB;EAEA,MAAM;IAAEC;EAAF,IAAiB,IAAAC,iBAAA,EAAWC,wBAAX,CAAvB;;EAEA,MAAMC,SAAS,GAAIC,CAAD,IAAe;IAC7B,IAAIC,MAAM,CAAC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AFM,CAAP;EAGH,CAJD,EAIG,CAACzB,UAAD,EAAaa,kBAAb,CAJH;EAMA,OAAO;IAAEjB,aAAF;IAAiBe;EAAjB,CAAP;AACH;;AAAA"}
|
|
@@ -6,7 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
class MockStore {
|
|
9
|
-
dispatch(
|
|
9
|
+
dispatch(state) {// do nothing
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getState() {
|
|
13
|
+
throw new Error('stub!');
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
removeAllListeners() {// do nothing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MockStore","dispatch","
|
|
1
|
+
{"version":3,"names":["MockStore","dispatch","state","getState","Error","removeAllListeners","subscribe","listener"],"sources":["MockStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nexport default class MockStore<S> implements MonoStore<S> {\n\n dispatch(state: S): void {\n // do nothing\n }\n\n getState(): S {\n throw new Error('stub!');\n }\n\n removeAllListeners(): void {\n // do nothing\n }\n\n subscribe(listener: (state: S) => void): StoreSubscription {\n return () => void 0;\n }\n\n};\n"],"mappings":";;;;;;;AAEe,MAAMA,SAAN,CAA2C;EAEtDC,QAAQ,CAACC,KAAD,EAAiB,CACrB;EACH;;EAEDC,QAAQ,GAAM;IACV,MAAM,IAAIC,KAAJ,CAAU,OAAV,CAAN;EACH;;EAEDC,kBAAkB,GAAS,CACvB;EACH;;EAEDC,SAAS,CAACC,QAAD,EAAkD;IACvD,OAAO,MAAM,KAAK,CAAlB;EACH;;AAhBqD;;;AAkBzD"}
|
|
@@ -12,36 +12,40 @@ function refEqual(a, b) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
class SimpleStore {
|
|
15
|
-
constructor(
|
|
16
|
-
_defineProperty(this, "
|
|
15
|
+
constructor(initialState) {
|
|
16
|
+
_defineProperty(this, "state", void 0);
|
|
17
17
|
|
|
18
18
|
_defineProperty(this, "listeners", []);
|
|
19
19
|
|
|
20
|
-
this.
|
|
20
|
+
this.state = initialState;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const index = this.listeners.indexOf(listener);
|
|
27
|
-
this.listeners.splice(index, 1);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
dispatch(data) {
|
|
32
|
-
// Do not dispatch if data ref is equal
|
|
33
|
-
if (refEqual(this.data, data)) {
|
|
23
|
+
dispatch(state) {
|
|
24
|
+
// Do not dispatch if state ref is equal
|
|
25
|
+
if (refEqual(this.state, state)) {
|
|
34
26
|
return;
|
|
35
27
|
}
|
|
36
28
|
|
|
37
|
-
this.
|
|
29
|
+
this.state = state;
|
|
38
30
|
|
|
39
31
|
for (const id in this.listeners) {
|
|
40
32
|
const listener = this.listeners[id];
|
|
41
|
-
listener === null || listener === void 0 ? void 0 : listener(
|
|
33
|
+
listener === null || listener === void 0 ? void 0 : listener(state);
|
|
42
34
|
}
|
|
43
35
|
}
|
|
44
36
|
|
|
37
|
+
getState() {
|
|
38
|
+
return this.state;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
subscribe(listener) {
|
|
42
|
+
this.listeners.push(listener);
|
|
43
|
+
return () => {
|
|
44
|
+
const index = this.listeners.indexOf(listener);
|
|
45
|
+
this.listeners.splice(index, 1);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
removeAllListeners() {
|
|
46
50
|
this.listeners.splice(0, this.listeners.length);
|
|
47
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["refEqual","a","b","SimpleStore","constructor","
|
|
1
|
+
{"version":3,"names":["refEqual","a","b","SimpleStore","constructor","initialState","state","dispatch","id","listeners","listener","getState","subscribe","push","index","indexOf","splice","removeAllListeners","length"],"sources":["SimpleStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nfunction refEqual(a: any, b: any): boolean {\n return a === b;\n}\n\nexport default class SimpleStore<S> implements MonoStore<S> {\n\n private state: S;\n\n private listeners: Array<(state: S) => void> = [];\n\n constructor(initialState: S) {\n this.state = initialState;\n }\n\n dispatch(state: S): void {\n // Do not dispatch if state ref is equal\n if (refEqual(this.state, state)) {\n return;\n }\n\n this.state = state;\n for (const id in this.listeners) {\n const listener = this.listeners[id];\n listener?.(state);\n }\n }\n\n getState(): S {\n return this.state;\n }\n\n subscribe(listener: (state: S) => void): StoreSubscription {\n this.listeners.push(listener);\n\n return () => {\n const index = this.listeners.indexOf(listener);\n this.listeners.splice(index, 1);\n };\n }\n\n removeAllListeners(): void {\n this.listeners.splice(0, this.listeners.length);\n }\n\n};\n"],"mappings":";;;;;;;;;AAEA,SAASA,QAAT,CAAkBC,CAAlB,EAA0BC,CAA1B,EAA2C;EACvC,OAAOD,CAAC,KAAKC,CAAb;AACH;;AAEc,MAAMC,WAAN,CAA6C;EAMxDC,WAAW,CAACC,YAAD,EAAkB;IAAA;;IAAA,mCAFkB,EAElB;;IACzB,KAAKC,KAAL,GAAaD,YAAb;EACH;;EAEDE,QAAQ,CAACD,KAAD,EAAiB;IACrB;IACA,IAAIN,QAAQ,CAAC,KAAKM,KAAN,EAAaA,KAAb,CAAZ,EAAiC;MAC7B;IACH;;IAED,KAAKA,KAAL,GAAaA,KAAb;;IACA,KAAK,MAAME,EAAX,IAAiB,KAAKC,SAAtB,EAAiC;MAC7B,MAAMC,QAAQ,GAAG,KAAKD,SAAL,CAAeD,EAAf,CAAjB;MACAE,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAGJ,KAAH,CAAR;IACH;EACJ;;EAEDK,QAAQ,GAAM;IACV,OAAO,KAAKL,KAAZ;EACH;;EAEDM,SAAS,CAACF,QAAD,EAAkD;IACvD,KAAKD,SAAL,CAAeI,IAAf,CAAoBH,QAApB;IAEA,OAAO,MAAM;MACT,MAAMI,KAAK,GAAG,KAAKL,SAAL,CAAeM,OAAf,CAAuBL,QAAvB,CAAd;MACA,KAAKD,SAAL,CAAeO,MAAf,CAAsBF,KAAtB,EAA6B,CAA7B;IACH,CAHD;EAIH;;EAEDG,kBAAkB,GAAS;IACvB,KAAKR,SAAL,CAAeO,MAAf,CAAsB,CAAtB,EAAyB,KAAKP,SAAL,CAAeS,MAAxC;EACH;;AAtCuD;;;AAwC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface StoreSubscription {\n (): void;\n}\n\nexport interface MonoStore<
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface StoreSubscription {\n (): void;\n}\n\nexport interface MonoStore<S> {\n dispatch: (state: S) => void;\n getState: () => S;\n subscribe: (listener: (state: S) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n"],"mappings":""}
|
|
@@ -26,6 +26,7 @@ export default function Chip(props) {
|
|
|
26
26
|
const {
|
|
27
27
|
children,
|
|
28
28
|
endIcon: endIconProp,
|
|
29
|
+
numberOfLines,
|
|
29
30
|
onPress,
|
|
30
31
|
startIcon: startIconProp,
|
|
31
32
|
style: styleProp,
|
|
@@ -76,6 +77,7 @@ export default function Chip(props) {
|
|
|
76
77
|
style: chipStyle
|
|
77
78
|
}, otherProps), startIcon, /*#__PURE__*/React.createElement(Text, {
|
|
78
79
|
children: children,
|
|
80
|
+
numberOfLines: numberOfLines,
|
|
79
81
|
style: textStyle
|
|
80
82
|
}), endIcon);
|
|
81
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Text","createFontStyle","css","useTheme","cloneElementSafely","ButtonBase","ICON_SIZE","useStyles","theme","root","alignItems","borderRadius","flexDirection","height","justifyContent","paddingLeft","spacing","paddingRight","Chip","props","children","endIcon","endIconProp","onPress","startIcon","startIconProp","style","styleProp","variant","otherProps","styles","fontColor","palette","tertiary","main","primary","variantStyleMap","outlined","backgroundColor","paper","default","borderColor","border","borderWidth","filled","grey","bold","chipStyle","fontStyle","selector","typo","subtitle2","color","textMarginSize","textMarginStyle","marginLeft","marginRight","undefined","textStyle","textAlign","iconProps","width","fill"],"sources":["Chip.tsx"],"sourcesContent":["import React from 'react';\nimport { Text } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { createFontStyle, css, useTheme } from '../styles';\nimport { cloneElementSafely } from '../utils';\nimport ButtonBase from '../ButtonBase';\nimport type ChipProps from './ChipProps';\n\ntype ChipStyles = NamedStylesStringUnion<'root'>;\n\nconst ICON_SIZE = 16;\n\nconst useStyles: UseStyles<ChipStyles> = function (): ChipStyles {\n const theme = useTheme();\n\n return {\n root: {\n alignItems: 'center',\n borderRadius: 20,\n flexDirection: 'row',\n height: 32,\n justifyContent: 'center',\n paddingLeft: theme.spacing(2),\n paddingRight: theme.spacing(2),\n },\n };\n};\n\nexport default function Chip(props: ChipProps) {\n const {\n children,\n endIcon: endIconProp,\n onPress,\n startIcon: startIconProp,\n style: styleProp,\n variant = 'outlined',\n ...otherProps\n } = props;\n\n const theme = useTheme();\n const styles = useStyles();\n\n const fontColor = variant === 'outlined'\n ? theme.palette.tertiary.main\n : theme.palette.primary.main;\n\n const variantStyleMap = {\n outlined: {\n backgroundColor: theme.palette.paper.default,\n borderColor: theme.palette.border,\n borderWidth: 2,\n },\n filled: {\n backgroundColor: theme.palette.paper.grey,\n },\n bold: {\n backgroundColor: theme.palette.paper.grey,\n borderColor: theme.palette.primary.main,\n borderWidth: 2,\n },\n };\n\n const chipStyle = css([\n styles.root,\n variantStyleMap[variant],\n styleProp,\n ]);\n\n const fontStyle = createFontStyle(theme, {\n selector: (typo) => typo.subtitle2,\n color: fontColor,\n });\n\n const textMarginSize = theme.spacing(1);\n const textMarginStyle = startIconProp\n ? { marginLeft: textMarginSize }\n : endIconProp\n ? { marginRight: textMarginSize }\n : undefined;\n\n const textStyle = css([\n fontStyle,\n textMarginStyle,\n { textAlign: 'center' },\n ]);\n\n const iconProps = {\n width: ICON_SIZE,\n height: ICON_SIZE,\n fill: fontColor,\n };\n\n const startIcon = cloneElementSafely(startIconProp, iconProps);\n const endIcon = cloneElementSafely(endIconProp, iconProps);\n\n return (\n <ButtonBase\n onPress={onPress}\n style={chipStyle}\n {...otherProps}\n >\n {startIcon}\n\n <Text\n children={children}\n style={textStyle}\n />\n\n {endIcon}\n </ButtonBase>\n );\n}\n"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,IAAT,QAAqB,cAArB;AAEA,SAASC,eAAT,EAA0BC,GAA1B,EAA+BC,QAA/B,QAA+C,WAA/C;AACA,SAASC,kBAAT,QAAmC,UAAnC;AACA,OAAOC,UAAP,MAAuB,eAAvB;AAKA,MAAMC,SAAS,GAAG,EAAlB;;AAEA,MAAMC,SAAgC,GAAG,YAAwB;EAC7D,MAAMC,KAAK,GAAGL,QAAQ,EAAtB;EAEA,OAAO;IACHM,IAAI,EAAE;MACFC,UAAU,EAAE,QADV;MAEFC,YAAY,EAAE,EAFZ;MAGFC,aAAa,EAAE,KAHb;MAIFC,MAAM,EAAE,EAJN;MAKFC,cAAc,EAAE,QALd;MAMFC,WAAW,EAAEP,KAAK,CAACQ,OAAN,CAAc,CAAd,CANX;MAOFC,YAAY,EAAET,KAAK,CAACQ,OAAN,CAAc,CAAd;IAPZ;EADH,CAAP;AAWH,CAdD;;AAgBA,eAAe,SAASE,IAAT,CAAcC,KAAd,EAAgC;EAC3C,MAAM;IACFC,QADE;IAEFC,OAAO,EAAEC,WAFP;IAGFC,
|
|
1
|
+
{"version":3,"names":["React","Text","createFontStyle","css","useTheme","cloneElementSafely","ButtonBase","ICON_SIZE","useStyles","theme","root","alignItems","borderRadius","flexDirection","height","justifyContent","paddingLeft","spacing","paddingRight","Chip","props","children","endIcon","endIconProp","numberOfLines","onPress","startIcon","startIconProp","style","styleProp","variant","otherProps","styles","fontColor","palette","tertiary","main","primary","variantStyleMap","outlined","backgroundColor","paper","default","borderColor","border","borderWidth","filled","grey","bold","chipStyle","fontStyle","selector","typo","subtitle2","color","textMarginSize","textMarginStyle","marginLeft","marginRight","undefined","textStyle","textAlign","iconProps","width","fill"],"sources":["Chip.tsx"],"sourcesContent":["import React from 'react';\nimport { Text } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { createFontStyle, css, useTheme } from '../styles';\nimport { cloneElementSafely } from '../utils';\nimport ButtonBase from '../ButtonBase';\nimport type ChipProps from './ChipProps';\n\ntype ChipStyles = NamedStylesStringUnion<'root'>;\n\nconst ICON_SIZE = 16;\n\nconst useStyles: UseStyles<ChipStyles> = function (): ChipStyles {\n const theme = useTheme();\n\n return {\n root: {\n alignItems: 'center',\n borderRadius: 20,\n flexDirection: 'row',\n height: 32,\n justifyContent: 'center',\n paddingLeft: theme.spacing(2),\n paddingRight: theme.spacing(2),\n },\n };\n};\n\nexport default function Chip(props: ChipProps) {\n const {\n children,\n endIcon: endIconProp,\n numberOfLines,\n onPress,\n startIcon: startIconProp,\n style: styleProp,\n variant = 'outlined',\n ...otherProps\n } = props;\n\n const theme = useTheme();\n const styles = useStyles();\n\n const fontColor = variant === 'outlined'\n ? theme.palette.tertiary.main\n : theme.palette.primary.main;\n\n const variantStyleMap = {\n outlined: {\n backgroundColor: theme.palette.paper.default,\n borderColor: theme.palette.border,\n borderWidth: 2,\n },\n filled: {\n backgroundColor: theme.palette.paper.grey,\n },\n bold: {\n backgroundColor: theme.palette.paper.grey,\n borderColor: theme.palette.primary.main,\n borderWidth: 2,\n },\n };\n\n const chipStyle = css([\n styles.root,\n variantStyleMap[variant],\n styleProp,\n ]);\n\n const fontStyle = createFontStyle(theme, {\n selector: (typo) => typo.subtitle2,\n color: fontColor,\n });\n\n const textMarginSize = theme.spacing(1);\n const textMarginStyle = startIconProp\n ? { marginLeft: textMarginSize }\n : endIconProp\n ? { marginRight: textMarginSize }\n : undefined;\n\n const textStyle = css([\n fontStyle,\n textMarginStyle,\n { textAlign: 'center' },\n ]);\n\n const iconProps = {\n width: ICON_SIZE,\n height: ICON_SIZE,\n fill: fontColor,\n };\n\n const startIcon = cloneElementSafely(startIconProp, iconProps);\n const endIcon = cloneElementSafely(endIconProp, iconProps);\n\n return (\n <ButtonBase\n onPress={onPress}\n style={chipStyle}\n {...otherProps}\n >\n {startIcon}\n\n <Text\n children={children}\n numberOfLines={numberOfLines}\n style={textStyle}\n />\n\n {endIcon}\n </ButtonBase>\n );\n}\n"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,IAAT,QAAqB,cAArB;AAEA,SAASC,eAAT,EAA0BC,GAA1B,EAA+BC,QAA/B,QAA+C,WAA/C;AACA,SAASC,kBAAT,QAAmC,UAAnC;AACA,OAAOC,UAAP,MAAuB,eAAvB;AAKA,MAAMC,SAAS,GAAG,EAAlB;;AAEA,MAAMC,SAAgC,GAAG,YAAwB;EAC7D,MAAMC,KAAK,GAAGL,QAAQ,EAAtB;EAEA,OAAO;IACHM,IAAI,EAAE;MACFC,UAAU,EAAE,QADV;MAEFC,YAAY,EAAE,EAFZ;MAGFC,aAAa,EAAE,KAHb;MAIFC,MAAM,EAAE,EAJN;MAKFC,cAAc,EAAE,QALd;MAMFC,WAAW,EAAEP,KAAK,CAACQ,OAAN,CAAc,CAAd,CANX;MAOFC,YAAY,EAAET,KAAK,CAACQ,OAAN,CAAc,CAAd;IAPZ;EADH,CAAP;AAWH,CAdD;;AAgBA,eAAe,SAASE,IAAT,CAAcC,KAAd,EAAgC;EAC3C,MAAM;IACFC,QADE;IAEFC,OAAO,EAAEC,WAFP;IAGFC,aAHE;IAIFC,OAJE;IAKFC,SAAS,EAAEC,aALT;IAMFC,KAAK,EAAEC,SANL;IAOFC,OAAO,GAAG,UAPR;IAQF,GAAGC;EARD,IASFX,KATJ;EAWA,MAAMX,KAAK,GAAGL,QAAQ,EAAtB;EACA,MAAM4B,MAAM,GAAGxB,SA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AAb,CAHkB,CAAD,CAArB;EAMA,MAAMC,SAAS,GAAG;IACdC,KAAK,EAAExD,SADO;IAEdO,MAAM,EAAEP,SAFM;IAGdyD,IAAI,EAAE/B;EAHQ,CAAlB;EAMA,MAAMP,SAAS,GAAGrB,kBAAkB,CAACsB,aAAD,EAAgBmC,SAAhB,CAApC;EACA,MAAMxC,OAAO,GAAGjB,kBAAkB,CAACkB,WAAD,EAAcuC,SAAd,CAAlC;EAEA,oBACI,oBAAC,UAAD;IACI,OAAO,EAAErC,OADb;IAEI,KAAK,EAAEwB;EAFX,GAGQlB,UAHR,GAKKL,SALL,eAOI,oBAAC,IAAD;IACI,QAAQ,EAAEL,QADd;IAEI,aAAa,EAAEG,aAFnB;IAGI,KAAK,EAAEoC;EAHX,EAPJ,EAaKtC,OAbL,CADJ;AAiBH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["ChipProps.ts"],"sourcesContent":["import React from 'react';\nimport { OverridableComponentProps } from '../types';\nimport type { ButtonBaseProps } from '../ButtonBase';\n\nexport type ChipVariant = 'outlined' | 'filled' | 'bold';\n\nexport default interface ChipProps extends OverridableComponentProps<ButtonBaseProps, {\n /**\n * Element placed after the children.\n */\n endIcon?: React.ReactElement;\n\n /**\n * The content of the component.\n */\n children: string;\n\n /**\n * Element placed before the children.\n */\n startIcon?: React.ReactElement;\n\n /**\n * The variant to use.\n * @default 'outlined'\n */\n variant?: ChipVariant;\n}> {}"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["ChipProps.ts"],"sourcesContent":["import React from 'react';\nimport { OverridableComponentProps } from '../types';\nimport type { ButtonBaseProps } from '../ButtonBase';\n\nexport type ChipVariant = 'outlined' | 'filled' | 'bold';\n\nexport default interface ChipProps extends OverridableComponentProps<ButtonBaseProps, {\n /**\n * Element placed after the children.\n */\n endIcon?: React.ReactElement;\n\n /**\n * The content of the component.\n */\n children: string;\n\n /**\n * Number of lines of children.\n */\n numberOfLines?: number;\n\n /**\n * Element placed before the children.\n */\n startIcon?: React.ReactElement;\n\n /**\n * The variant to use.\n * @default 'outlined'\n */\n variant?: ChipVariant;\n}> {}"],"mappings":""}
|
|
@@ -6,12 +6,13 @@ import useScrollViewReaction from './useScrollViewReaction';
|
|
|
6
6
|
export default function ScrollableTabsView(props) {
|
|
7
7
|
const {
|
|
8
8
|
coordinates,
|
|
9
|
+
initialIndex,
|
|
9
10
|
...scrollViewProps
|
|
10
11
|
} = props;
|
|
11
12
|
const {
|
|
12
13
|
scrollViewRef,
|
|
13
14
|
onLayout
|
|
14
|
-
} = useScrollViewReaction(coordinates);
|
|
15
|
+
} = useScrollViewReaction(initialIndex, coordinates);
|
|
15
16
|
return /*#__PURE__*/React.createElement(ScrollView, _extends({
|
|
16
17
|
ref: scrollViewRef,
|
|
17
18
|
onLayout: onLayout
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","ScrollView","useScrollViewReaction","ScrollableTabsView","props","coordinates","scrollViewProps","scrollViewRef","onLayout"],"sources":["ScrollableTabsView.tsx"],"sourcesContent":["import React from 'react';\nimport type { ScrollViewProps } from 'react-native';\nimport { ScrollView } from 'react-native';\nimport TabCoordinate from './TabCoordinate';\nimport useScrollViewReaction from './useScrollViewReaction';\n\nexport interface ScrollableTabsViewProps extends ScrollViewProps {\n coordinates: TabCoordinate[];\n}\n\nexport default function ScrollableTabsView(props: ScrollableTabsViewProps) {\n const {\n coordinates,\n ...scrollViewProps\n } = props;\n\n const { scrollViewRef, onLayout } = useScrollViewReaction(coordinates);\n\n return (\n <ScrollView\n ref={scrollViewRef}\n onLayout={onLayout}\n {...scrollViewProps}\n />\n );\n};\n"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,UAAT,QAA2B,cAA3B;AAEA,OAAOC,qBAAP,MAAkC,yBAAlC;
|
|
1
|
+
{"version":3,"names":["React","ScrollView","useScrollViewReaction","ScrollableTabsView","props","coordinates","initialIndex","scrollViewProps","scrollViewRef","onLayout"],"sources":["ScrollableTabsView.tsx"],"sourcesContent":["import React from 'react';\nimport type { ScrollViewProps } from 'react-native';\nimport { ScrollView } from 'react-native';\nimport TabCoordinate from './TabCoordinate';\nimport useScrollViewReaction from './useScrollViewReaction';\n\nexport interface ScrollableTabsViewProps extends ScrollViewProps {\n initialIndex: number;\n coordinates: TabCoordinate[];\n}\n\nexport default function ScrollableTabsView(props: ScrollableTabsViewProps) {\n const {\n coordinates,\n initialIndex,\n ...scrollViewProps\n } = props;\n\n const { scrollViewRef, onLayout } = useScrollViewReaction(initialIndex, coordinates);\n\n return (\n <ScrollView\n ref={scrollViewRef}\n onLayout={onLayout}\n {...scrollViewProps}\n />\n );\n};\n"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,UAAT,QAA2B,cAA3B;AAEA,OAAOC,qBAAP,MAAkC,yBAAlC;AAOA,eAAe,SAASC,kBAAT,CAA4BC,KAA5B,EAA4D;EACvE,MAAM;IACFC,WADE;IAEFC,YAFE;IAGF,GAAGC;EAHD,IAIFH,KAJJ;EAMA,MAAM;IAAEI,aAAF;IAAiBC;EAAjB,IAA8BP,qBAAqB,CAACI,YAAD,EAAeD,WAAf,CAAzD;EAEA,oBACI,oBAAC,UAAD;IACI,GAAG,EAAEG,aADT;IAEI,QAAQ,EAAEC;EAFd,GAGQF,eAHR,EADJ;AAOH;AAAA"}
|
|
@@ -43,6 +43,7 @@ const Tabs = /*#__PURE__*/forwardRef(function Tabs(props, ref) {
|
|
|
43
43
|
initialValue: initialIndex
|
|
44
44
|
});
|
|
45
45
|
const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;
|
|
46
|
+
const realInitialIndex = sharedIndex.initialValue;
|
|
46
47
|
|
|
47
48
|
const setTab = newIndex => {
|
|
48
49
|
sharedIndex.animatedValue.setValue(newIndex);
|
|
@@ -95,13 +96,13 @@ const Tabs = /*#__PURE__*/forwardRef(function Tabs(props, ref) {
|
|
|
95
96
|
return /*#__PURE__*/React.createElement(IndexAwareTab, {
|
|
96
97
|
children: tabElement,
|
|
97
98
|
index: index,
|
|
98
|
-
initialIndex:
|
|
99
|
+
initialIndex: realInitialIndex
|
|
99
100
|
});
|
|
100
101
|
});
|
|
101
102
|
const tabIndicator = canRenderIndicator ? /*#__PURE__*/React.createElement(TabIndicator, {
|
|
102
103
|
coordinates: coordinates,
|
|
103
104
|
disabled: disableIndicator,
|
|
104
|
-
initialIndex:
|
|
105
|
+
initialIndex: realInitialIndex,
|
|
105
106
|
scrollable: scrollable
|
|
106
107
|
}) : null;
|
|
107
108
|
return /*#__PURE__*/React.createElement(InternalContext.Provider, {
|
|
@@ -117,6 +118,7 @@ const Tabs = /*#__PURE__*/forwardRef(function Tabs(props, ref) {
|
|
|
117
118
|
coordinates: coordinates,
|
|
118
119
|
directionalLockEnabled: true,
|
|
119
120
|
horizontal: true,
|
|
121
|
+
initialIndex: realInitialIndex,
|
|
120
122
|
scrollsToTop: false,
|
|
121
123
|
showsHorizontalScrollIndicator: false,
|
|
122
124
|
showsVerticalScrollIndicator: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","cloneElement","forwardRef","useEffect","useImperativeHandle","View","css","useTheme","useSyncAnimatedValue","TabIndicator","ScrollableTabsView","IndexAwareTab","useTabCoordinates","useIndexStore","InternalContext","isEveryTabCoordinatesDefined","useStyles","theme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","props","ref","children","initialIndex","disableIndicator","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","fallbackSharedIndex","initialValue","sharedIndex","setTab","newIndex","animatedValue","setValue","styles","coordinates","updateCoordinate","canRenderIndicator","indexStore","subscribe","tabElements","Children","map","child","index","onLayout","event","x","width","nativeEvent","layout","onMouseDown","e","preventDefault","onPress","tabElement","enableIndicator","undefined","tabIndicator"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useEffect, useImperativeHandle } from 'react';\nimport type { GestureResponderEvent, LayoutChangeEvent } from 'react-native';\nimport { View } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport { useSyncAnimatedValue } from '../hooks';\nimport type TabsProps from './TabsProps';\nimport type { TabsInstance } from './types';\nimport TabIndicator from './TabIndicator';\nimport ScrollableTabsView from './ScrollableTabsView';\nimport IndexAwareTab from './IndexAwareTab';\nimport useTabCoordinates from './useTabCoordinates';\nimport useIndexStore from './useIndexStore';\nimport InternalContext from './InternalContext';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\ntype TabsStyleKeys =\n | 'root'\n | 'fixedRoot'\n | 'fixedTab'\n | 'scrollableContainer';\n\ntype TabsStyles = NamedStylesStringUnion<TabsStyleKeys>;\n\nconst useStyles: UseStyles<TabsStyles> = function (): TabsStyles {\n const theme = useTheme();\n\n return {\n root: {},\n fixedRoot: {\n flexDirection: 'row',\n },\n fixedTab: {\n flex: 1,\n },\n scrollableContainer: {\n paddingHorizontal: theme.spacing(1),\n },\n };\n};\n\nconst Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {\n const {\n children,\n initialIndex = 0,\n disableIndicator = false,\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });\n
|
|
1
|
+
{"version":3,"names":["React","cloneElement","forwardRef","useEffect","useImperativeHandle","View","css","useTheme","useSyncAnimatedValue","TabIndicator","ScrollableTabsView","IndexAwareTab","useTabCoordinates","useIndexStore","InternalContext","isEveryTabCoordinatesDefined","useStyles","theme","root","fixedRoot","flexDirection","fixedTab","flex","scrollableContainer","paddingHorizontal","spacing","Tabs","props","ref","children","initialIndex","disableIndicator","keyboardDismissMode","keyboardShouldPersistTaps","onChange","scrollable","style","variant","UNSTABLE_sharedIndex","fallbackSharedIndex","initialValue","sharedIndex","realInitialIndex","setTab","newIndex","animatedValue","setValue","styles","coordinates","updateCoordinate","canRenderIndicator","indexStore","subscribe","tabElements","Children","map","child","index","onLayout","event","x","width","nativeEvent","layout","onMouseDown","e","preventDefault","onPress","tabElement","enableIndicator","undefined","tabIndicator"],"sources":["Tabs.tsx"],"sourcesContent":["import React, { cloneElement, forwardRef, useEffect, useImperativeHandle } from 'react';\nimport type { GestureResponderEvent, LayoutChangeEvent } from 'react-native';\nimport { View } from 'react-native';\nimport { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';\nimport { css, useTheme } from '../styles';\nimport { useSyncAnimatedValue } from '../hooks';\nimport type TabsProps from './TabsProps';\nimport type { TabsInstance } from './types';\nimport TabIndicator from './TabIndicator';\nimport ScrollableTabsView from './ScrollableTabsView';\nimport IndexAwareTab from './IndexAwareTab';\nimport useTabCoordinates from './useTabCoordinates';\nimport useIndexStore from './useIndexStore';\nimport InternalContext from './InternalContext';\nimport { isEveryTabCoordinatesDefined } from './utils';\n\ntype TabsStyleKeys =\n | 'root'\n | 'fixedRoot'\n | 'fixedTab'\n | 'scrollableContainer';\n\ntype TabsStyles = NamedStylesStringUnion<TabsStyleKeys>;\n\nconst useStyles: UseStyles<TabsStyles> = function (): TabsStyles {\n const theme = useTheme();\n\n return {\n root: {},\n fixedRoot: {\n flexDirection: 'row',\n },\n fixedTab: {\n flex: 1,\n },\n scrollableContainer: {\n paddingHorizontal: theme.spacing(1),\n },\n };\n};\n\nconst Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {\n const {\n children,\n initialIndex = 0,\n disableIndicator = false,\n keyboardDismissMode = 'none',\n keyboardShouldPersistTaps = 'never',\n onChange,\n scrollable = false,\n style,\n variant = 'primary',\n UNSTABLE_sharedIndex,\n } = props;\n\n const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });\n const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;\n const realInitialIndex = sharedIndex.initialValue;\n\n const setTab = (newIndex: number) => {\n sharedIndex.animatedValue.setValue(newIndex);\n };\n\n useImperativeHandle(\n ref,\n () => ({\n setTab,\n }),\n [sharedIndex],\n );\n\n const styles = useStyles();\n\n const [coordinates, updateCoordinate] = useTabCoordinates(children);\n\n const canRenderIndicator = isEveryTabCoordinatesDefined(coordinates, children);\n\n const indexStore = useIndexStore(sharedIndex);\n\n useEffect(() => {\n return indexStore.subscribe(newIndex => {\n onChange?.(newIndex);\n });\n }, [indexStore, onChange]);\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 // @ts-ignore\n child.props.onPress?.();\n };\n\n // @ts-ignore\n const tabElement = cloneElement(child, {\n enableIndicator: !disableIndicator && !canRenderIndicator,\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 initialIndex={realInitialIndex}\n />\n );\n });\n\n const tabIndicator = canRenderIndicator ? (\n <TabIndicator\n coordinates={coordinates}\n disabled={disableIndicator}\n initialIndex={realInitialIndex}\n scrollable={scrollable}\n />\n ) : null;\n\n return (\n <InternalContext.Provider value={{ indexStore }}>\n <View\n style={css([\n styles.root,\n scrollable ? undefined : styles.fixedRoot,\n style,\n ])}\n >\n {scrollable ? (\n <ScrollableTabsView\n automaticallyAdjustContentInsets={false}\n bounces={false}\n contentContainerStyle={styles.scrollableContainer}\n coordinates={coordinates}\n directionalLockEnabled={true}\n horizontal={true}\n initialIndex={realInitialIndex}\n scrollsToTop={false}\n showsHorizontalScrollIndicator={false}\n showsVerticalScrollIndicator={false}\n keyboardDismissMode={keyboardDismissMode}\n keyboardShouldPersistTaps={keyboardShouldPersistTaps}\n >\n {tabElements}\n {tabIndicator}\n </ScrollableTabsView>\n ) : (\n <React.Fragment>\n {tabElements}\n {tabIndicator}\n </React.Fragment>\n )}\n </View>\n </InternalContext.Provider>\n );\n});\n\nexport default Tabs;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,YAAhB,EAA8BC,UAA9B,EAA0CC,SAA1C,EAAqDC,mBAArD,QAAgF,OAAhF;AAEA,SAASC,IAAT,QAAqB,cAArB;AAEA,SAASC,GAAT,EAAcC,QAAd,QAA8B,WAA9B;AACA,SAASC,oBAAT,QAAqC,UAArC;AAGA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,kBAAP,MAA+B,sBAA/B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,SAASC,4BAAT,QAA6C,SAA7C;;AAUA,MAAMC,SAAgC,GAAG,YAAwB;EAC7D,MAAMC,KAAK,GAAGV,QAAQ,EAAtB;EAEA,OAAO;IACHW,IAAI,EAAE,EADH;IAEHC,SAAS,EAAE;MACPC,aAAa,EAAE;IADR,CAFR;IAKHC,QAAQ,EAAE;MACNC,IAAI,EAAE;IADA,CALP;IAQHC,mBAAmB,EAAE;MACjBC,iBAAiB,EAAEP,KAAK,CAACQ,OAAN,CAAc,CAAd;IADF;EARlB,CAAP;AAYH,CAfD;;AAiBA,MAAMC,IAAI,gBAAGxB,UAAU,CAA0B,SAASwB,IAAT,CAAcC,KAAd,EAAqBC,GAArB,EAA0B;EACvE,MAAM;IACFC,QADE;IAEFC,YAAY,GAAG,CAFb;IAGFC,gBAAgB,GAAG,KAHjB;IAIFC,mBAAmB,GAAG,MAJpB;IAKFC,yBAAyB,GAAG,OAL1B;IAMFC,QANE;IAOFC,UAAU,GAAG,KAPX;IAQF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AII,WAAW,EAAEyB,WAJjB;IAKI,sBAAsB,EAAE,IAL5B;IAMI,UAAU,EAAE,IANhB;IAOI,YAAY,EAAEN,gBAPlB;IAQI,YAAY,EAAE,KARlB;IASI,8BAA8B,EAAE,KATpC;IAUI,4BAA4B,EAAE,KAVlC;IAWI,mBAAmB,EAAEV,mBAXzB;IAYI,yBAAyB,EAAEC;EAZ/B,GAcKoB,WAdL,EAeKkB,YAfL,CADO,gBAmBP,oBAAC,KAAD,CAAO,QAAP,QACKlB,WADL,EAEKkB,YAFL,CA1BR,CADJ,CADJ;AAoCH,CAhIsB,CAAvB;AAkIA,eAAe7C,IAAf"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useContext, useEffect, useRef } from 'react';
|
|
2
2
|
import InternalContext from './InternalContext';
|
|
3
|
-
export default function useScrollViewReaction(coordinates) {
|
|
3
|
+
export default function useScrollViewReaction(initialIndex, coordinates) {
|
|
4
4
|
const scrollViewRef = useRef(null);
|
|
5
5
|
const lastScrolledXRef = useRef(NaN);
|
|
6
6
|
const {
|
|
@@ -23,23 +23,31 @@ export default function useScrollViewReaction(coordinates) {
|
|
|
23
23
|
const onLayout = useCallback(() => {
|
|
24
24
|
scrollToX(lastScrolledXRef.current);
|
|
25
25
|
}, []);
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const prevCoordinate = coordinates[prevIndex];
|
|
26
|
+
const computeNextScrollX = useCallback(index => {
|
|
27
|
+
const prevIndex = index - 1;
|
|
28
|
+
const prevCoordinate = coordinates[prevIndex];
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
if (prevCoordinate) {
|
|
31
|
+
const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;
|
|
32
|
+
return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);
|
|
33
|
+
}
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
return 0;
|
|
36
|
+
}, [coordinates]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (Number.isNaN(lastScrolledXRef.current)) {
|
|
39
|
+
const x = computeNextScrollX(initialIndex);
|
|
38
40
|
|
|
41
|
+
if (x > 0) {
|
|
42
|
+
scrollToX(x);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}, [initialIndex, computeNextScrollX]);
|
|
46
|
+
useEffect(() => {
|
|
39
47
|
return indexStore.subscribe(currentIndex => {
|
|
40
48
|
scrollToX(computeNextScrollX(currentIndex));
|
|
41
49
|
});
|
|
42
|
-
}, [indexStore,
|
|
50
|
+
}, [indexStore, computeNextScrollX]);
|
|
43
51
|
return {
|
|
44
52
|
scrollViewRef,
|
|
45
53
|
onLayout
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useContext","useEffect","useRef","InternalContext","useScrollViewReaction","coordinates","scrollViewRef","lastScrolledXRef","NaN","indexStore","scrollToX","x","Number","isFinite","current","scrollTo","y","animated","onLayout","computeNextScrollX","index","prevIndex","prevCoordinate","prevTabWidth","x2","x1","Math","floor","subscribe","currentIndex"],"sources":["useScrollViewReaction.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useCallback, useContext, useEffect, useRef } from 'react';\nimport type { ScrollView, ViewProps } from 'react-native';\nimport type TabCoordinate from './TabCoordinate';\nimport InternalContext from './InternalContext';\n\nexport interface UseScrollViewReaction {\n scrollViewRef: MutableRefObject<ScrollView | null>;\n onLayout: ViewProps['onLayout'];\n}\n\nexport default function useScrollViewReaction(\n coordinates: TabCoordinate[],\n): UseScrollViewReaction {\n const scrollViewRef = useRef<ScrollView | null>(null);\n\n const lastScrolledXRef = useRef<number>(NaN);\n\n const { indexStore } = useContext(InternalContext);\n\n const scrollToX = (x: number) => {\n if (Number.isFinite(x)) {\n scrollViewRef.current?.scrollTo({ x, y: 0, animated: true });\n\n lastScrolledXRef.current = x;\n }\n };\n\n const onLayout = useCallback(() => {\n scrollToX(lastScrolledXRef.current);\n }, []);\n\n
|
|
1
|
+
{"version":3,"names":["useCallback","useContext","useEffect","useRef","InternalContext","useScrollViewReaction","initialIndex","coordinates","scrollViewRef","lastScrolledXRef","NaN","indexStore","scrollToX","x","Number","isFinite","current","scrollTo","y","animated","onLayout","computeNextScrollX","index","prevIndex","prevCoordinate","prevTabWidth","x2","x1","Math","floor","isNaN","subscribe","currentIndex"],"sources":["useScrollViewReaction.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useCallback, useContext, useEffect, useRef } from 'react';\nimport type { ScrollView, ViewProps } from 'react-native';\nimport type TabCoordinate from './TabCoordinate';\nimport InternalContext from './InternalContext';\n\nexport interface UseScrollViewReaction {\n scrollViewRef: MutableRefObject<ScrollView | null>;\n onLayout: ViewProps['onLayout'];\n}\n\nexport default function useScrollViewReaction(\n initialIndex: number,\n coordinates: TabCoordinate[],\n): UseScrollViewReaction {\n const scrollViewRef = useRef<ScrollView | null>(null);\n\n const lastScrolledXRef = useRef<number>(NaN);\n\n const { indexStore } = useContext(InternalContext);\n\n const scrollToX = (x: number) => {\n if (Number.isFinite(x)) {\n scrollViewRef.current?.scrollTo({ x, y: 0, animated: true });\n\n lastScrolledXRef.current = x;\n }\n };\n\n const onLayout = useCallback(() => {\n scrollToX(lastScrolledXRef.current);\n }, []);\n\n const computeNextScrollX = useCallback((index: number): number => {\n const prevIndex = index - 1;\n const prevCoordinate = coordinates[prevIndex];\n\n if (prevCoordinate) {\n const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;\n return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);\n }\n\n return 0;\n }, [coordinates]);\n\n useEffect(() => {\n if (Number.isNaN(lastScrolledXRef.current)) {\n const x = computeNextScrollX(initialIndex);\n if (x > 0) {\n scrollToX(x);\n }\n }\n }, [initialIndex, computeNextScrollX]);\n\n useEffect(() => {\n return indexStore.subscribe(currentIndex => {\n scrollToX(computeNextScrollX(currentIndex));\n });\n }, [indexStore, compute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AYAL,SAAS,CAAC,MAAM;IACZ,IAAIY,MAAM,CAACgB,KAAP,CAAarB,gBAAgB,CAACO,OAA9B,CAAJ,EAA4C;MACxC,MAAMH,CAAC,GAAGQ,kBAAkB,CAACf,YAAD,CAA5B;;MACA,IAAIO,CAAC,GAAG,CAAR,EAAW;QACPD,SAAS,CAACC,CAAD,CAAT;MACH;IACJ;EACJ,CAPQ,EAON,CAACP,YAAD,EAAee,kBAAf,CAPM,CAAT;EASAnB,SAAS,CAAC,MAAM;IACZ,OAAOS,UAAU,CAACoB,SAAX,CAAqBC,YAAY,IAAI;MACxCpB,SAAS,CAACS,kBAAkB,CAACW,YAAD,CAAnB,CAAT;IACH,CAFM,CAAP;EAGH,CAJQ,EAIN,CAACrB,UAAD,EAAaU,kBAAb,CAJM,CAAT;EAMA,OAAO;IAAEb,aAAF;IAAiBY;EAAjB,CAAP;AACH;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MockStore","dispatch","
|
|
1
|
+
{"version":3,"names":["MockStore","dispatch","state","getState","Error","removeAllListeners","subscribe","listener"],"sources":["MockStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nexport default class MockStore<S> implements MonoStore<S> {\n\n dispatch(state: S): void {\n // do nothing\n }\n\n getState(): S {\n throw new Error('stub!');\n }\n\n removeAllListeners(): void {\n // do nothing\n }\n\n subscribe(listener: (state: S) => void): StoreSubscription {\n return () => void 0;\n }\n\n};\n"],"mappings":"AAEA,eAAe,MAAMA,SAAN,CAA2C;EAEtDC,QAAQ,CAACC,KAAD,EAAiB,CACrB;EACH;;EAEDC,QAAQ,GAAM;IACV,MAAM,IAAIC,KAAJ,CAAU,OAAV,CAAN;EACH;;EAEDC,kBAAkB,GAAS,CACvB;EACH;;EAEDC,SAAS,CAACC,QAAD,EAAkD;IACvD,OAAO,MAAM,KAAK,CAAlB;EACH;;AAhBqD;AAkBzD"}
|
|
@@ -5,36 +5,40 @@ function refEqual(a, b) {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export default class SimpleStore {
|
|
8
|
-
constructor(
|
|
9
|
-
_defineProperty(this, "
|
|
8
|
+
constructor(initialState) {
|
|
9
|
+
_defineProperty(this, "state", void 0);
|
|
10
10
|
|
|
11
11
|
_defineProperty(this, "listeners", []);
|
|
12
12
|
|
|
13
|
-
this.
|
|
13
|
+
this.state = initialState;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const index = this.listeners.indexOf(listener);
|
|
20
|
-
this.listeners.splice(index, 1);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
dispatch(data) {
|
|
25
|
-
// Do not dispatch if data ref is equal
|
|
26
|
-
if (refEqual(this.data, data)) {
|
|
16
|
+
dispatch(state) {
|
|
17
|
+
// Do not dispatch if state ref is equal
|
|
18
|
+
if (refEqual(this.state, state)) {
|
|
27
19
|
return;
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
this.
|
|
22
|
+
this.state = state;
|
|
31
23
|
|
|
32
24
|
for (const id in this.listeners) {
|
|
33
25
|
const listener = this.listeners[id];
|
|
34
|
-
listener === null || listener === void 0 ? void 0 : listener(
|
|
26
|
+
listener === null || listener === void 0 ? void 0 : listener(state);
|
|
35
27
|
}
|
|
36
28
|
}
|
|
37
29
|
|
|
30
|
+
getState() {
|
|
31
|
+
return this.state;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
subscribe(listener) {
|
|
35
|
+
this.listeners.push(listener);
|
|
36
|
+
return () => {
|
|
37
|
+
const index = this.listeners.indexOf(listener);
|
|
38
|
+
this.listeners.splice(index, 1);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
removeAllListeners() {
|
|
39
43
|
this.listeners.splice(0, this.listeners.length);
|
|
40
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["refEqual","a","b","SimpleStore","constructor","
|
|
1
|
+
{"version":3,"names":["refEqual","a","b","SimpleStore","constructor","initialState","state","dispatch","id","listeners","listener","getState","subscribe","push","index","indexOf","splice","removeAllListeners","length"],"sources":["SimpleStore.ts"],"sourcesContent":["import { MonoStore, StoreSubscription } from './types';\n\nfunction refEqual(a: any, b: any): boolean {\n return a === b;\n}\n\nexport default class SimpleStore<S> implements MonoStore<S> {\n\n private state: S;\n\n private listeners: Array<(state: S) => void> = [];\n\n constructor(initialState: S) {\n this.state = initialState;\n }\n\n dispatch(state: S): void {\n // Do not dispatch if state ref is equal\n if (refEqual(this.state, state)) {\n return;\n }\n\n this.state = state;\n for (const id in this.listeners) {\n const listener = this.listeners[id];\n listener?.(state);\n }\n }\n\n getState(): S {\n return this.state;\n }\n\n subscribe(listener: (state: S) => void): StoreSubscription {\n this.listeners.push(listener);\n\n return () => {\n const index = this.listeners.indexOf(listener);\n this.listeners.splice(index, 1);\n };\n }\n\n removeAllListeners(): void {\n this.listeners.splice(0, this.listeners.length);\n }\n\n};\n"],"mappings":";;AAEA,SAASA,QAAT,CAAkBC,CAAlB,EAA0BC,CAA1B,EAA2C;EACvC,OAAOD,CAAC,KAAKC,CAAb;AACH;;AAED,eAAe,MAAMC,WAAN,CAA6C;EAMxDC,WAAW,CAACC,YAAD,EAAkB;IAAA;;IAAA,mCAFkB,EAElB;;IACzB,KAAKC,KAAL,GAAaD,YAAb;EACH;;EAEDE,QAAQ,CAACD,KAAD,EAAiB;IACrB;IACA,IAAIN,QAAQ,CAAC,KAAKM,KAAN,EAAaA,KAAb,CAAZ,EAAiC;MAC7B;IACH;;IAED,KAAKA,KAAL,GAAaA,KAAb;;IACA,KAAK,MAAME,EAAX,IAAiB,KAAKC,SAAtB,EAAiC;MAC7B,MAAMC,QAAQ,GAAG,KAAKD,SAAL,CAAeD,EAAf,CAAjB;MACAE,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAGJ,KAAH,CAAR;IACH;EACJ;;EAEDK,QAAQ,GAAM;IACV,OAAO,KAAKL,KAAZ;EACH;;EAEDM,SAAS,CAACF,QAAD,EAAkD;IACvD,KAAKD,SAAL,CAAeI,IAAf,CAAoBH,QAApB;IAEA,OAAO,MAAM;MACT,MAAMI,KAAK,GAAG,KAAKL,SAAL,CAAeM,OAAf,CAAuBL,QAAvB,CAAd;MACA,KAAKD,SAAL,CAAeO,MAAf,CAAsBF,KAAtB,EAA6B,CAA7B;IACH,CAHD;EAIH;;EAEDG,kBAAkB,GAAS;IACvB,KAAKR,SAAL,CAAeO,MAAf,CAAsB,CAAtB,EAAyB,KAAKP,SAAL,CAAeS,MAAxC;EACH;;AAtCuD;AAwC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface StoreSubscription {\n (): void;\n}\n\nexport interface MonoStore<
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface StoreSubscription {\n (): void;\n}\n\nexport interface MonoStore<S> {\n dispatch: (state: S) => void;\n getState: () => S;\n subscribe: (listener: (state: S) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n"],"mappings":""}
|
|
@@ -11,6 +11,10 @@ export default interface ChipProps extends OverridableComponentProps<ButtonBaseP
|
|
|
11
11
|
* The content of the component.
|
|
12
12
|
*/
|
|
13
13
|
children: string;
|
|
14
|
+
/**
|
|
15
|
+
* Number of lines of children.
|
|
16
|
+
*/
|
|
17
|
+
numberOfLines?: number;
|
|
14
18
|
/**
|
|
15
19
|
* Element placed before the children.
|
|
16
20
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ScrollViewProps } from 'react-native';
|
|
2
2
|
import TabCoordinate from './TabCoordinate';
|
|
3
3
|
export interface ScrollableTabsViewProps extends ScrollViewProps {
|
|
4
|
+
initialIndex: number;
|
|
4
5
|
coordinates: TabCoordinate[];
|
|
5
6
|
}
|
|
6
7
|
export default function ScrollableTabsView(props: ScrollableTabsViewProps): JSX.Element;
|
|
@@ -5,4 +5,4 @@ export interface UseScrollViewReaction {
|
|
|
5
5
|
scrollViewRef: MutableRefObject<ScrollView | null>;
|
|
6
6
|
onLayout: ViewProps['onLayout'];
|
|
7
7
|
}
|
|
8
|
-
export default function useScrollViewReaction(coordinates: TabCoordinate[]): UseScrollViewReaction;
|
|
8
|
+
export default function useScrollViewReaction(initialIndex: number, coordinates: TabCoordinate[]): UseScrollViewReaction;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MonoStore, StoreSubscription } from './types';
|
|
2
|
-
export default class MockStore<
|
|
3
|
-
dispatch(
|
|
2
|
+
export default class MockStore<S> implements MonoStore<S> {
|
|
3
|
+
dispatch(state: S): void;
|
|
4
|
+
getState(): S;
|
|
4
5
|
removeAllListeners(): void;
|
|
5
|
-
subscribe(listener: (
|
|
6
|
+
subscribe(listener: (state: S) => void): StoreSubscription;
|
|
6
7
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MonoStore, StoreSubscription } from './types';
|
|
2
|
-
export default class SimpleStore<
|
|
3
|
-
private
|
|
2
|
+
export default class SimpleStore<S> implements MonoStore<S> {
|
|
3
|
+
private state;
|
|
4
4
|
private listeners;
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
constructor(initialState: S);
|
|
6
|
+
dispatch(state: S): void;
|
|
7
|
+
getState(): S;
|
|
8
|
+
subscribe(listener: (state: S) => void): StoreSubscription;
|
|
8
9
|
removeAllListeners(): void;
|
|
9
10
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export interface StoreSubscription {
|
|
2
2
|
(): void;
|
|
3
3
|
}
|
|
4
|
-
export interface MonoStore<
|
|
5
|
-
dispatch: (
|
|
6
|
-
|
|
4
|
+
export interface MonoStore<S> {
|
|
5
|
+
dispatch: (state: S) => void;
|
|
6
|
+
getState: () => S;
|
|
7
|
+
subscribe: (listener: (state: S) => void) => StoreSubscription;
|
|
7
8
|
removeAllListeners: () => void;
|
|
8
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fountain-ui/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.23",
|
|
4
4
|
"author": "Fountain-UI Team",
|
|
5
5
|
"description": "React components that implement Tappytoon's Fountain Design.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "8b3569226ab4fc9c5812084f850461c9beffe496"
|
|
71
71
|
}
|
package/src/Chip/Chip.tsx
CHANGED
|
@@ -30,6 +30,7 @@ export default function Chip(props: ChipProps) {
|
|
|
30
30
|
const {
|
|
31
31
|
children,
|
|
32
32
|
endIcon: endIconProp,
|
|
33
|
+
numberOfLines,
|
|
33
34
|
onPress,
|
|
34
35
|
startIcon: startIconProp,
|
|
35
36
|
style: styleProp,
|
|
@@ -103,6 +104,7 @@ export default function Chip(props: ChipProps) {
|
|
|
103
104
|
|
|
104
105
|
<Text
|
|
105
106
|
children={children}
|
|
107
|
+
numberOfLines={numberOfLines}
|
|
106
108
|
style={textStyle}
|
|
107
109
|
/>
|
|
108
110
|
|
package/src/Chip/ChipProps.ts
CHANGED
|
@@ -5,16 +5,18 @@ import TabCoordinate from './TabCoordinate';
|
|
|
5
5
|
import useScrollViewReaction from './useScrollViewReaction';
|
|
6
6
|
|
|
7
7
|
export interface ScrollableTabsViewProps extends ScrollViewProps {
|
|
8
|
+
initialIndex: number;
|
|
8
9
|
coordinates: TabCoordinate[];
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export default function ScrollableTabsView(props: ScrollableTabsViewProps) {
|
|
12
13
|
const {
|
|
13
14
|
coordinates,
|
|
15
|
+
initialIndex,
|
|
14
16
|
...scrollViewProps
|
|
15
17
|
} = props;
|
|
16
18
|
|
|
17
|
-
const { scrollViewRef, onLayout } = useScrollViewReaction(coordinates);
|
|
19
|
+
const { scrollViewRef, onLayout } = useScrollViewReaction(initialIndex, coordinates);
|
|
18
20
|
|
|
19
21
|
return (
|
|
20
22
|
<ScrollView
|
package/src/Tabs/Tabs.tsx
CHANGED
|
@@ -54,8 +54,8 @@ const Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {
|
|
|
54
54
|
} = props;
|
|
55
55
|
|
|
56
56
|
const fallbackSharedIndex = useSyncAnimatedValue({ initialValue: initialIndex });
|
|
57
|
-
|
|
58
57
|
const sharedIndex = UNSTABLE_sharedIndex ?? fallbackSharedIndex;
|
|
58
|
+
const realInitialIndex = sharedIndex.initialValue;
|
|
59
59
|
|
|
60
60
|
const setTab = (newIndex: number) => {
|
|
61
61
|
sharedIndex.animatedValue.setValue(newIndex);
|
|
@@ -117,7 +117,7 @@ const Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {
|
|
|
117
117
|
<IndexAwareTab
|
|
118
118
|
children={tabElement}
|
|
119
119
|
index={index}
|
|
120
|
-
initialIndex={
|
|
120
|
+
initialIndex={realInitialIndex}
|
|
121
121
|
/>
|
|
122
122
|
);
|
|
123
123
|
});
|
|
@@ -126,7 +126,7 @@ const Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {
|
|
|
126
126
|
<TabIndicator
|
|
127
127
|
coordinates={coordinates}
|
|
128
128
|
disabled={disableIndicator}
|
|
129
|
-
initialIndex={
|
|
129
|
+
initialIndex={realInitialIndex}
|
|
130
130
|
scrollable={scrollable}
|
|
131
131
|
/>
|
|
132
132
|
) : null;
|
|
@@ -148,6 +148,7 @@ const Tabs = forwardRef<TabsInstance, TabsProps>(function Tabs(props, ref) {
|
|
|
148
148
|
coordinates={coordinates}
|
|
149
149
|
directionalLockEnabled={true}
|
|
150
150
|
horizontal={true}
|
|
151
|
+
initialIndex={realInitialIndex}
|
|
151
152
|
scrollsToTop={false}
|
|
152
153
|
showsHorizontalScrollIndicator={false}
|
|
153
154
|
showsVerticalScrollIndicator={false}
|
|
@@ -10,6 +10,7 @@ export interface UseScrollViewReaction {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export default function useScrollViewReaction(
|
|
13
|
+
initialIndex: number,
|
|
13
14
|
coordinates: TabCoordinate[],
|
|
14
15
|
): UseScrollViewReaction {
|
|
15
16
|
const scrollViewRef = useRef<ScrollView | null>(null);
|
|
@@ -30,23 +31,32 @@ export default function useScrollViewReaction(
|
|
|
30
31
|
scrollToX(lastScrolledXRef.current);
|
|
31
32
|
}, []);
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
const prevCoordinate = coordinates[prevIndex];
|
|
34
|
+
const computeNextScrollX = useCallback((index: number): number => {
|
|
35
|
+
const prevIndex = index - 1;
|
|
36
|
+
const prevCoordinate = coordinates[prevIndex];
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
if (prevCoordinate) {
|
|
39
|
+
const prevTabWidth = prevCoordinate.x2 - prevCoordinate.x1;
|
|
40
|
+
return Math.floor(prevCoordinate.x1 + prevTabWidth / 2);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return 0;
|
|
44
|
+
}, [coordinates]);
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (Number.isNaN(lastScrolledXRef.current)) {
|
|
48
|
+
const x = computeNextScrollX(initialIndex);
|
|
49
|
+
if (x > 0) {
|
|
50
|
+
scrollToX(x);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}, [initialIndex, computeNextScrollX]);
|
|
45
54
|
|
|
55
|
+
useEffect(() => {
|
|
46
56
|
return indexStore.subscribe(currentIndex => {
|
|
47
57
|
scrollToX(computeNextScrollX(currentIndex));
|
|
48
58
|
});
|
|
49
|
-
}, [indexStore,
|
|
59
|
+
}, [indexStore, computeNextScrollX]);
|
|
50
60
|
|
|
51
61
|
return { scrollViewRef, onLayout };
|
|
52
62
|
};
|
package/src/store/MockStore.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { MonoStore, StoreSubscription } from './types';
|
|
2
2
|
|
|
3
|
-
export default class MockStore<
|
|
3
|
+
export default class MockStore<S> implements MonoStore<S> {
|
|
4
4
|
|
|
5
|
-
dispatch(
|
|
5
|
+
dispatch(state: S): void {
|
|
6
6
|
// do nothing
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
getState(): S {
|
|
10
|
+
throw new Error('stub!');
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
removeAllListeners(): void {
|
|
10
14
|
// do nothing
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
subscribe(listener: (
|
|
17
|
+
subscribe(listener: (state: S) => void): StoreSubscription {
|
|
14
18
|
return () => void 0;
|
|
15
19
|
}
|
|
16
20
|
|
package/src/store/SimpleStore.ts
CHANGED
|
@@ -4,38 +4,42 @@ function refEqual(a: any, b: any): boolean {
|
|
|
4
4
|
return a === b;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export default class SimpleStore<
|
|
7
|
+
export default class SimpleStore<S> implements MonoStore<S> {
|
|
8
8
|
|
|
9
|
-
private
|
|
9
|
+
private state: S;
|
|
10
10
|
|
|
11
|
-
private listeners: Array<(
|
|
11
|
+
private listeners: Array<(state: S) => void> = [];
|
|
12
12
|
|
|
13
|
-
constructor(
|
|
14
|
-
this.
|
|
13
|
+
constructor(initialState: S) {
|
|
14
|
+
this.state = initialState;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return () => {
|
|
21
|
-
const index = this.listeners.indexOf(listener);
|
|
22
|
-
this.listeners.splice(index, 1);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
dispatch(data: T): void {
|
|
27
|
-
// Do not dispatch if data ref is equal
|
|
28
|
-
if (refEqual(this.data, data)) {
|
|
17
|
+
dispatch(state: S): void {
|
|
18
|
+
// Do not dispatch if state ref is equal
|
|
19
|
+
if (refEqual(this.state, state)) {
|
|
29
20
|
return;
|
|
30
21
|
}
|
|
31
22
|
|
|
32
|
-
this.
|
|
23
|
+
this.state = state;
|
|
33
24
|
for (const id in this.listeners) {
|
|
34
25
|
const listener = this.listeners[id];
|
|
35
|
-
listener?.(
|
|
26
|
+
listener?.(state);
|
|
36
27
|
}
|
|
37
28
|
}
|
|
38
29
|
|
|
30
|
+
getState(): S {
|
|
31
|
+
return this.state;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
subscribe(listener: (state: S) => void): StoreSubscription {
|
|
35
|
+
this.listeners.push(listener);
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
const index = this.listeners.indexOf(listener);
|
|
39
|
+
this.listeners.splice(index, 1);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
removeAllListeners(): void {
|
|
40
44
|
this.listeners.splice(0, this.listeners.length);
|
|
41
45
|
}
|
package/src/store/types.ts
CHANGED
|
@@ -2,8 +2,9 @@ export interface StoreSubscription {
|
|
|
2
2
|
(): void;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export interface MonoStore<
|
|
6
|
-
dispatch: (
|
|
7
|
-
|
|
5
|
+
export interface MonoStore<S> {
|
|
6
|
+
dispatch: (state: S) => void;
|
|
7
|
+
getState: () => S;
|
|
8
|
+
subscribe: (listener: (state: S) => void) => StoreSubscription;
|
|
8
9
|
removeAllListeners: () => void;
|
|
9
10
|
}
|