react-native-system-ui 0.0.3 → 0.0.4
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/dist/cjs/components/area/Area.js +4 -10
- package/dist/cjs/components/avatar/Avatar.js +3 -3
- package/dist/cjs/components/avatar/tokens.js +2 -1
- package/dist/cjs/components/badge/Badge.js +30 -38
- package/dist/cjs/components/button/Button.js +13 -13
- package/dist/cjs/components/button/ButtonGroup.js +8 -8
- package/dist/cjs/components/calendar/Calendar.js +10 -10
- package/dist/cjs/components/cascader/Cascader.js +4 -4
- package/dist/cjs/components/cascader/useCascaderExtend.js +5 -15
- package/dist/cjs/components/checkbox/CheckboxGroup.js +2 -2
- package/dist/cjs/components/circle/Circle.js +2 -2
- package/dist/cjs/components/collapse/Collapse.js +13 -16
- package/dist/cjs/components/config-provider/ConfigProvider.js +1 -1
- package/dist/cjs/components/datetime-picker/DatetimePicker.js +7 -7
- package/dist/cjs/components/dialog/Dialog.js +4 -6
- package/dist/cjs/components/dialog/tokens.js +2 -1
- package/dist/cjs/components/dropdown-menu/DropdownItem.js +53 -52
- package/dist/cjs/components/dropdown-menu/DropdownMenu.js +19 -23
- package/dist/cjs/components/dropdown-menu/tokens.js +20 -3
- package/dist/cjs/components/field/Field.js +6 -6
- package/dist/cjs/components/form/Form.js +5 -9
- package/dist/cjs/components/grid/Grid.js +4 -4
- package/dist/cjs/components/image/Image.js +19 -15
- package/dist/cjs/components/image-preview/ImagePreview.js +62 -60
- package/dist/cjs/components/image-preview/tokens.js +21 -2
- package/dist/cjs/components/index-bar/IndexAnchor.js +7 -6
- package/dist/cjs/components/index-bar/IndexBar.js +38 -44
- package/dist/cjs/components/index-bar/tokens.js +22 -13
- package/dist/cjs/components/index.js +343 -0
- package/dist/cjs/components/input/Input.js +7 -10
- package/dist/cjs/components/notice-bar/NoticeBar.js +69 -95
- package/dist/cjs/components/notify/Notify.js +46 -22
- package/dist/cjs/components/notify/defaults.js +2 -2
- package/dist/cjs/components/notify/imperative.js +1 -1
- package/dist/cjs/components/notify/tokens.js +5 -4
- package/dist/cjs/components/number-keyboard/NumberKeyboard.js +12 -12
- package/dist/cjs/components/number-keyboard/tokens.js +4 -2
- package/dist/cjs/components/overlay/useOverlayStack.js +5 -1
- package/dist/cjs/components/pagination/Pagination.js +2 -2
- package/dist/cjs/components/password-input/PasswordInput.js +35 -27
- package/dist/cjs/components/picker/Picker.js +11 -12
- package/dist/cjs/components/picker/WheelPicker.js +9 -9
- package/dist/cjs/components/picker/tokens.js +4 -2
- package/dist/cjs/components/popup/Popup.js +39 -54
- package/dist/cjs/components/popup/tokens.js +2 -1
- package/dist/cjs/components/portal/Portal.js +5 -0
- package/dist/cjs/components/portal/PortalHost.js +1 -13
- package/dist/cjs/components/pull-refresh/PullRefresh.js +46 -27
- package/dist/cjs/components/radio/RadioGroup.js +2 -2
- package/dist/cjs/components/search/Search.js +52 -67
- package/dist/cjs/components/search/tokens.js +2 -1
- package/dist/cjs/components/selector/Selector.js +3 -3
- package/dist/cjs/components/share-sheet/ShareSheet.js +64 -62
- package/dist/cjs/components/share-sheet/tokens.js +15 -2
- package/dist/cjs/components/sidebar/Sidebar.js +15 -19
- package/dist/cjs/components/sidebar/SidebarItem.js +0 -3
- package/dist/cjs/components/skeleton/Skeleton.js +44 -56
- package/dist/cjs/components/slider/Slider.js +55 -61
- package/dist/cjs/components/stepper/Stepper.js +13 -16
- package/dist/cjs/components/stepper/tokens.js +4 -2
- package/dist/cjs/components/swiper/Swiper.js +21 -42
- package/dist/cjs/components/swiper/useSwiperWeb.js +15 -18
- package/dist/cjs/components/tabbar/Tabbar.js +8 -11
- package/dist/cjs/components/tabbar/TabbarItem.js +0 -3
- package/dist/cjs/components/tabs/Tabs.js +33 -54
- package/dist/cjs/components/tabs/tokens.js +9 -1
- package/dist/cjs/components/tabs/useTabsScroll.js +4 -0
- package/dist/cjs/components/toast/Toast.js +10 -8
- package/dist/cjs/components/toast/tokens.js +5 -1
- package/dist/cjs/components/typography/Typography.js +17 -30
- package/dist/cjs/components/uploader/Uploader.js +49 -46
- package/dist/cjs/components/uploader/tokens.js +27 -1
- package/dist/cjs/components/water-mark/WaterMark.js +16 -16
- package/dist/cjs/hooks/usePresenceAnimation.js +12 -2
- package/dist/es/components/area/Area.js +5 -11
- package/dist/es/components/avatar/Avatar.js +3 -3
- package/dist/es/components/avatar/tokens.js +2 -1
- package/dist/es/components/badge/Badge.js +31 -39
- package/dist/es/components/button/Button.js +14 -14
- package/dist/es/components/button/ButtonGroup.js +7 -7
- package/dist/es/components/calendar/Calendar.js +11 -11
- package/dist/es/components/cascader/Cascader.js +5 -5
- package/dist/es/components/cascader/useCascaderExtend.js +5 -9
- package/dist/es/components/checkbox/CheckboxGroup.js +3 -3
- package/dist/es/components/circle/Circle.js +3 -3
- package/dist/es/components/collapse/Collapse.js +14 -17
- package/dist/es/components/config-provider/ConfigProvider.js +2 -2
- package/dist/es/components/datetime-picker/DatetimePicker.js +8 -8
- package/dist/es/components/dialog/Dialog.js +4 -6
- package/dist/es/components/dialog/tokens.js +2 -1
- package/dist/es/components/dropdown-menu/DropdownItem.js +53 -52
- package/dist/es/components/dropdown-menu/DropdownMenu.js +20 -24
- package/dist/es/components/dropdown-menu/tokens.js +20 -3
- package/dist/es/components/field/Field.js +7 -7
- package/dist/es/components/field/index.js +1 -1
- package/dist/es/components/form/Form.js +6 -10
- package/dist/es/components/grid/Grid.js +3 -3
- package/dist/es/components/image/Image.js +20 -16
- package/dist/es/components/image-preview/ImagePreview.js +63 -61
- package/dist/es/components/image-preview/tokens.js +21 -2
- package/dist/es/components/index-bar/IndexAnchor.js +7 -6
- package/dist/es/components/index-bar/IndexBar.js +39 -45
- package/dist/es/components/index-bar/tokens.js +22 -13
- package/dist/es/components/index.js +50 -1
- package/dist/es/components/input/Input.js +8 -11
- package/dist/es/components/notice-bar/NoticeBar.js +70 -96
- package/dist/es/components/notify/Notify.js +46 -23
- package/dist/es/components/notify/defaults.js +2 -2
- package/dist/es/components/notify/imperative.js +1 -1
- package/dist/es/components/notify/tokens.js +5 -4
- package/dist/es/components/number-keyboard/NumberKeyboard.js +13 -13
- package/dist/es/components/number-keyboard/tokens.js +4 -2
- package/dist/es/components/overlay/useOverlayStack.js +6 -2
- package/dist/es/components/pagination/Pagination.js +3 -3
- package/dist/es/components/password-input/PasswordInput.js +36 -28
- package/dist/es/components/picker/Picker.js +12 -13
- package/dist/es/components/picker/WheelPicker.js +10 -10
- package/dist/es/components/picker/tokens.js +4 -2
- package/dist/es/components/popup/Popup.js +41 -56
- package/dist/es/components/popup/tokens.js +2 -1
- package/dist/es/components/portal/Portal.js +5 -0
- package/dist/es/components/portal/PortalHost.js +1 -13
- package/dist/es/components/pull-refresh/PullRefresh.js +47 -28
- package/dist/es/components/radio/RadioGroup.js +3 -3
- package/dist/es/components/search/Search.js +53 -68
- package/dist/es/components/search/tokens.js +2 -1
- package/dist/es/components/selector/Selector.js +4 -4
- package/dist/es/components/share-sheet/ShareSheet.js +65 -63
- package/dist/es/components/share-sheet/tokens.js +15 -2
- package/dist/es/components/sidebar/Sidebar.js +14 -18
- package/dist/es/components/sidebar/SidebarItem.js +0 -3
- package/dist/es/components/skeleton/Skeleton.js +45 -57
- package/dist/es/components/slider/Slider.js +56 -62
- package/dist/es/components/stepper/Stepper.js +14 -17
- package/dist/es/components/stepper/tokens.js +4 -2
- package/dist/es/components/swiper/Swiper.js +22 -43
- package/dist/es/components/swiper/useSwiperWeb.js +16 -19
- package/dist/es/components/tabbar/Tabbar.js +9 -12
- package/dist/es/components/tabbar/TabbarItem.js +0 -3
- package/dist/es/components/tabs/Tabs.js +34 -55
- package/dist/es/components/tabs/tokens.js +9 -1
- package/dist/es/components/tabs/useTabsScroll.js +4 -0
- package/dist/es/components/toast/Toast.js +10 -8
- package/dist/es/components/toast/tokens.js +5 -1
- package/dist/es/components/typography/Typography.js +18 -31
- package/dist/es/components/uploader/Uploader.js +49 -46
- package/dist/es/components/uploader/tokens.js +27 -1
- package/dist/es/components/water-mark/WaterMark.js +17 -17
- package/dist/es/hooks/usePresenceAnimation.js +12 -2
- package/dist/types/components/dialog/tokens.d.ts +1 -0
- package/dist/types/components/dropdown-menu/tokens.d.ts +17 -0
- package/dist/types/components/field/index.d.ts +1 -1
- package/dist/types/components/image-preview/tokens.d.ts +16 -0
- package/dist/types/components/index-bar/tokens.d.ts +13 -4
- package/dist/types/components/index.d.ts +102 -0
- package/dist/types/components/notify/defaults.d.ts +2 -2
- package/dist/types/components/number-keyboard/tokens.d.ts +1 -0
- package/dist/types/components/password-input/PasswordInput.d.ts +4 -0
- package/dist/types/components/picker/tokens.d.ts +2 -0
- package/dist/types/components/popup/tokens.d.ts +1 -0
- package/dist/types/components/search/tokens.d.ts +1 -0
- package/dist/types/components/share-sheet/tokens.d.ts +13 -0
- package/dist/types/components/stepper/tokens.d.ts +2 -0
- package/dist/types/components/tabs/tokens.d.ts +8 -0
- package/dist/types/components/toast/tokens.d.ts +4 -0
- package/dist/types/components/uploader/tokens.d.ts +25 -0
- package/dist/types/hooks/usePresenceAnimation.d.ts +6 -1
- package/package.json +135 -135
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { useCallback, useEffect, useImperativeHandle,
|
|
2
|
+
import React, { useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
3
3
|
import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
|
|
4
4
|
import { useControllableValue } from '../../hooks';
|
|
5
5
|
import { parseNumber, addNumber as add, clampValue, formatNumber as formatValue, numberToString as valueToString, parseDecimalLength, isFiniteNumber, isPromiseLike } from '../../utils';
|
|
@@ -139,8 +139,7 @@ export const Stepper = /*#__PURE__*/React.forwardRef((p, ref) => {
|
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
141
|
commit();
|
|
142
|
-
}).catch(
|
|
143
|
-
if (typeof __DEV__ !== 'undefined' && __DEV__) console.error(error);
|
|
142
|
+
}).catch(() => {
|
|
144
143
|
commit();
|
|
145
144
|
}).finally(() => {
|
|
146
145
|
changingRef.current = false;
|
|
@@ -153,8 +152,7 @@ export const Stepper = /*#__PURE__*/React.forwardRef((p, ref) => {
|
|
|
153
152
|
return 'noop';
|
|
154
153
|
}
|
|
155
154
|
return commit();
|
|
156
|
-
} catch
|
|
157
|
-
if (typeof __DEV__ !== 'undefined' && __DEV__) console.error(error);
|
|
155
|
+
} catch {
|
|
158
156
|
return commit();
|
|
159
157
|
}
|
|
160
158
|
}, [beforeChange, decimalLength, setInputText, setValue]);
|
|
@@ -247,15 +245,15 @@ export const Stepper = /*#__PURE__*/React.forwardRef((p, ref) => {
|
|
|
247
245
|
const minusDisabled = disabledForAll || disableMinus || minNumber !== undefined && currentForCompare <= minNumber;
|
|
248
246
|
const plusDisabled = disabledForAll || disablePlus || maxNumber !== undefined && currentForCompare >= maxNumber;
|
|
249
247
|
const radius = tokens.radii.default;
|
|
250
|
-
const buttonBaseStyle =
|
|
248
|
+
const buttonBaseStyle = {
|
|
251
249
|
width: resolvedButtonSize,
|
|
252
250
|
height: resolvedButtonSize
|
|
253
|
-
}
|
|
254
|
-
const inputBoxStyle =
|
|
251
|
+
};
|
|
252
|
+
const inputBoxStyle = {
|
|
255
253
|
width: resolvedInputWidth,
|
|
256
254
|
height: resolvedButtonSize,
|
|
257
255
|
marginHorizontal: tokens.spacing.gap
|
|
258
|
-
}
|
|
256
|
+
};
|
|
259
257
|
const getButtonStyle = useCallback((type, state) => {
|
|
260
258
|
const isPlus = type === 'plus';
|
|
261
259
|
const disabledState = isPlus ? plusDisabled : minusDisabled;
|
|
@@ -394,11 +392,10 @@ export const Stepper = /*#__PURE__*/React.forwardRef((p, ref) => {
|
|
|
394
392
|
style: getButtonTextStyle('plus')
|
|
395
393
|
}, "+"));
|
|
396
394
|
}, [getButtonTextStyle, getPlusButtonStyle, handlePlusPress, handlePlusPressIn, handlePressOut, plusDisabled, showPlus]);
|
|
397
|
-
const inputNode =
|
|
398
|
-
if (!showInput) return null;
|
|
395
|
+
const inputNode = !showInput ? null : (() => {
|
|
399
396
|
const editable = !disabledForAll && !disableInput;
|
|
400
397
|
const inputDisabled = disabledForAll || disableInput;
|
|
401
|
-
const inputBackground = theme === 'round' ?
|
|
398
|
+
const inputBackground = theme === 'round' ? tokens.colors.transparent : inputDisabled ? tokens.colors.inputDisabledBackground : tokens.colors.background;
|
|
402
399
|
const inputTextColor = inputDisabled ? tokens.colors.inputDisabledText : tokens.colors.inputText;
|
|
403
400
|
const keyboardType = integer ? 'number-pad' : 'decimal-pad';
|
|
404
401
|
return /*#__PURE__*/React.createElement(TextInput, _extends({
|
|
@@ -406,7 +403,9 @@ export const Stepper = /*#__PURE__*/React.forwardRef((p, ref) => {
|
|
|
406
403
|
}, inputProps, {
|
|
407
404
|
style: [styles.input, inputBoxStyle, {
|
|
408
405
|
backgroundColor: inputBackground,
|
|
409
|
-
color: inputTextColor
|
|
406
|
+
color: inputTextColor,
|
|
407
|
+
paddingHorizontal: tokens.spacing.none,
|
|
408
|
+
paddingVertical: tokens.spacing.none
|
|
410
409
|
}, inputStyle],
|
|
411
410
|
value: inputValue,
|
|
412
411
|
placeholder: placeholder,
|
|
@@ -417,7 +416,7 @@ export const Stepper = /*#__PURE__*/React.forwardRef((p, ref) => {
|
|
|
417
416
|
onBlur: handleBlur,
|
|
418
417
|
onPressIn: handleInputPressIn
|
|
419
418
|
}));
|
|
420
|
-
}
|
|
419
|
+
})();
|
|
421
420
|
return /*#__PURE__*/React.createElement(View, _extends({}, rest, {
|
|
422
421
|
style: [styles.container, style]
|
|
423
422
|
}), renderMinusButton(), inputNode, renderPlusButton());
|
|
@@ -433,9 +432,7 @@ const styles = StyleSheet.create({
|
|
|
433
432
|
},
|
|
434
433
|
buttonText: {},
|
|
435
434
|
input: {
|
|
436
|
-
textAlign: 'center'
|
|
437
|
-
paddingHorizontal: 0,
|
|
438
|
-
paddingVertical: 0
|
|
435
|
+
textAlign: 'center'
|
|
439
436
|
}
|
|
440
437
|
});
|
|
441
438
|
Stepper.displayName = 'Stepper';
|
|
@@ -29,7 +29,8 @@ const createStepperTokens = foundations => {
|
|
|
29
29
|
roundThemeBackground: '#ffffff',
|
|
30
30
|
inputText: palette.default[900],
|
|
31
31
|
inputDisabledText: palette.default[400],
|
|
32
|
-
inputDisabledBackground: palette.default[100]
|
|
32
|
+
inputDisabledBackground: palette.default[100],
|
|
33
|
+
transparent: 'transparent'
|
|
33
34
|
},
|
|
34
35
|
radii: {
|
|
35
36
|
default: radii.md
|
|
@@ -44,7 +45,8 @@ const createStepperTokens = foundations => {
|
|
|
44
45
|
pressed: opacity.pressed
|
|
45
46
|
},
|
|
46
47
|
spacing: {
|
|
47
|
-
gap: 2
|
|
48
|
+
gap: 2,
|
|
49
|
+
none: foundations.spacing.none
|
|
48
50
|
}
|
|
49
51
|
};
|
|
50
52
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { useRef, useState, useCallback, useEffect,
|
|
2
|
+
import React, { useRef, useState, useCallback, useEffect, useImperativeHandle, forwardRef, cloneElement, Children, isValidElement } from 'react';
|
|
3
3
|
import { FlatList, View, StyleSheet, Platform, Animated, Easing, useWindowDimensions } from 'react-native';
|
|
4
4
|
import { clamp } from '../../utils/number';
|
|
5
5
|
import { isFiniteNumber } from '../../utils/validate';
|
|
@@ -71,39 +71,21 @@ const SwiperImpl = (props, ref) => {
|
|
|
71
71
|
nativeScrollEndTimerRef.current = null;
|
|
72
72
|
}
|
|
73
73
|
}, []);
|
|
74
|
-
const validChildren =
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}, [children]);
|
|
85
|
-
const itemsData = useMemo(() => {
|
|
86
|
-
if (data) {
|
|
87
|
-
return data;
|
|
88
|
-
}
|
|
89
|
-
if (validChildren.length > 0) {
|
|
90
|
-
return validChildren.map((_, idx) => ({
|
|
91
|
-
type: 'child',
|
|
92
|
-
index: idx
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
return [];
|
|
96
|
-
}, [data, validChildren]);
|
|
74
|
+
const validChildren = children ? Children.toArray(children).filter(child => {
|
|
75
|
+
if (! /*#__PURE__*/isValidElement(child)) return false;
|
|
76
|
+
if (child.type === SwiperItem) return true;
|
|
77
|
+
const type = child.type;
|
|
78
|
+
return type.displayName === 'SwiperItem';
|
|
79
|
+
}) : [];
|
|
80
|
+
const itemsData = data ? data : validChildren.length > 0 ? validChildren.map((_, idx) => ({
|
|
81
|
+
type: 'child',
|
|
82
|
+
index: idx
|
|
83
|
+
})) : [];
|
|
97
84
|
const count = itemsData.length;
|
|
98
85
|
const slideRatio = slideSizePct / 100;
|
|
99
86
|
const offsetRatio = trackOffsetPct / 100;
|
|
100
87
|
const shouldLoop = loop && count > 1 && slideRatio * (count - 1) >= 1;
|
|
101
|
-
const loopData =
|
|
102
|
-
if (!shouldLoop || count <= 1) {
|
|
103
|
-
return itemsData;
|
|
104
|
-
}
|
|
105
|
-
return [...itemsData.slice(-1), ...itemsData, ...itemsData.slice(0, 1)];
|
|
106
|
-
}, [shouldLoop, itemsData, count]);
|
|
88
|
+
const loopData = !shouldLoop || count <= 1 ? itemsData : [...itemsData.slice(-1), ...itemsData, ...itemsData.slice(0, 1)];
|
|
107
89
|
const displayData = shouldLoop ? loopData : itemsData;
|
|
108
90
|
const displayCount = displayData.length;
|
|
109
91
|
const getDisplayIndex = useCallback(index => {
|
|
@@ -127,15 +109,12 @@ const SwiperImpl = (props, ref) => {
|
|
|
127
109
|
const crossAxisMeasured = vertical ? containerLayout.width : containerLayout.height;
|
|
128
110
|
const crossAxisSize = crossAxisMeasured > 0 ? crossAxisMeasured : undefined;
|
|
129
111
|
const slideSizeValue = (vertical ? containerHeight : containerWidth) * slideRatio;
|
|
130
|
-
const itemSizeStyle =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
return style;
|
|
138
|
-
}, [vertical, slideSizeValue, crossAxisSize, autoHeight]);
|
|
112
|
+
const itemSizeStyle = {
|
|
113
|
+
[vertical ? 'height' : 'width']: slideSizeValue
|
|
114
|
+
};
|
|
115
|
+
if (crossAxisSize != null && !(autoHeight && !vertical)) {
|
|
116
|
+
itemSizeStyle[vertical ? 'width' : 'height'] = crossAxisSize;
|
|
117
|
+
}
|
|
139
118
|
const mainAxisMeasured = vertical ? containerLayout.height : containerLayout.width;
|
|
140
119
|
const trackOffsetPx = mainAxisMeasured > 0 ? mainAxisMeasured * offsetRatio : 0;
|
|
141
120
|
const nativeTrackContentPaddingStyle = !trackOffsetPx ? undefined : vertical ? {
|
|
@@ -149,12 +128,12 @@ const SwiperImpl = (props, ref) => {
|
|
|
149
128
|
const mainAxisSize = vertical ? containerHeight : containerWidth;
|
|
150
129
|
const nonLoopMinOffset = stuckAtBoundaryEnabled ? trackOffsetPx : 0;
|
|
151
130
|
const nonLoopMaxOffset = stuckAtBoundaryEnabled ? Math.max(nonLoopMinOffset, trackOffsetPx + count * slideSizeValue - mainAxisSize, 0) : Math.max(0, (count - 1) * slideSizeValue);
|
|
152
|
-
const nonLoopSnapOffsets =
|
|
131
|
+
const nonLoopSnapOffsets = (() => {
|
|
153
132
|
if (!stuckAtBoundaryEnabled || count <= 1) return null;
|
|
154
133
|
const offsets = new Array(count);
|
|
155
134
|
for (let i = 0; i < count; i += 1) offsets[i] = i === 0 ? nonLoopMinOffset : i === count - 1 ? nonLoopMaxOffset : slideSizeValue * i;
|
|
156
135
|
return offsets;
|
|
157
|
-
}
|
|
136
|
+
})();
|
|
158
137
|
const getInitialIndex = useCallback(() => {
|
|
159
138
|
const initial = clamp(initialSwipeValue, 0, count - 1);
|
|
160
139
|
return shouldLoop ? initial + 1 : initial;
|
|
@@ -672,11 +651,11 @@ const SwiperImpl = (props, ref) => {
|
|
|
672
651
|
index
|
|
673
652
|
};
|
|
674
653
|
}, [nonLoopSnapOffsets, shouldLoop, slideSizeValue]);
|
|
675
|
-
const snapToOffsets =
|
|
654
|
+
const snapToOffsets = (() => {
|
|
676
655
|
if (slideSizePct === 100 && trackOffsetPct === 0) return undefined;
|
|
677
656
|
if (!shouldLoop && nonLoopSnapOffsets) return nonLoopSnapOffsets;
|
|
678
657
|
return displayData.map((_, index) => slideSizeValue * index);
|
|
679
|
-
}
|
|
658
|
+
})();
|
|
680
659
|
useEffect(() => {
|
|
681
660
|
if (!isWeb) return;
|
|
682
661
|
const initialIndex = getInitialIndex();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef, useCallback,
|
|
1
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
2
2
|
import { Animated, PanResponder } from 'react-native';
|
|
3
3
|
import { clamp } from '../../utils';
|
|
4
4
|
import { stopWebEvent } from './utils';
|
|
@@ -97,23 +97,20 @@ export const useSwiperWeb = ({
|
|
|
97
97
|
(latest.vertical ? webTranslateXAnim : webTranslateYAnim).stopAnimation();
|
|
98
98
|
webOffsetRef.current = nextOffset;
|
|
99
99
|
}, []);
|
|
100
|
-
const webTrackTransform =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}];
|
|
115
|
-
}, [trackOffsetPx, vertical, webTranslateXAnim, webTranslateYAnim]);
|
|
116
|
-
const panResponder = useMemo(() => {
|
|
100
|
+
const webTrackTransform = vertical ? trackOffsetPx ? [{
|
|
101
|
+
translateY: trackOffsetPx
|
|
102
|
+
}, {
|
|
103
|
+
translateY: webTranslateYAnim
|
|
104
|
+
}] : [{
|
|
105
|
+
translateY: webTranslateYAnim
|
|
106
|
+
}] : trackOffsetPx ? [{
|
|
107
|
+
translateX: trackOffsetPx
|
|
108
|
+
}, {
|
|
109
|
+
translateX: webTranslateXAnim
|
|
110
|
+
}] : [{
|
|
111
|
+
translateX: webTranslateXAnim
|
|
112
|
+
}];
|
|
113
|
+
const panResponder = (() => {
|
|
117
114
|
if (!isWeb) return null;
|
|
118
115
|
return PanResponder.create({
|
|
119
116
|
onStartShouldSetPanResponder: () => false,
|
|
@@ -171,7 +168,7 @@ export const useSwiperWeb = ({
|
|
|
171
168
|
panLatestRef.current.onDragEnd?.();
|
|
172
169
|
}
|
|
173
170
|
});
|
|
174
|
-
}
|
|
171
|
+
})();
|
|
175
172
|
useEffect(() => {
|
|
176
173
|
return () => {
|
|
177
174
|
cancelWebRaf();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { useCallback,
|
|
2
|
+
import React, { useCallback, useState } from 'react';
|
|
3
3
|
import { StyleSheet, View } from 'react-native';
|
|
4
4
|
import { mergeTokensOverride } from '../../design-system';
|
|
5
5
|
import { useControllableValue } from '../../hooks';
|
|
@@ -34,19 +34,16 @@ const TabbarBase = props => {
|
|
|
34
34
|
const placeholder = placeholderProp ?? tokens.defaults.placeholder;
|
|
35
35
|
const iconSize = iconSizeProp ?? tokens.icon.size;
|
|
36
36
|
const enableSafeAreaInsetBottom = safeAreaInsetBottom ?? fixed;
|
|
37
|
-
const items =
|
|
38
|
-
const firstName =
|
|
37
|
+
const items = React.Children.toArray(children).filter(React.isValidElement);
|
|
38
|
+
const firstName = items.length ? items[0].props.name ?? 0 : undefined;
|
|
39
39
|
const [activeValue, setActiveValue] = useControllableValue(props, {
|
|
40
40
|
defaultValue: firstName,
|
|
41
41
|
valuePropName: 'value',
|
|
42
42
|
defaultValuePropName: 'defaultValue',
|
|
43
43
|
trigger: 'onChange'
|
|
44
44
|
});
|
|
45
|
-
const itemNames =
|
|
46
|
-
const currentName =
|
|
47
|
-
if (activeValue === undefined || activeValue === null) return firstName;
|
|
48
|
-
return itemNames.some(name => name === activeValue) ? activeValue : firstName;
|
|
49
|
-
}, [activeValue, firstName, itemNames]);
|
|
45
|
+
const itemNames = items.map((item, index) => item.props.name ?? index);
|
|
46
|
+
const currentName = activeValue === undefined || activeValue === null ? firstName : itemNames.some(name => name === activeValue) ? activeValue : firstName;
|
|
50
47
|
const [barHeight, setBarHeight] = useState(tokens.layout.height);
|
|
51
48
|
const enablePlaceholder = fixed && placeholder;
|
|
52
49
|
const handleLayout = useCallback(event => {
|
|
@@ -55,15 +52,15 @@ const TabbarBase = props => {
|
|
|
55
52
|
setBarHeight(prev => Math.abs(prev - nextHeight) < 0.5 ? prev : nextHeight);
|
|
56
53
|
}, [enablePlaceholder]);
|
|
57
54
|
const onSelect = useCallback((name, index) => setActiveValue(name, index), [setActiveValue]);
|
|
58
|
-
const contextValue =
|
|
55
|
+
const contextValue = {
|
|
59
56
|
activeValue: currentName,
|
|
60
57
|
activeColor: activeColor ?? tokens.colors.active,
|
|
61
58
|
inactiveColor: inactiveColor ?? tokens.colors.inactive,
|
|
62
59
|
fontSize: tokens.typography.fontSize,
|
|
63
60
|
fontWeight: tokens.typography.fontWeight,
|
|
64
61
|
onSelect
|
|
65
|
-
}
|
|
66
|
-
const clonedChildren =
|
|
62
|
+
};
|
|
63
|
+
const clonedChildren = items.map((item, index) => {
|
|
67
64
|
const name = item.props.name ?? index;
|
|
68
65
|
return /*#__PURE__*/React.cloneElement(item, {
|
|
69
66
|
key: item.key ?? name,
|
|
@@ -72,7 +69,7 @@ const TabbarBase = props => {
|
|
|
72
69
|
iconSize,
|
|
73
70
|
tokensOverride: mergeTokensOverride(tokensOverride, item.props.tokensOverride)
|
|
74
71
|
});
|
|
75
|
-
})
|
|
72
|
+
});
|
|
76
73
|
if (items.length === 0) return null;
|
|
77
74
|
const ContentWrapper = enableSafeAreaInsetBottom ? SafeAreaView : View;
|
|
78
75
|
return /*#__PURE__*/React.createElement(React.Fragment, null, enablePlaceholder && /*#__PURE__*/React.createElement(View, {
|
|
@@ -27,9 +27,6 @@ const TabbarItem = props => {
|
|
|
27
27
|
const tokens = useTabbarTokens(tokensOverride);
|
|
28
28
|
const context = useTabbarContext();
|
|
29
29
|
if (!context) {
|
|
30
|
-
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
31
|
-
console.warn('[TabbarItem] 需要作为 Tabbar 的子节点使用。');
|
|
32
|
-
}
|
|
33
30
|
return null;
|
|
34
31
|
}
|
|
35
32
|
const itemName = name ?? index ?? 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { memo, useCallback, useEffect, useImperativeHandle,
|
|
2
|
+
import React, { memo, useCallback, useEffect, useImperativeHandle, useRef, useState, Children, isValidElement, Fragment } from 'react';
|
|
3
3
|
import { Animated, Pressable, StyleSheet, Text, ScrollView, View, Platform } from 'react-native';
|
|
4
4
|
import { useAriaPress, useControllableValue } from '../../hooks';
|
|
5
5
|
import { parseNumberLike } from '../../utils/number';
|
|
@@ -119,10 +119,10 @@ const TabBarItemInner = ({
|
|
|
119
119
|
}, ellipsis && !isJumbo ? styles.ellipsis : null, titleStyle],
|
|
120
120
|
numberOfLines: ellipsis && !isJumbo ? 1 : undefined
|
|
121
121
|
}, renderTitle), isRenderable(renderDescription) && (isText(renderDescription) ? /*#__PURE__*/React.createElement(Text, {
|
|
122
|
-
style: [styles.
|
|
122
|
+
style: [styles.descriptionText, isJumbo ? {
|
|
123
123
|
color: descriptionColor,
|
|
124
124
|
fontSize: tokens.typography.descriptionSize,
|
|
125
|
-
marginTop:
|
|
125
|
+
marginTop: tokens.spacing.jumboDescriptionMarginTop,
|
|
126
126
|
textAlign: 'center',
|
|
127
127
|
backgroundColor: isActive ? tokens.colors.jumboDescriptionActiveBackground : tokens.colors.jumboDescriptionBackground,
|
|
128
128
|
paddingHorizontal: tokens.jumbo.descriptionPaddingHorizontal,
|
|
@@ -131,26 +131,29 @@ const TabBarItemInner = ({
|
|
|
131
131
|
} : {
|
|
132
132
|
color: descriptionColor,
|
|
133
133
|
fontSize: tokens.typography.descriptionSize,
|
|
134
|
-
marginTop:
|
|
134
|
+
marginTop: tokens.spacing.descriptionMarginTop,
|
|
135
135
|
textAlign: 'center'
|
|
136
136
|
}, descriptionStyle]
|
|
137
137
|
}, renderDescription) : /*#__PURE__*/React.createElement(View, {
|
|
138
|
-
style: [styles.
|
|
139
|
-
marginTop:
|
|
138
|
+
style: [styles.descriptionView, isJumbo ? {
|
|
139
|
+
marginTop: tokens.spacing.jumboDescriptionMarginTop,
|
|
140
140
|
alignItems: 'center',
|
|
141
141
|
backgroundColor: isActive ? tokens.colors.jumboDescriptionActiveBackground : tokens.colors.jumboDescriptionBackground,
|
|
142
142
|
paddingHorizontal: tokens.jumbo.descriptionPaddingHorizontal,
|
|
143
143
|
paddingVertical: tokens.jumbo.descriptionPaddingVertical,
|
|
144
144
|
borderRadius: tokens.jumbo.descriptionRadius
|
|
145
145
|
} : {
|
|
146
|
-
marginTop:
|
|
146
|
+
marginTop: tokens.spacing.descriptionMarginTop,
|
|
147
147
|
alignItems: 'center'
|
|
148
148
|
}]
|
|
149
149
|
}, renderDescription)), isRenderable(pane.badge) && /*#__PURE__*/React.createElement(View, {
|
|
150
|
-
style: styles.badge
|
|
150
|
+
style: [styles.badge, {
|
|
151
|
+
marginTop: tokens.spacing.badgeMarginTop
|
|
152
|
+
}]
|
|
151
153
|
}, isText(pane.badge) ? /*#__PURE__*/React.createElement(Text, {
|
|
152
154
|
style: [styles.badgeText, {
|
|
153
|
-
color: tokens.colors.badgeText
|
|
155
|
+
color: tokens.colors.badgeText,
|
|
156
|
+
fontSize: tokens.typography.badgeTextSize
|
|
154
157
|
}]
|
|
155
158
|
}, pane.badge) : pane.badge)));
|
|
156
159
|
};
|
|
@@ -212,7 +215,7 @@ const TabsBaseInner = (props, ref) => {
|
|
|
212
215
|
preventScroll: true
|
|
213
216
|
};
|
|
214
217
|
const isSwipeable = !!swipeableConfig;
|
|
215
|
-
const panes =
|
|
218
|
+
const panes = (() => {
|
|
216
219
|
const result = [];
|
|
217
220
|
let paneIndex = 0;
|
|
218
221
|
const walk = nodes => {
|
|
@@ -224,11 +227,6 @@ const TabsBaseInner = (props, ref) => {
|
|
|
224
227
|
return;
|
|
225
228
|
}
|
|
226
229
|
if (!isTabPaneElement(element)) {
|
|
227
|
-
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
228
|
-
const type = element.type;
|
|
229
|
-
const childName = typeof type === 'string' ? type : type.displayName ?? type.name ?? 'Unknown';
|
|
230
|
-
console.warn('[Tabs] children 只能是 <Tabs.TabPane />,已忽略:', childName);
|
|
231
|
-
}
|
|
232
230
|
return;
|
|
233
231
|
}
|
|
234
232
|
const paneProps = element.props;
|
|
@@ -244,7 +242,7 @@ const TabsBaseInner = (props, ref) => {
|
|
|
244
242
|
};
|
|
245
243
|
walk(children);
|
|
246
244
|
return result;
|
|
247
|
-
}
|
|
245
|
+
})();
|
|
248
246
|
const firstPaneName = panes[0]?.name;
|
|
249
247
|
const [activeValue, setActiveValue] = useControllableValue(props, {
|
|
250
248
|
defaultValue: firstPaneName,
|
|
@@ -257,13 +255,13 @@ const TabsBaseInner = (props, ref) => {
|
|
|
257
255
|
useEffect(() => {
|
|
258
256
|
currentNameRef.current = currentName;
|
|
259
257
|
}, [currentName]);
|
|
260
|
-
const nameIndexMap =
|
|
258
|
+
const nameIndexMap = (() => {
|
|
261
259
|
const map = new Map();
|
|
262
260
|
panes.forEach(pane => {
|
|
263
261
|
map.set(pane.name, pane.index);
|
|
264
262
|
});
|
|
265
263
|
return map;
|
|
266
|
-
}
|
|
264
|
+
})();
|
|
267
265
|
const activeIndex = currentName == null ? -1 : nameIndexMap.get(currentName) ?? -1;
|
|
268
266
|
const visitedRef = useRef(new Set());
|
|
269
267
|
useEffect(() => {
|
|
@@ -312,12 +310,7 @@ const TabsBaseInner = (props, ref) => {
|
|
|
312
310
|
navContentSizeSyncFrameRef.current = null;
|
|
313
311
|
};
|
|
314
312
|
}, []);
|
|
315
|
-
const scrollable =
|
|
316
|
-
if (isBoolean(scrollableProp)) {
|
|
317
|
-
return scrollableProp;
|
|
318
|
-
}
|
|
319
|
-
return panes.length > resolvedSwipeThreshold || ellipsis === false;
|
|
320
|
-
}, [ellipsis, panes.length, resolvedSwipeThreshold, scrollableProp]);
|
|
313
|
+
const scrollable = isBoolean(scrollableProp) ? scrollableProp : panes.length > resolvedSwipeThreshold || ellipsis === false;
|
|
321
314
|
const indicatorColor = color ?? tokens.colors.indicator;
|
|
322
315
|
const indicatorCornerRadius = resolvedLineHeight ? resolvedLineHeight / 2 : tokens.indicator.radius;
|
|
323
316
|
const {
|
|
@@ -386,12 +379,8 @@ const TabsBaseInner = (props, ref) => {
|
|
|
386
379
|
const runBeforeChange = useCallback(name => {
|
|
387
380
|
if (!beforeChange) return Promise.resolve(true);
|
|
388
381
|
try {
|
|
389
|
-
return Promise.resolve(beforeChange(name)).then(res => res !== false).catch(
|
|
390
|
-
if (typeof __DEV__ !== 'undefined' && __DEV__) console.warn('[Tabs] beforeChange 抛出异常:', error);
|
|
391
|
-
return false;
|
|
392
|
-
});
|
|
382
|
+
return Promise.resolve(beforeChange(name)).then(res => res !== false).catch(() => false);
|
|
393
383
|
} catch (error) {
|
|
394
|
-
if (typeof __DEV__ !== 'undefined' && __DEV__) console.warn('[Tabs] beforeChange 抛出异常:', error);
|
|
395
384
|
return Promise.resolve(false);
|
|
396
385
|
}
|
|
397
386
|
}, [beforeChange]);
|
|
@@ -490,15 +479,7 @@ const TabsBaseInner = (props, ref) => {
|
|
|
490
479
|
}, [currentName, scrollIntoView]);
|
|
491
480
|
const borderEnabled = border ?? false;
|
|
492
481
|
const showIndicator = type === 'line';
|
|
493
|
-
const navHeight =
|
|
494
|
-
if (type === 'jumbo') {
|
|
495
|
-
return tokens.jumbo.height;
|
|
496
|
-
}
|
|
497
|
-
if (type === 'card') {
|
|
498
|
-
return tokens.card.height;
|
|
499
|
-
}
|
|
500
|
-
return tokens.tabList.height;
|
|
501
|
-
}, [type, tokens]);
|
|
482
|
+
const navHeight = type === 'jumbo' ? tokens.jumbo.height : type === 'card' ? tokens.card.height : tokens.tabList.height;
|
|
502
483
|
const navPaddingBottom = Platform.OS === 'web' && type !== 'line' && type !== 'card' ? tokens.tabList.paddingBottom : 0;
|
|
503
484
|
const indicatorBottom = showIndicator ? type === 'line' ? 0 : tokens.indicator.offset : 0;
|
|
504
485
|
if (panes.length === 0) {
|
|
@@ -572,7 +553,9 @@ const TabsBaseInner = (props, ref) => {
|
|
|
572
553
|
backgroundColor: background
|
|
573
554
|
}, tabBarStyle]
|
|
574
555
|
}, navLeft && /*#__PURE__*/React.createElement(View, {
|
|
575
|
-
style: styles.navSide
|
|
556
|
+
style: [styles.navSide, {
|
|
557
|
+
paddingHorizontal: tokens.spacing.navSidePaddingHorizontal
|
|
558
|
+
}]
|
|
576
559
|
}, navLeft), /*#__PURE__*/React.createElement(View, {
|
|
577
560
|
style: [styles.nav, {
|
|
578
561
|
minHeight: navHeight + navPaddingBottom,
|
|
@@ -586,7 +569,9 @@ const TabsBaseInner = (props, ref) => {
|
|
|
586
569
|
} : null],
|
|
587
570
|
onLayout: handleNavContainerLayout
|
|
588
571
|
}, navBody), navRight && /*#__PURE__*/React.createElement(View, {
|
|
589
|
-
style: styles.navSide
|
|
572
|
+
style: [styles.navSide, {
|
|
573
|
+
paddingHorizontal: tokens.spacing.navSidePaddingHorizontal
|
|
574
|
+
}]
|
|
590
575
|
}, navRight));
|
|
591
576
|
const paneNodes = panes.map(pane => {
|
|
592
577
|
const isActive = pane.name === currentName;
|
|
@@ -629,7 +614,9 @@ const TabsBaseInner = (props, ref) => {
|
|
|
629
614
|
style: [styles.container, style],
|
|
630
615
|
onLayout: handleContainerLayout
|
|
631
616
|
}), navContent, navBottom && /*#__PURE__*/React.createElement(View, {
|
|
632
|
-
style: styles.navBottom
|
|
617
|
+
style: [styles.navBottom, {
|
|
618
|
+
marginTop: tokens.spacing.navBottomMarginTop
|
|
619
|
+
}]
|
|
633
620
|
}, navBottom), contentNode);
|
|
634
621
|
};
|
|
635
622
|
const styles = StyleSheet.create({
|
|
@@ -655,12 +642,8 @@ const styles = StyleSheet.create({
|
|
|
655
642
|
navContentStatic: {
|
|
656
643
|
flex: 1
|
|
657
644
|
},
|
|
658
|
-
navSide: {
|
|
659
|
-
|
|
660
|
-
},
|
|
661
|
-
navBottom: {
|
|
662
|
-
marginTop: 8
|
|
663
|
-
},
|
|
645
|
+
navSide: {},
|
|
646
|
+
navBottom: {},
|
|
664
647
|
labelWrapper: {
|
|
665
648
|
justifyContent: 'center',
|
|
666
649
|
alignItems: 'center',
|
|
@@ -688,20 +671,16 @@ const styles = StyleSheet.create({
|
|
|
688
671
|
title: {
|
|
689
672
|
includeFontPadding: false
|
|
690
673
|
},
|
|
691
|
-
|
|
692
|
-
marginTop: 2,
|
|
674
|
+
descriptionText: {
|
|
693
675
|
includeFontPadding: false
|
|
694
676
|
},
|
|
677
|
+
descriptionView: {},
|
|
695
678
|
ellipsis: {
|
|
696
679
|
maxWidth: '100%',
|
|
697
680
|
flexShrink: 1
|
|
698
681
|
},
|
|
699
|
-
badge: {
|
|
700
|
-
|
|
701
|
-
},
|
|
702
|
-
badgeText: {
|
|
703
|
-
fontSize: 10
|
|
704
|
-
},
|
|
682
|
+
badge: {},
|
|
683
|
+
badgeText: {},
|
|
705
684
|
indicator: {
|
|
706
685
|
position: 'absolute',
|
|
707
686
|
bottom: 0,
|
|
@@ -61,7 +61,15 @@ const createTokens = foundations => {
|
|
|
61
61
|
titleActiveWeight: foundations.typography.weight.semiBold,
|
|
62
62
|
descriptionSize: fontSize.xs,
|
|
63
63
|
jumboTitleSize: fontSize.md,
|
|
64
|
-
jumboLineHeight: Math.round(fontSize.md * 1.6)
|
|
64
|
+
jumboLineHeight: Math.round(fontSize.md * 1.6),
|
|
65
|
+
badgeTextSize: fontSize.xxs
|
|
66
|
+
},
|
|
67
|
+
spacing: {
|
|
68
|
+
navSidePaddingHorizontal: spacing.sm,
|
|
69
|
+
navBottomMarginTop: spacing.sm,
|
|
70
|
+
descriptionMarginTop: spacing.xxs,
|
|
71
|
+
jumboDescriptionMarginTop: spacing.sm,
|
|
72
|
+
badgeMarginTop: spacing.xs
|
|
65
73
|
},
|
|
66
74
|
indicator: {
|
|
67
75
|
height: 3,
|
|
@@ -69,7 +69,11 @@ export const useTabsScroll = ({
|
|
|
69
69
|
const listenerId = navScrollX.addListener(({
|
|
70
70
|
value
|
|
71
71
|
}) => {
|
|
72
|
+
const prev = navLastScrollXRef.current;
|
|
72
73
|
navLastScrollXRef.current = value;
|
|
74
|
+
if (Math.abs(value - prev) < 0.5) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
73
77
|
navScrollRef.current?.scrollTo({
|
|
74
78
|
x: value,
|
|
75
79
|
y: 0,
|
|
@@ -58,7 +58,7 @@ export const Toast = props => {
|
|
|
58
58
|
});
|
|
59
59
|
const prevVisibleRef = useRef(visible);
|
|
60
60
|
const closingRef = useRef(false);
|
|
61
|
-
const positionOffset = windowHeight > 0 ? Math.round(windowHeight *
|
|
61
|
+
const positionOffset = windowHeight > 0 ? Math.round(windowHeight * tokens.positionOffsetRatio) : tokens.positionOffsetMin;
|
|
62
62
|
const needsSafeAreaTop = safeAreaInsetTopProp !== undefined ? safeAreaInsetTopProp : position === 'top';
|
|
63
63
|
const needsSafeAreaBottom = safeAreaInsetBottomProp !== undefined ? safeAreaInsetBottomProp : position === 'bottom';
|
|
64
64
|
const positionStyle = position === 'top' ? {
|
|
@@ -159,7 +159,7 @@ export const Toast = props => {
|
|
|
159
159
|
};
|
|
160
160
|
const toastStyle = {
|
|
161
161
|
borderRadius: tokens.radius,
|
|
162
|
-
opacity: closeOnClick && toastPress.states.pressed ?
|
|
162
|
+
opacity: closeOnClick && toastPress.states.pressed ? tokens.pressedOpacity : animated,
|
|
163
163
|
backgroundColor: tokens.colors.variants[type],
|
|
164
164
|
maxWidth: tokens.maxWidth,
|
|
165
165
|
...boxStyle
|
|
@@ -167,13 +167,17 @@ export const Toast = props => {
|
|
|
167
167
|
if (!mounted) return null;
|
|
168
168
|
const hasMessage = message !== undefined && message !== null && message !== false && message !== '';
|
|
169
169
|
return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(View, {
|
|
170
|
-
style: [styles.backdrop,
|
|
170
|
+
style: [styles.backdrop, {
|
|
171
|
+
backgroundColor: tokens.colors.transparent
|
|
172
|
+
}, positionStyle, stackZIndex ? {
|
|
171
173
|
zIndex: stackZIndex
|
|
172
174
|
} : undefined],
|
|
173
175
|
pointerEvents: forbidClick || overlay || closeOnClick ? 'auto' : 'none'
|
|
174
176
|
}, overlay || forbidClick ? /*#__PURE__*/React.createElement(Pressable, {
|
|
175
177
|
testID: "rv-toast-overlay",
|
|
176
|
-
style: [styles.overlay,
|
|
178
|
+
style: [styles.overlay, {
|
|
179
|
+
backgroundColor: tokens.colors.transparent
|
|
180
|
+
}, overlay && {
|
|
177
181
|
backgroundColor: colors.backdrop
|
|
178
182
|
}, overlayStyle],
|
|
179
183
|
pointerEvents: "auto",
|
|
@@ -209,12 +213,10 @@ export const Toast = props => {
|
|
|
209
213
|
const styles = StyleSheet.create({
|
|
210
214
|
backdrop: {
|
|
211
215
|
flex: 1,
|
|
212
|
-
alignItems: 'center'
|
|
213
|
-
backgroundColor: 'transparent'
|
|
216
|
+
alignItems: 'center'
|
|
214
217
|
},
|
|
215
218
|
overlay: {
|
|
216
|
-
...StyleSheet.absoluteFillObject
|
|
217
|
-
backgroundColor: 'transparent'
|
|
219
|
+
...StyleSheet.absoluteFillObject
|
|
218
220
|
},
|
|
219
221
|
toast: {
|
|
220
222
|
alignItems: 'center',
|
|
@@ -11,7 +11,8 @@ export const createToastTokens = foundations => {
|
|
|
11
11
|
success: backdrop,
|
|
12
12
|
fail: backdrop,
|
|
13
13
|
loading: backdrop
|
|
14
|
-
}
|
|
14
|
+
},
|
|
15
|
+
transparent: 'transparent'
|
|
15
16
|
},
|
|
16
17
|
fontSize: foundations.fontSize.sm,
|
|
17
18
|
lineHeight: Math.round(foundations.fontSize.sm * foundations.typography.lineHeightMultiplier),
|
|
@@ -25,6 +26,9 @@ export const createToastTokens = foundations => {
|
|
|
25
26
|
defaultPadding: foundations.spacing.lg,
|
|
26
27
|
defaultWidth: 88,
|
|
27
28
|
defaultMinHeight: 88,
|
|
29
|
+
pressedOpacity: 0.85,
|
|
30
|
+
positionOffsetRatio: 0.2,
|
|
31
|
+
positionOffsetMin: 60,
|
|
28
32
|
animationDuration: 160
|
|
29
33
|
};
|
|
30
34
|
};
|