@momo-kits/foundation 0.168.1-beta.39 → 0.168.1-beta.40
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/Application/BottomSheet.tsx +398 -86
- package/Application/BottomTab/BottomTabBar.tsx +275 -215
- package/Application/BottomTab/CustomBottomTabItem.tsx +107 -131
- package/Application/BottomTab/DuoBarCompression.tsx +28 -14
- package/Application/BottomTab/DuoTabBar.tsx +540 -32
- package/Application/BottomTab/TabBarIcon.tsx +72 -146
- package/Application/BottomTab/index.tsx +353 -89
- package/Application/BottomTab/useLiquidSelection.ts +374 -0
- package/Application/Components/BackgroundImageView.tsx +0 -4
- package/Application/Components/DuoGlassBackground.tsx +5 -7
- package/Application/Components/HeaderAnimated.tsx +13 -41
- package/Application/Components/HeaderBackground.tsx +3 -20
- package/Application/Components/HeaderExtendHeader.tsx +46 -66
- package/Application/Components/HeaderLeft.tsx +18 -5
- package/Application/Components/HeaderRight.tsx +529 -8
- package/Application/Components/HeaderTitle.tsx +579 -16
- package/Application/Components/NavigationButton.tsx +11 -18
- package/Application/Components/SearchHeader.tsx +18 -38
- package/Application/Localize.ts +0 -7
- package/Application/ModalScreen.tsx +18 -41
- package/Application/Navigation.ts +17 -15
- package/Application/NavigationContainer.tsx +21 -23
- package/Application/Navigator.ts +48 -20
- package/Application/ScaleSizeProvider.tsx +6 -13
- package/Application/StackScreen.tsx +172 -27
- package/Application/TooltipPortal.tsx +5 -12
- package/Application/WidgetContainer.tsx +7 -20
- package/Application/device.ts +52 -0
- package/Application/index.ts +1 -23
- package/Application/types.ts +242 -17
- package/Application/utils.tsx +493 -0
- package/Badge/Badge.tsx +0 -5
- package/Badge/BadgeDot.tsx +0 -1
- package/Badge/BadgeDotAnimation.tsx +7 -15
- package/Badge/BadgeRibbon.tsx +39 -47
- package/Badge/Shape.tsx +0 -2
- package/Badge/styles.ts +0 -2
- package/Badge/types.ts +2 -2
- package/Button/index.tsx +152 -21
- package/Button/styles.ts +1 -1
- package/CheckBox/index.tsx +6 -5
- package/Consts/theme.ts +10 -10
- package/Context/index.ts +1 -5
- package/Divider/DashDivider.tsx +11 -11
- package/Divider/index.tsx +7 -21
- package/FoundationList/index.tsx +0 -4
- package/Icon/index.tsx +6 -6
- package/Icon/types.ts +1 -1
- package/IconButton/index.tsx +12 -4
- package/Image/index.tsx +7 -9
- package/Input/Input.tsx +12 -10
- package/Input/InputDropDown.tsx +13 -10
- package/Input/InputMoney.tsx +152 -45
- package/Input/InputOTP.tsx +34 -36
- package/Input/InputPhoneNumber.tsx +5 -8
- package/Input/InputSearch.tsx +111 -19
- package/Input/InputTextArea.tsx +5 -5
- package/Input/SystemTextInput.tsx +2 -7
- package/Input/TextTyping.tsx +0 -4
- package/Input/common.tsx +17 -31
- package/Input/index.tsx +21 -24
- package/Input/styles.ts +5 -25
- package/Input/utils.ts +12 -14
- package/Layout/Card.tsx +4 -7
- package/Layout/FloatingButton.tsx +21 -26
- package/Layout/Item.tsx +2 -6
- package/Layout/ItemList.tsx +7 -9
- package/Layout/ItemSectionList.tsx +1 -2
- package/Layout/ReservedRegions.tsx +17 -34
- package/Layout/Screen.tsx +696 -122
- package/Layout/Section.tsx +7 -9
- package/Layout/TrackingScope.tsx +0 -1
- package/Layout/index.ts +4 -10
- package/Layout/styles.ts +0 -2
- package/Layout/types.ts +4 -2
- package/Layout/utils.ts +181 -40
- package/Loader/DotLoader.tsx +3 -11
- package/Loader/Loader.tsx +0 -4
- package/Loader/ProgressBar.tsx +6 -3
- package/Loader/Spinner.tsx +3 -11
- package/Loader/styles.ts +0 -4
- package/Loader/utils.ts +7 -11
- package/Pagination/Dot.tsx +0 -4
- package/Pagination/PaginationDot.tsx +0 -1
- package/Pagination/PaginationNumber.tsx +3 -5
- package/Pagination/PaginationScroll.tsx +0 -5
- package/Pagination/PaginationWhiteDot.tsx +0 -1
- package/Pagination/index.tsx +0 -4
- package/Pagination/types.ts +2 -2
- package/Popup/PopupNotify.tsx +102 -94
- package/Popup/PopupPromotion.tsx +11 -9
- package/Popup/types.ts +4 -11
- package/Popup/utils.ts +18 -50
- package/Radio/index.tsx +10 -6
- package/Radio/styles.ts +0 -6
- package/Skeleton/index.tsx +9 -9
- package/Skeleton/styles.ts +0 -1
- package/Switch/index.tsx +0 -1
- package/Tag/index.tsx +4 -8
- package/Tag/types.ts +3 -3
- package/Text/index.tsx +5 -25
- package/Text/styles.ts +1 -1
- package/Text/types.ts +6 -1
- package/Text/utils.ts +4 -20
- package/Title/index.tsx +40 -42
- package/Title/styles.ts +0 -6
- package/ViewBoundary/index.tsx +2 -4
- package/index.ts +6 -0
- package/package.json +1 -2
- package/Application/BottomSheet.hooks.ts +0 -195
- package/Application/BottomSheet.parts.tsx +0 -157
- package/Application/BottomSheet.styles.ts +0 -43
- package/Application/BottomTab/ActiveIndicator.tsx +0 -91
- package/Application/BottomTab/BottomTabBar.styles.ts +0 -65
- package/Application/BottomTab/BottomTabInset.tsx +0 -18
- package/Application/BottomTab/CurvedContainer.tsx +0 -155
- package/Application/BottomTab/DuoRailTabBar.tsx +0 -223
- package/Application/BottomTab/DuoTabBar.styles.ts +0 -81
- package/Application/BottomTab/TabScreen.tsx +0 -160
- package/Application/BottomTab/metrics.ts +0 -164
- package/Application/BottomTab/tabItems.ts +0 -46
- package/Application/BottomTab/usePressLift.ts +0 -32
- package/Application/Components/HeaderRight.styles.ts +0 -146
- package/Application/Components/HeaderTitle.shared.ts +0 -44
- package/Application/Components/HeaderTitle.styles.ts +0 -125
- package/Application/Components/HeaderToolkitAction.tsx +0 -180
- package/Application/Components/SwipeBackHaptic.tsx +0 -95
- package/Application/Components/TitleJourney.tsx +0 -110
- package/Application/Components/TitleLocation.tsx +0 -73
- package/Application/Components/TitleUser.tsx +0 -304
- package/Application/Components/useToolkitActions.tsx +0 -218
- package/Application/ModalIconButton.tsx +0 -66
- package/Application/StackScreen.tracking.ts +0 -143
- package/Application/headerLayout.ts +0 -158
- package/Application/hooks.ts +0 -137
- package/Application/modalLayout.ts +0 -176
- package/Application/navigationOptions.tsx +0 -212
- package/Application/types.header.ts +0 -121
- package/Application/types.tabs.ts +0 -48
- package/Application/types.theme.ts +0 -87
- package/Application/utils.ts +0 -107
- package/Button/utils.ts +0 -133
- package/Input/InputMoneyView.tsx +0 -194
- package/Input/SearchTextTyping.tsx +0 -108
- package/Input/moneyUtils.ts +0 -23
- package/Layout/layoutMetrics.ts +0 -58
- package/Layout/layoutTypes.ts +0 -86
- package/Layout/screenContent.tsx +0 -92
- package/Layout/screenFooter.tsx +0 -63
- package/Layout/screenHeader.tsx +0 -321
- package/Layout/screenQuickReturn.tsx +0 -64
- package/Layout/screenScroll.ts +0 -107
- package/Layout/screenTypes.ts +0 -143
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useContext,
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import {
|
|
9
|
+
CardAnimationContext,
|
|
10
|
+
CardStyleInterpolators,
|
|
11
|
+
StackNavigationOptions,
|
|
12
|
+
TransitionPresets,
|
|
13
|
+
} from '@react-navigation/stack';
|
|
14
|
+
import type {
|
|
15
|
+
StackCardInterpolatedStyle,
|
|
16
|
+
StackCardInterpolationProps,
|
|
17
|
+
} from '@react-navigation/stack';
|
|
18
|
+
import type { NavigationState, PartialState } from '@react-navigation/native';
|
|
19
|
+
import type { HeaderTitleProps, NavigationOptions } from './types';
|
|
20
|
+
import { ApplicationContext } from '../Context';
|
|
21
|
+
import { Colors, Spacing } from '../Consts';
|
|
22
|
+
import { Animated, AppState, NativeModules, Platform } from 'react-native';
|
|
23
|
+
import type { SharedValue } from 'react-native-reanimated';
|
|
24
|
+
import { useSharedValue } from 'react-native-reanimated';
|
|
25
|
+
import {
|
|
26
|
+
MiniAppContext,
|
|
27
|
+
ScreenContext,
|
|
28
|
+
TrackingScopeContext,
|
|
29
|
+
} from '../Context';
|
|
30
|
+
import { HeaderTitle, TitleCustom } from './Components/HeaderTitle';
|
|
31
|
+
import { HeaderBackground } from './Components/HeaderBackground';
|
|
32
|
+
import { HeaderLeft } from './Components/HeaderLeft';
|
|
33
|
+
import { HeaderRight } from './Components/HeaderRight';
|
|
34
|
+
|
|
35
|
+
const SWIPE_BACK_HAPTIC_THRESHOLD = 50;
|
|
36
|
+
|
|
37
|
+
const forStackTransitionWithOverlay = (
|
|
38
|
+
props: StackCardInterpolationProps,
|
|
39
|
+
): StackCardInterpolatedStyle => {
|
|
40
|
+
const { cardStyle } = CardStyleInterpolators.forHorizontalIOS(props);
|
|
41
|
+
return {
|
|
42
|
+
cardStyle,
|
|
43
|
+
shadowStyle: {
|
|
44
|
+
shadowOpacity: props.current.progress.interpolate({
|
|
45
|
+
inputRange: [0, 1],
|
|
46
|
+
outputRange: [0, 0.3],
|
|
47
|
+
extrapolate: 'clamp',
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
overlayStyle: {
|
|
51
|
+
backgroundColor: '#FDEAF4',
|
|
52
|
+
opacity: props.current.progress.interpolate({
|
|
53
|
+
inputRange: [0, 1],
|
|
54
|
+
outputRange: [0, 0.6],
|
|
55
|
+
extrapolate: 'clamp',
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* default options for stack screen
|
|
63
|
+
*/
|
|
64
|
+
const getStackOptions = (): StackNavigationOptions => {
|
|
65
|
+
return {
|
|
66
|
+
headerTitleAlign: 'left',
|
|
67
|
+
headerTitle: props => <HeaderTitle {...props} />,
|
|
68
|
+
headerTitleContainerStyle: {
|
|
69
|
+
marginLeft: 0,
|
|
70
|
+
marginEnd: 0,
|
|
71
|
+
marginStart: 0,
|
|
72
|
+
marginHorizontal: 0,
|
|
73
|
+
marginVertical: 0,
|
|
74
|
+
margin: 0,
|
|
75
|
+
left: Spacing.S,
|
|
76
|
+
},
|
|
77
|
+
headerBackground: (props: any) => <HeaderBackground {...props} />,
|
|
78
|
+
headerLeft: (props: any) => <HeaderLeft {...props} floating />,
|
|
79
|
+
headerRight: (props: any) => <HeaderRight {...props} floating />,
|
|
80
|
+
headerTintColor: Colors.black_17,
|
|
81
|
+
gestureEnabled: Platform.OS === 'ios',
|
|
82
|
+
...TransitionPresets.SlideFromRightIOS,
|
|
83
|
+
cardStyleInterpolator: forStackTransitionWithOverlay,
|
|
84
|
+
cardOverlayEnabled: true,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* default options for modal screen
|
|
90
|
+
*/
|
|
91
|
+
const getModalOptions = (): StackNavigationOptions => {
|
|
92
|
+
return {
|
|
93
|
+
headerShown: false,
|
|
94
|
+
headerBackground: undefined,
|
|
95
|
+
cardStyle: { backgroundColor: 'transparent' },
|
|
96
|
+
cardOverlayEnabled: true,
|
|
97
|
+
animation: 'none',
|
|
98
|
+
presentation: 'transparentModal',
|
|
99
|
+
gestureEnabled: false,
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* screen owns its back flow (guard popup, custom handler or no back button),
|
|
105
|
+
* so swipe back must not bypass it
|
|
106
|
+
*/
|
|
107
|
+
const hasCustomBackHandling = (params: NavigationOptions) =>
|
|
108
|
+
params.preventBack !== undefined || params.hiddenBack === true;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* build react-navigation options
|
|
112
|
+
*/
|
|
113
|
+
const getOptions = (
|
|
114
|
+
params: NavigationOptions,
|
|
115
|
+
animatedValue?: SharedValue<number>,
|
|
116
|
+
) => {
|
|
117
|
+
let options: StackNavigationOptions = {};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* left header factory
|
|
121
|
+
*/
|
|
122
|
+
if (
|
|
123
|
+
typeof params.onPressLeftHeader === 'function' ||
|
|
124
|
+
typeof params.onBackHandler === 'function' ||
|
|
125
|
+
params.preventBack !== undefined ||
|
|
126
|
+
typeof params.hiddenBack === 'boolean'
|
|
127
|
+
) {
|
|
128
|
+
let headerLeft: any = (props: any) => (
|
|
129
|
+
<HeaderLeft
|
|
130
|
+
{...props}
|
|
131
|
+
preventBack={params.preventBack}
|
|
132
|
+
onPressLeftHeader={params.onPressLeftHeader}
|
|
133
|
+
onBackHandler={params.onBackHandler}
|
|
134
|
+
floating
|
|
135
|
+
/>
|
|
136
|
+
);
|
|
137
|
+
if (params.hiddenBack) {
|
|
138
|
+
headerLeft = null;
|
|
139
|
+
options.headerTitleContainerStyle = {
|
|
140
|
+
marginLeft: 0,
|
|
141
|
+
marginEnd: 0,
|
|
142
|
+
marginStart: 0,
|
|
143
|
+
marginHorizontal: 0,
|
|
144
|
+
marginVertical: 0,
|
|
145
|
+
margin: 0,
|
|
146
|
+
left: Spacing.M,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
options = {
|
|
150
|
+
...options,
|
|
151
|
+
headerLeft,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* title
|
|
157
|
+
*/
|
|
158
|
+
if (params.headerTitle) {
|
|
159
|
+
options = {
|
|
160
|
+
...options,
|
|
161
|
+
...exportHeaderTitle(params, animatedValue),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* header right
|
|
167
|
+
*/
|
|
168
|
+
if (params.headerRight) {
|
|
169
|
+
options = {
|
|
170
|
+
...options,
|
|
171
|
+
...{
|
|
172
|
+
headerRight: (props: any) => {
|
|
173
|
+
return (
|
|
174
|
+
<HeaderRight {...props} headerRight={params.headerRight} floating />
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* only ever turns swipe back off, screens opt in via gestureEnabled
|
|
183
|
+
*/
|
|
184
|
+
if (params.gestureEnabled === undefined && hasCustomBackHandling(params)) {
|
|
185
|
+
options.gestureEnabled = false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
...params,
|
|
190
|
+
...options,
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const exportHeaderTitle = (
|
|
195
|
+
params: NavigationOptions,
|
|
196
|
+
animatedValue?: SharedValue<number>,
|
|
197
|
+
): StackNavigationOptions => {
|
|
198
|
+
if (typeof params.headerTitle === 'object') {
|
|
199
|
+
return {
|
|
200
|
+
headerTitleAlign: 'left',
|
|
201
|
+
headerTitle: (props: any) => {
|
|
202
|
+
return (
|
|
203
|
+
<TitleCustom
|
|
204
|
+
{...props}
|
|
205
|
+
{...(params.headerTitle as HeaderTitleProps)}
|
|
206
|
+
animatedValue={animatedValue}
|
|
207
|
+
/>
|
|
208
|
+
);
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
} else if (typeof params.headerTitle === 'string') {
|
|
212
|
+
return {
|
|
213
|
+
headerTitle: (props: any) => (
|
|
214
|
+
<HeaderTitle
|
|
215
|
+
{...props}
|
|
216
|
+
children={params.headerTitle}
|
|
217
|
+
animatedValue={animatedValue}
|
|
218
|
+
/>
|
|
219
|
+
),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return {};
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const setAutomationID = (accessibilityLabel = '') => {
|
|
226
|
+
if (Platform.OS === 'ios') {
|
|
227
|
+
return {
|
|
228
|
+
accessible: true,
|
|
229
|
+
testID: accessibilityLabel,
|
|
230
|
+
accessibilityLabel: undefined,
|
|
231
|
+
};
|
|
232
|
+
} else {
|
|
233
|
+
return {
|
|
234
|
+
accessibilityLabel,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const useComponentId = (componentName: string, accessibilityLabel?: string) => {
|
|
240
|
+
const app = useContext<any>(MiniAppContext);
|
|
241
|
+
const screen = useContext<any>(ScreenContext);
|
|
242
|
+
const { scopeName } = useContext<any>(TrackingScopeContext);
|
|
243
|
+
|
|
244
|
+
const scope = scopeName ? `${scopeName}/` : '';
|
|
245
|
+
|
|
246
|
+
const componentId = useMemo(() => {
|
|
247
|
+
if (accessibilityLabel) {
|
|
248
|
+
return accessibilityLabel;
|
|
249
|
+
}
|
|
250
|
+
return `${app.appId}/${app.code}/${screen.screenName}/${scope}${componentName}`;
|
|
251
|
+
}, [
|
|
252
|
+
accessibilityLabel,
|
|
253
|
+
app.appId,
|
|
254
|
+
app.code,
|
|
255
|
+
screen.screenName,
|
|
256
|
+
scope,
|
|
257
|
+
componentName,
|
|
258
|
+
]);
|
|
259
|
+
|
|
260
|
+
return { componentId };
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const useAppState = () => {
|
|
264
|
+
const isBackgroundToForeground = useRef(false);
|
|
265
|
+
const appState = useRef(AppState.currentState);
|
|
266
|
+
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
const subscription = AppState.addEventListener('change', nextAppState => {
|
|
269
|
+
isBackgroundToForeground.current = !!(
|
|
270
|
+
appState.current.match(/inactive|background/) &&
|
|
271
|
+
nextAppState === 'active'
|
|
272
|
+
);
|
|
273
|
+
appState.current = nextAppState;
|
|
274
|
+
|
|
275
|
+
if (isBackgroundToForeground.current) {
|
|
276
|
+
setTimeout(() => {
|
|
277
|
+
isBackgroundToForeground.current = false;
|
|
278
|
+
}, 100);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
return () => {
|
|
283
|
+
subscription.remove();
|
|
284
|
+
};
|
|
285
|
+
}, []);
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
isBackgroundToForeground: isBackgroundToForeground.current,
|
|
289
|
+
appState: appState.current,
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* screens the focused navigation branch can still pop.
|
|
295
|
+
* only stack navigators count, switching bottom tab is not a back step
|
|
296
|
+
*/
|
|
297
|
+
const getStackDepth = (
|
|
298
|
+
state?: NavigationState | PartialState<NavigationState>,
|
|
299
|
+
): number => {
|
|
300
|
+
const routes = state?.routes;
|
|
301
|
+
if (!routes?.length) {
|
|
302
|
+
return 0;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const index = state?.index ?? routes.length - 1;
|
|
306
|
+
const depth = state?.type === 'stack' ? index : 0;
|
|
307
|
+
|
|
308
|
+
return depth + getStackDepth(routes[index]?.state);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* report back ownership to the native container: `true` when the mini app sits
|
|
313
|
+
* on its root screen and native may dismiss the rootview, `false` while
|
|
314
|
+
* react-navigation still has screens (or a modal / bottom sheet) to pop.
|
|
315
|
+
*/
|
|
316
|
+
const useNativeCanGoBack = () => {
|
|
317
|
+
const lastValue = useRef<boolean | undefined>(undefined);
|
|
318
|
+
|
|
319
|
+
return useCallback(
|
|
320
|
+
(state?: NavigationState | PartialState<NavigationState>) => {
|
|
321
|
+
const canDismiss = getStackDepth(state) === 0;
|
|
322
|
+
if (lastValue.current === canDismiss) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const setCanGoBack = NativeModules?.MiniAppModule?.setCanGoBack;
|
|
327
|
+
if (typeof setCanGoBack !== 'function') {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
lastValue.current = canDismiss;
|
|
332
|
+
try {
|
|
333
|
+
setCanGoBack(canDismiss);
|
|
334
|
+
} catch (error) {
|
|
335
|
+
console.warn('[NavigationContainer] setCanGoBack failed:', error);
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
[],
|
|
339
|
+
);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Union of the two animation runtimes an internal foundation component might
|
|
344
|
+
* receive. Public Screen props still accept React Native Animated.Value only;
|
|
345
|
+
* this type keeps lower-level header/floating components compatible while they
|
|
346
|
+
* render with reanimated.
|
|
347
|
+
*/
|
|
348
|
+
export type AnimatedCompatValue = Animated.Value | SharedValue<number>;
|
|
349
|
+
|
|
350
|
+
const isRNAnimatedValue = (v: unknown): v is Animated.Value =>
|
|
351
|
+
!!v &&
|
|
352
|
+
typeof (v as Animated.Value).setValue === 'function' &&
|
|
353
|
+
typeof (v as Animated.Value).interpolate === 'function';
|
|
354
|
+
|
|
355
|
+
const isSharedValue = (v: unknown): v is SharedValue<number> =>
|
|
356
|
+
!!v && !isRNAnimatedValue(v) && 'value' in (v as object);
|
|
357
|
+
|
|
358
|
+
const useNormalizedSharedValue = (
|
|
359
|
+
input?: AnimatedCompatValue,
|
|
360
|
+
): SharedValue<number> => {
|
|
361
|
+
const fallback = useSharedValue(0);
|
|
362
|
+
|
|
363
|
+
useEffect(() => {
|
|
364
|
+
if (!isRNAnimatedValue(input)) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const id = input.addListener(({ value }) => {
|
|
368
|
+
fallback.value = value;
|
|
369
|
+
});
|
|
370
|
+
return () => input.removeListener(id);
|
|
371
|
+
}, [input, fallback]);
|
|
372
|
+
|
|
373
|
+
if (isSharedValue(input)) {
|
|
374
|
+
return input;
|
|
375
|
+
}
|
|
376
|
+
return fallback;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* `current.progress` is `gesture.interpolate(...)` built by CardStack
|
|
381
|
+
* (@react-navigation/stack 7.4.2, views/Stack/CardStack.tsx `getProgressFromGesture`).
|
|
382
|
+
* Only `Animated.Value.addListener` bridges native driver updates back to js, so the raw
|
|
383
|
+
* translation has to be read off the interpolation's parent.
|
|
384
|
+
*
|
|
385
|
+
* Reaches into a private field. Every hop is optional and duck typed, so a shape change in
|
|
386
|
+
* a future @react-navigation/stack degrades to "no haptic" rather than a crash.
|
|
387
|
+
*/
|
|
388
|
+
const getSwipeGestureValue = (
|
|
389
|
+
progress: Animated.AnimatedInterpolation<number> | undefined,
|
|
390
|
+
): Animated.Value | undefined => {
|
|
391
|
+
const parent = (progress as { _parent?: unknown } | undefined)?._parent as
|
|
392
|
+
| Animated.Value
|
|
393
|
+
| undefined;
|
|
394
|
+
|
|
395
|
+
const isListenable =
|
|
396
|
+
typeof parent?.addListener === 'function' &&
|
|
397
|
+
typeof parent?.removeListener === 'function';
|
|
398
|
+
return isListenable ? parent : undefined;
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const readAnimatedValue = (node: unknown, fallback: number): number => {
|
|
402
|
+
const value = (node as { __getValue?: () => unknown } | undefined)?.__getValue?.();
|
|
403
|
+
return typeof value === 'number' ? value : fallback;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Haptic tick for the iOS swipe back gesture.
|
|
408
|
+
*
|
|
409
|
+
* Deliberately a leaf that renders nothing. Consuming `CardAnimationContext` re-renders on
|
|
410
|
+
* every `Card` render, and an earlier version put that on `StackScreen` itself — which then
|
|
411
|
+
* re-rendered the whole screen mid gesture and cost the pop: `Card` defers `onClose()` by
|
|
412
|
+
* 32ms and clears that timer from `animate()`, which `componentDidUpdate` re-enters on any
|
|
413
|
+
* render in the window. Keeping the subscription in a null leaf isolates it.
|
|
414
|
+
*
|
|
415
|
+
* Both listeners are installed on mount, never lazily inside the gesture: on the New
|
|
416
|
+
* Architecture `addListener` queues `startListeningToAnimatedNodeValue` via
|
|
417
|
+
* `queueOperationBlock`, and that queue is only drained by a React mount commit — which
|
|
418
|
+
* never happens during a native driven pan.
|
|
419
|
+
*/
|
|
420
|
+
const SwipeBackHaptic = () => {
|
|
421
|
+
const { navigator } = useContext<any>(ApplicationContext);
|
|
422
|
+
const animation = useContext(CardAnimationContext);
|
|
423
|
+
const hasFired = useRef(false);
|
|
424
|
+
|
|
425
|
+
useEffect(() => {
|
|
426
|
+
if (Platform.OS !== 'ios' || !animation) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const { swiping, inverted, current } = animation;
|
|
431
|
+
const gesture = getSwipeGestureValue(current?.progress);
|
|
432
|
+
if (!gesture || typeof swiping?.addListener !== 'function') {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
let isSwiping = readAnimatedValue(swiping, 0) === 1;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* sign, not magnitude: a leftward overdrag reports a negative translation and must
|
|
440
|
+
* not count as progress toward dismissal
|
|
441
|
+
*/
|
|
442
|
+
const direction = readAnimatedValue(inverted, 1);
|
|
443
|
+
|
|
444
|
+
const swipingListener = swiping.addListener(({ value }) => {
|
|
445
|
+
isSwiping = value === 1;
|
|
446
|
+
if (!isSwiping) {
|
|
447
|
+
hasFired.current = false;
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
const gestureListener = gesture.addListener(({ value: translation }) => {
|
|
452
|
+
if (!isSwiping) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (translation * direction < SWIPE_BACK_HAPTIC_THRESHOLD) {
|
|
457
|
+
hasFired.current = false;
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (!hasFired.current) {
|
|
462
|
+
hasFired.current = true;
|
|
463
|
+
navigator?.maxApi?.triggerEventVibration?.('light');
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
return () => {
|
|
468
|
+
gesture.removeListener(gestureListener);
|
|
469
|
+
swiping.removeListener(swipingListener);
|
|
470
|
+
};
|
|
471
|
+
}, [animation, navigator]);
|
|
472
|
+
|
|
473
|
+
return null;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
const isWhiteListDesignSystem = (context: any): boolean => {
|
|
477
|
+
return context?.designSystemConfig?.isWhiteListDesignSystem === true;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
export {
|
|
481
|
+
getStackOptions,
|
|
482
|
+
getModalOptions,
|
|
483
|
+
getOptions,
|
|
484
|
+
getStackDepth,
|
|
485
|
+
exportHeaderTitle,
|
|
486
|
+
setAutomationID,
|
|
487
|
+
useComponentId,
|
|
488
|
+
useAppState,
|
|
489
|
+
useNativeCanGoBack,
|
|
490
|
+
useNormalizedSharedValue,
|
|
491
|
+
SwipeBackHaptic,
|
|
492
|
+
isWhiteListDesignSystem,
|
|
493
|
+
};
|
package/Badge/Badge.tsx
CHANGED
|
@@ -7,11 +7,6 @@ import { BadgeProps } from './types';
|
|
|
7
7
|
import { Colors, Radius, Spacing } from '../Consts';
|
|
8
8
|
import { Text, useScaleSize } from '../Text';
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Label or count badge; counts over 99 show "99+". Counts use the error color,
|
|
12
|
-
* labels the warning color, and `backgroundColor` applies only if it's a
|
|
13
|
-
* `Colors.*_03` token.
|
|
14
|
-
*/
|
|
15
10
|
const Badge: FC<BadgeProps> = ({
|
|
16
11
|
label = '',
|
|
17
12
|
style,
|
package/Badge/BadgeDot.tsx
CHANGED
|
@@ -4,7 +4,6 @@ import { BadgeDotProps } from './types';
|
|
|
4
4
|
import styles from './styles';
|
|
5
5
|
import { MiniAppContext } from '../Context';
|
|
6
6
|
|
|
7
|
-
/** Static red notification dot with a white ring, `large` or `small`. */
|
|
8
7
|
const BadgeDot: FC<BadgeDotProps> = ({ size = 'large', style }) => {
|
|
9
8
|
const context = useContext<any>(MiniAppContext);
|
|
10
9
|
let dotStyle;
|
|
@@ -14,10 +14,6 @@ import styles from './styles';
|
|
|
14
14
|
|
|
15
15
|
const DURATION = 500;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Red notification dot that pulses with a spring and emits an expanding,
|
|
19
|
-
* fading wave ring, looping until unmounted.
|
|
20
|
-
*/
|
|
21
17
|
const BadgeDotAnimation = ({ size, style }: BadgeDotProps) => {
|
|
22
18
|
const scaleAnim = useSharedValue(1);
|
|
23
19
|
const waveScaleAnim = useSharedValue(1);
|
|
@@ -61,18 +57,14 @@ const BadgeDotAnimation = ({ size, style }: BadgeDotProps) => {
|
|
|
61
57
|
};
|
|
62
58
|
}, [scaleAnim, waveOpacityAnim, waveScaleAnim]);
|
|
63
59
|
|
|
64
|
-
const waveAnimatedStyle = useAnimatedStyle(() => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
});
|
|
60
|
+
const waveAnimatedStyle = useAnimatedStyle(() => ({
|
|
61
|
+
transform: [{ scale: waveScaleAnim.value }],
|
|
62
|
+
opacity: waveOpacityAnim.value,
|
|
63
|
+
}));
|
|
70
64
|
|
|
71
|
-
const dotAnimatedStyle = useAnimatedStyle(() => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
});
|
|
65
|
+
const dotAnimatedStyle = useAnimatedStyle(() => ({
|
|
66
|
+
transform: [{ scale: scaleAnim.value }],
|
|
67
|
+
}));
|
|
76
68
|
|
|
77
69
|
return (
|
|
78
70
|
<View style={[styles.dotAnimationContainer, style]}>
|
package/Badge/BadgeRibbon.tsx
CHANGED
|
@@ -8,10 +8,6 @@ import { Text } from '../Text';
|
|
|
8
8
|
import { Colors } from '../Consts';
|
|
9
9
|
import { Image } from '../Image';
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Corner ribbon label in the warning color, skewed or `isRound`. Right-corner
|
|
13
|
-
* ribbons are rotated 180deg with the text counter-rotated to stay upright.
|
|
14
|
-
*/
|
|
15
11
|
const BadgeRibbon: FC<BadgeRibbonProps> = ({
|
|
16
12
|
position = 'top_right',
|
|
17
13
|
label = 'Label',
|
|
@@ -37,21 +33,44 @@ const BadgeRibbon: FC<BadgeRibbonProps> = ({
|
|
|
37
33
|
const textTransform = useMemo(() => [{ rotateZ: textRotate }], [textRotate]);
|
|
38
34
|
|
|
39
35
|
const ribbonTail = isUpTail ? <UpTail /> : <DownTail />;
|
|
40
|
-
const renderRoundContent = () =>
|
|
41
|
-
|
|
36
|
+
const renderRoundContent = () => (
|
|
37
|
+
<View
|
|
38
|
+
collapsable={false}
|
|
39
|
+
style={[
|
|
40
|
+
styles.ribbonContent,
|
|
41
|
+
{
|
|
42
|
+
backgroundColor: theme.colors.warning.primary,
|
|
43
|
+
marginTop: textMargin,
|
|
44
|
+
},
|
|
45
|
+
]}
|
|
46
|
+
>
|
|
47
|
+
<View
|
|
48
|
+
collapsable={false}
|
|
49
|
+
style={{ transform: textTransform, marginVertical: -2 }}
|
|
50
|
+
>
|
|
51
|
+
<Text
|
|
52
|
+
style={styles.ribbonLabel}
|
|
53
|
+
color={Colors.black_01}
|
|
54
|
+
typography="label_xs_medium"
|
|
55
|
+
>
|
|
56
|
+
{label}
|
|
57
|
+
</Text>
|
|
58
|
+
</View>
|
|
59
|
+
</View>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const renderSkewContent = () => (
|
|
63
|
+
<View style={{ flexDirection: 'row', marginTop: skewMargin }}>
|
|
42
64
|
<View
|
|
43
65
|
collapsable={false}
|
|
44
66
|
style={[
|
|
45
|
-
styles.
|
|
46
|
-
{
|
|
47
|
-
backgroundColor: theme.colors.warning.primary,
|
|
48
|
-
marginTop: textMargin,
|
|
49
|
-
},
|
|
67
|
+
styles.ribbonSkewContent,
|
|
68
|
+
{ backgroundColor: theme.colors.warning.primary },
|
|
50
69
|
]}
|
|
51
70
|
>
|
|
52
71
|
<View
|
|
53
72
|
collapsable={false}
|
|
54
|
-
style={
|
|
73
|
+
style={{ transform: textTransform, marginVertical: -2 }}
|
|
55
74
|
>
|
|
56
75
|
<Text
|
|
57
76
|
style={styles.ribbonLabel}
|
|
@@ -62,41 +81,14 @@ const BadgeRibbon: FC<BadgeRibbonProps> = ({
|
|
|
62
81
|
</Text>
|
|
63
82
|
</View>
|
|
64
83
|
</View>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
style={[
|
|
74
|
-
styles.ribbonSkewContent,
|
|
75
|
-
{ backgroundColor: theme.colors.warning.primary },
|
|
76
|
-
]}
|
|
77
|
-
>
|
|
78
|
-
<View
|
|
79
|
-
collapsable={false}
|
|
80
|
-
style={[styles.ribbonLabelWrapper, { transform: textTransform }]}
|
|
81
|
-
>
|
|
82
|
-
<Text
|
|
83
|
-
style={styles.ribbonLabel}
|
|
84
|
-
color={Colors.black_01}
|
|
85
|
-
typography="label_xs_medium"
|
|
86
|
-
>
|
|
87
|
-
{label}
|
|
88
|
-
</Text>
|
|
89
|
-
</View>
|
|
90
|
-
</View>
|
|
91
|
-
<Image
|
|
92
|
-
source={{
|
|
93
|
-
uri: 'https://static.momocdn.net/app/img/kits/utils/Tail_4x.png',
|
|
94
|
-
}}
|
|
95
|
-
style={styles.skew}
|
|
96
|
-
/>
|
|
97
|
-
</View>
|
|
98
|
-
);
|
|
99
|
-
};
|
|
84
|
+
<Image
|
|
85
|
+
source={{
|
|
86
|
+
uri: 'https://static.momocdn.net/app/img/kits/utils/Tail_4x.png',
|
|
87
|
+
}}
|
|
88
|
+
style={styles.skew}
|
|
89
|
+
/>
|
|
90
|
+
</View>
|
|
91
|
+
);
|
|
100
92
|
|
|
101
93
|
const content = isRound ? renderRoundContent() : renderSkewContent();
|
|
102
94
|
|
package/Badge/Shape.tsx
CHANGED
|
@@ -2,7 +2,6 @@ import React from 'react';
|
|
|
2
2
|
import styles from './styles';
|
|
3
3
|
import {Image} from '../Image';
|
|
4
4
|
|
|
5
|
-
/** Ribbon tail image pointing up (the down tail rotated 180deg). */
|
|
6
5
|
const UpTail = () => {
|
|
7
6
|
return (
|
|
8
7
|
<Image
|
|
@@ -15,7 +14,6 @@ const UpTail = () => {
|
|
|
15
14
|
);
|
|
16
15
|
};
|
|
17
16
|
|
|
18
|
-
/** Ribbon tail image pointing down. */
|
|
19
17
|
const DownTail = () => {
|
|
20
18
|
return (
|
|
21
19
|
<Image
|
package/Badge/styles.ts
CHANGED
|
@@ -118,8 +118,6 @@ export default StyleSheet.create({
|
|
|
118
118
|
ribbonLabel: {
|
|
119
119
|
color: Colors.black_01,
|
|
120
120
|
},
|
|
121
|
-
ribbonLabelWrapper: {marginVertical: -2},
|
|
122
|
-
ribbonSkewRow: {flexDirection: 'row'},
|
|
123
121
|
skew: {width: 8, height: 16},
|
|
124
122
|
tail: {width: 5, height: 20},
|
|
125
123
|
debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
|
package/Badge/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ViewStyle} from 'react-native';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Props for a Badge component. It
|
|
4
|
+
* Props for a general Badge component. It can display a wide range of badges including simple labels, numbers, or dots.
|
|
5
5
|
*/
|
|
6
6
|
export type BadgeProps = {
|
|
7
7
|
/**
|
|
@@ -20,7 +20,7 @@ export type BadgeProps = {
|
|
|
20
20
|
backgroundColor?: string;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
*
|
|
24
24
|
*/
|
|
25
25
|
accessibilityLabel?: string;
|
|
26
26
|
};
|