@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
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { Alert } from 'react-native';
|
|
2
|
-
import { version } from '../package.json';
|
|
3
|
-
|
|
4
|
-
type ScreenTrackingDeps = {
|
|
5
|
-
tracking: { current: any };
|
|
6
|
-
context: any;
|
|
7
|
-
navigator: any;
|
|
8
|
-
screenName: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Auto-tracking reporters of a stack screen. Each event fires at most once per
|
|
13
|
-
* screen, guarded by the `release*` flags on `tracking.current`.
|
|
14
|
-
*/
|
|
15
|
-
export const createScreenTracking = ({
|
|
16
|
-
tracking,
|
|
17
|
-
context,
|
|
18
|
-
navigator,
|
|
19
|
-
screenName,
|
|
20
|
-
}: ScreenTrackingDeps) => {
|
|
21
|
-
/** Reports the screen load time. */
|
|
22
|
-
const onScreenLoad = () => {
|
|
23
|
-
if (!tracking.current?.releaseLoad) {
|
|
24
|
-
let timeLoad = tracking.current.timeLoad;
|
|
25
|
-
if (timeLoad === 0) {
|
|
26
|
-
timeLoad = tracking.current.endTime - tracking.current.startTime;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
context?.autoTracking?.({
|
|
30
|
-
...context,
|
|
31
|
-
screenName,
|
|
32
|
-
componentName: 'Screen',
|
|
33
|
-
state: 'load',
|
|
34
|
-
duration: timeLoad,
|
|
35
|
-
widgets: tracking.current.widgets,
|
|
36
|
-
params: tracking.current.params,
|
|
37
|
-
version: version,
|
|
38
|
-
lastElement: tracking.current.lastElement,
|
|
39
|
-
});
|
|
40
|
-
navigator?.maxApi?.stopTrace?.(
|
|
41
|
-
tracking.current.traceIdLoad,
|
|
42
|
-
{ value: timeLoad / 1000 },
|
|
43
|
-
null,
|
|
44
|
-
);
|
|
45
|
-
tracking.current.releaseLoad = true;
|
|
46
|
-
|
|
47
|
-
navigator?.maxApi?.showToastDebug?.({
|
|
48
|
-
appId: context.appId,
|
|
49
|
-
message: `${screenName} screen_load_time ${timeLoad}`,
|
|
50
|
-
type: 'ERROR',
|
|
51
|
-
});
|
|
52
|
-
const lastChildren = tracking.current.lastElement?.children?.current;
|
|
53
|
-
if (__DEV__ && lastChildren?.length > 0) {
|
|
54
|
-
Alert.alert(
|
|
55
|
-
`${screenName}- load ${timeLoad}ms`,
|
|
56
|
-
JSON.stringify(lastChildren),
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/** Reports the time until the screen became interactive. */
|
|
63
|
-
const onScreenInteraction = () => {
|
|
64
|
-
if (!tracking.current?.releaseInteraction) {
|
|
65
|
-
let timeLoad = tracking.current.timeLoad;
|
|
66
|
-
if (timeLoad === 0) {
|
|
67
|
-
timeLoad = tracking.current.endTime - tracking.current.startTime;
|
|
68
|
-
}
|
|
69
|
-
if (tracking.current.timeInteraction === 0) {
|
|
70
|
-
tracking.current.timeInteraction = timeLoad;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
context?.autoTracking?.({
|
|
74
|
-
...context,
|
|
75
|
-
screenName,
|
|
76
|
-
componentName: 'Screen',
|
|
77
|
-
state: 'interaction',
|
|
78
|
-
duration: tracking.current.timeInteraction - timeLoad,
|
|
79
|
-
totalDuration: tracking.current.timeInteraction,
|
|
80
|
-
params: tracking.current.params,
|
|
81
|
-
version: version,
|
|
82
|
-
});
|
|
83
|
-
navigator?.maxApi?.stopTrace?.(
|
|
84
|
-
tracking.current.traceIdInteraction,
|
|
85
|
-
{ value: tracking.current.timeInteraction / 1000 },
|
|
86
|
-
null,
|
|
87
|
-
);
|
|
88
|
-
tracking.current.releaseInteraction = true;
|
|
89
|
-
|
|
90
|
-
navigator?.maxApi?.showToastDebug?.({
|
|
91
|
-
appId: context.appId,
|
|
92
|
-
message: `${screenName} screen_interaction_time ${tracking.current.timeInteraction}`,
|
|
93
|
-
type: 'ERROR',
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/** Reports the user's first interaction with the screen. */
|
|
99
|
-
const onFirstInteraction = (action: string) => {
|
|
100
|
-
if (!tracking.current?.releaseUserInteraction) {
|
|
101
|
-
const timeLoad = tracking.current.endTime - tracking.current.startTime;
|
|
102
|
-
context?.autoTracking?.({
|
|
103
|
-
...context,
|
|
104
|
-
screenName,
|
|
105
|
-
componentName: 'Screen',
|
|
106
|
-
state: 'interaction',
|
|
107
|
-
duration: timeLoad,
|
|
108
|
-
action,
|
|
109
|
-
});
|
|
110
|
-
tracking.current.releaseUserInteraction = true;
|
|
111
|
-
|
|
112
|
-
navigator?.maxApi?.showToastDebug?.({
|
|
113
|
-
appId: context.appId,
|
|
114
|
-
message: `${screenName} user_interaction ${timeLoad}`,
|
|
115
|
-
type: 'ERROR',
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
/** Reports how long the skeleton loading state lasted. */
|
|
121
|
-
const onScreenLoading = () => {
|
|
122
|
-
const start = tracking.current.timeStartLoading;
|
|
123
|
-
const end = tracking.current.timeEndLoading;
|
|
124
|
-
if (!tracking.current?.releaseLoading && start && end && end > start) {
|
|
125
|
-
context?.autoTracking?.({
|
|
126
|
-
...context,
|
|
127
|
-
screenName,
|
|
128
|
-
componentName: 'Screen',
|
|
129
|
-
state: 'loading',
|
|
130
|
-
duration: end - start,
|
|
131
|
-
loadingType: 'skeleton',
|
|
132
|
-
});
|
|
133
|
-
tracking.current.releaseLoading = true;
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
onScreenLoad,
|
|
139
|
-
onScreenInteraction,
|
|
140
|
-
onFirstInteraction,
|
|
141
|
-
onScreenLoading,
|
|
142
|
-
};
|
|
143
|
-
};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { useWindowDimensions, type ViewStyle } from 'react-native';
|
|
3
|
-
import type { StackNavigationOptions } from '@react-navigation/stack';
|
|
4
|
-
import { Spacing } from '../Consts';
|
|
5
|
-
import { getHeaderMargin } from '../Layout/utils';
|
|
6
|
-
import { FOLDABLE_MIN_WIDTH } from './modalLayout';
|
|
7
|
-
import { isIPhoneDuo } from './utils';
|
|
8
|
-
|
|
9
|
-
// Top navigation spec, shared with the Compose / SwiftUI kits
|
|
10
|
-
const HEADER_FRAME_MAX_WIDTH = 600;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Top navigation geometry on every device
|
|
14
|
-
* - buttonSize / iconSize: round back and shortcut buttons, icons inside them and the pill
|
|
15
|
-
* - pillWidth / pillHeight: help center | home capsule
|
|
16
|
-
* - clusterWidth: shortcut, gap and pill on the right of the bar
|
|
17
|
-
* - searchHeight: search field inside the header
|
|
18
|
-
* - titleGap: space between back and the title, and the title and the right cluster
|
|
19
|
-
* - sidePadding: bar edge to back and to the right cluster
|
|
20
|
-
* - gradientHeight: header gradient, kept at the phone height on wide windows
|
|
21
|
-
* - bannerWidth: animated banner image, kept at the phone width on wide windows
|
|
22
|
-
*/
|
|
23
|
-
const HeaderBarMetrics = {
|
|
24
|
-
buttonSize: 32,
|
|
25
|
-
iconSize: 20,
|
|
26
|
-
pillWidth: 72,
|
|
27
|
-
pillHeight: 32,
|
|
28
|
-
clusterWidth: 112,
|
|
29
|
-
searchHeight: 32,
|
|
30
|
-
titleGap: Spacing.S,
|
|
31
|
-
sidePadding: Spacing.M,
|
|
32
|
-
gradientHeight: 154,
|
|
33
|
-
bannerWidth: 375,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* `grid` keeps the header row at the bar edges, `stretch` centers it in a 600pt
|
|
38
|
-
* frame on wide windows. Background and status bar always span the window.
|
|
39
|
-
*/
|
|
40
|
-
type HeaderContentLayout = 'grid' | 'stretch';
|
|
41
|
-
|
|
42
|
-
type HeaderLayout = typeof HeaderBarMetrics & {
|
|
43
|
-
/**
|
|
44
|
-
* Window whose short side is at least 600 (Galaxy Z Fold / Pixel Fold inner
|
|
45
|
-
* display, tablets), iPhone Duo excluded. Phones, landscape included, are not.
|
|
46
|
-
*/
|
|
47
|
-
isWide: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Window edge to back and to the right cluster: `sidePadding`, or centering the
|
|
50
|
-
* row in the 600pt frame with `stretch` on a wide window.
|
|
51
|
-
*/
|
|
52
|
-
frameInset: number;
|
|
53
|
-
/**
|
|
54
|
-
* Header row width between the two `frameInset`s.
|
|
55
|
-
*/
|
|
56
|
-
frameWidth: number;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
type HeaderLayoutInput = {
|
|
60
|
-
width: number;
|
|
61
|
-
height: number;
|
|
62
|
-
isDuo: boolean;
|
|
63
|
-
contentLayout?: HeaderContentLayout;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Header geometry for a window, pure so it can be tested without a device.
|
|
68
|
-
*/
|
|
69
|
-
const getHeaderLayout = ({
|
|
70
|
-
width,
|
|
71
|
-
height,
|
|
72
|
-
isDuo,
|
|
73
|
-
contentLayout = 'grid',
|
|
74
|
-
}: HeaderLayoutInput): HeaderLayout => {
|
|
75
|
-
const { sidePadding } = HeaderBarMetrics;
|
|
76
|
-
const isWide = !isDuo && Math.min(width, height) >= FOLDABLE_MIN_WIDTH;
|
|
77
|
-
let frameInset = sidePadding;
|
|
78
|
-
if (isWide && contentLayout === 'stretch') {
|
|
79
|
-
const centered = (width - HEADER_FRAME_MAX_WIDTH) / 2;
|
|
80
|
-
frameInset = Math.max(sidePadding, centered);
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
...HeaderBarMetrics,
|
|
84
|
-
isWide,
|
|
85
|
-
frameInset,
|
|
86
|
-
frameWidth: width - frameInset * 2,
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Widest a title can be between back and the right cluster of the header row.
|
|
92
|
-
*/
|
|
93
|
-
const getTitleBudget = (layout: HeaderLayout) => {
|
|
94
|
-
const { buttonSize, titleGap, clusterWidth } = layout;
|
|
95
|
-
return layout.frameWidth - buttonSize - titleGap * 2 - clusterWidth;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Header geometry for the current window; follows fold, unfold and rotation.
|
|
100
|
-
*/
|
|
101
|
-
const useHeaderLayout = (contentLayout?: HeaderContentLayout): HeaderLayout => {
|
|
102
|
-
const { width, height } = useWindowDimensions();
|
|
103
|
-
const isDuo = isIPhoneDuo();
|
|
104
|
-
return useMemo(() => {
|
|
105
|
-
return getHeaderLayout({ width, height, isDuo, contentLayout });
|
|
106
|
-
}, [width, height, isDuo, contentLayout]);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const TITLE_CONTAINER_RESET: ViewStyle = {
|
|
110
|
-
marginLeft: 0,
|
|
111
|
-
marginEnd: 0,
|
|
112
|
-
marginStart: 0,
|
|
113
|
-
marginHorizontal: 0,
|
|
114
|
-
marginVertical: 0,
|
|
115
|
-
margin: 0,
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* React Navigation container styles that keep back, title and the right cluster
|
|
120
|
-
* in the `stretch` frame. `undefined` for `grid`, and on iPhone Duo, which keeps
|
|
121
|
-
* its own header row.
|
|
122
|
-
*/
|
|
123
|
-
const useHeaderFrameOptions = (
|
|
124
|
-
contentLayout?: HeaderContentLayout,
|
|
125
|
-
): StackNavigationOptions | undefined => {
|
|
126
|
-
const layout = useHeaderLayout(contentLayout);
|
|
127
|
-
const { width } = useWindowDimensions();
|
|
128
|
-
const isDuo = isIPhoneDuo();
|
|
129
|
-
return useMemo(() => {
|
|
130
|
-
if (contentLayout !== 'stretch' || isDuo) {
|
|
131
|
-
return undefined;
|
|
132
|
-
}
|
|
133
|
-
// the header content row already sits this far in on large iOS windows
|
|
134
|
-
const shift = layout.frameInset - layout.sidePadding;
|
|
135
|
-
const containerShift = Math.max(0, shift - getHeaderMargin(width));
|
|
136
|
-
return {
|
|
137
|
-
headerLeftContainerStyle: { paddingLeft: containerShift },
|
|
138
|
-
headerRightContainerStyle: { paddingRight: containerShift },
|
|
139
|
-
headerTitleContainerStyle: {
|
|
140
|
-
...TITLE_CONTAINER_RESET,
|
|
141
|
-
left: layout.titleGap,
|
|
142
|
-
maxWidth: getTitleBudget(layout),
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
}, [contentLayout, isDuo, layout, width]);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export type { HeaderContentLayout, HeaderLayout };
|
|
149
|
-
|
|
150
|
-
export {
|
|
151
|
-
HeaderBarMetrics,
|
|
152
|
-
HEADER_FRAME_MAX_WIDTH,
|
|
153
|
-
TITLE_CONTAINER_RESET,
|
|
154
|
-
getHeaderLayout,
|
|
155
|
-
getTitleBudget,
|
|
156
|
-
useHeaderLayout,
|
|
157
|
-
useHeaderFrameOptions,
|
|
158
|
-
};
|
package/Application/hooks.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { useCallback, useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import { AppState, NativeModules } from 'react-native';
|
|
3
|
-
import { type SharedValue, useSharedValue } from 'react-native-reanimated';
|
|
4
|
-
import {
|
|
5
|
-
MiniAppContext,
|
|
6
|
-
ScreenContext,
|
|
7
|
-
TrackingScopeContext,
|
|
8
|
-
} from '../Context';
|
|
9
|
-
import {
|
|
10
|
-
type AnimatedCompatValue,
|
|
11
|
-
type NavigationTreeState,
|
|
12
|
-
getStackDepth,
|
|
13
|
-
isRNAnimatedValue,
|
|
14
|
-
isSharedValue,
|
|
15
|
-
} from './utils';
|
|
16
|
-
|
|
17
|
-
const FOREGROUND_FLAG_DURATION = 100;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Automation id of a component: `accessibilityLabel` when given, otherwise
|
|
21
|
-
* `appId/code/screenName/scope/componentName` from the surrounding contexts.
|
|
22
|
-
*/
|
|
23
|
-
const useComponentId = (componentName: string, accessibilityLabel?: string) => {
|
|
24
|
-
const app = useContext<any>(MiniAppContext);
|
|
25
|
-
const screen = useContext<any>(ScreenContext);
|
|
26
|
-
const { scopeName } = useContext<any>(TrackingScopeContext);
|
|
27
|
-
|
|
28
|
-
const scope = scopeName ? `${scopeName}/` : '';
|
|
29
|
-
|
|
30
|
-
const componentId = useMemo(() => {
|
|
31
|
-
if (accessibilityLabel) {
|
|
32
|
-
return accessibilityLabel;
|
|
33
|
-
}
|
|
34
|
-
return `${app.appId}/${app.code}/${screen.screenName}/${scope}${componentName}`;
|
|
35
|
-
}, [
|
|
36
|
-
accessibilityLabel,
|
|
37
|
-
app.appId,
|
|
38
|
-
app.code,
|
|
39
|
-
screen.screenName,
|
|
40
|
-
scope,
|
|
41
|
-
componentName,
|
|
42
|
-
]);
|
|
43
|
-
|
|
44
|
-
return { componentId };
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* App state and whether the app just came back from background (true for
|
|
49
|
-
* FOREGROUND_FLAG_DURATION ms). Read at render time, it never re-renders.
|
|
50
|
-
*/
|
|
51
|
-
const useAppState = () => {
|
|
52
|
-
const isBackgroundToForeground = useRef(false);
|
|
53
|
-
const appState = useRef(AppState.currentState);
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
const subscription = AppState.addEventListener('change', nextAppState => {
|
|
57
|
-
const wasInBackground = /inactive|background/.test(appState.current);
|
|
58
|
-
const isReturning = wasInBackground && nextAppState === 'active';
|
|
59
|
-
isBackgroundToForeground.current = isReturning;
|
|
60
|
-
appState.current = nextAppState;
|
|
61
|
-
|
|
62
|
-
if (isReturning) {
|
|
63
|
-
setTimeout(() => {
|
|
64
|
-
isBackgroundToForeground.current = false;
|
|
65
|
-
}, FOREGROUND_FLAG_DURATION);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return () => {
|
|
70
|
-
subscription.remove();
|
|
71
|
-
};
|
|
72
|
-
}, []);
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
isBackgroundToForeground: isBackgroundToForeground.current,
|
|
76
|
-
appState: appState.current,
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Returns a navigation state listener that tells native who owns back: `true`
|
|
82
|
-
* on the mini app's root screen, `false` while there is still something to pop.
|
|
83
|
-
*/
|
|
84
|
-
const useNativeCanGoBack = () => {
|
|
85
|
-
const lastValue = useRef<boolean | undefined>(undefined);
|
|
86
|
-
|
|
87
|
-
return useCallback((state?: NavigationTreeState) => {
|
|
88
|
-
const canDismiss = getStackDepth(state) === 0;
|
|
89
|
-
if (lastValue.current === canDismiss) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const setCanGoBack = NativeModules?.MiniAppModule?.setCanGoBack;
|
|
94
|
-
if (typeof setCanGoBack !== 'function') {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
lastValue.current = canDismiss;
|
|
99
|
-
try {
|
|
100
|
-
setCanGoBack(canDismiss);
|
|
101
|
-
} catch (error) {
|
|
102
|
-
console.warn('[NavigationContainer] setCanGoBack failed:', error);
|
|
103
|
-
}
|
|
104
|
-
}, []);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Either animation runtime as a reanimated shared value: a shared value passes
|
|
109
|
-
* through, an RN `Animated.Value` is mirrored into a fallback shared value.
|
|
110
|
-
*/
|
|
111
|
-
const useNormalizedSharedValue = (
|
|
112
|
-
input?: AnimatedCompatValue,
|
|
113
|
-
): SharedValue<number> => {
|
|
114
|
-
const fallback = useSharedValue(0);
|
|
115
|
-
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
if (!isRNAnimatedValue(input)) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const id = input.addListener(({ value }) => {
|
|
121
|
-
fallback.value = value;
|
|
122
|
-
});
|
|
123
|
-
return () => input.removeListener(id);
|
|
124
|
-
}, [input, fallback]);
|
|
125
|
-
|
|
126
|
-
if (isSharedValue(input)) {
|
|
127
|
-
return input;
|
|
128
|
-
}
|
|
129
|
-
return fallback;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export {
|
|
133
|
-
useComponentId,
|
|
134
|
-
useAppState,
|
|
135
|
-
useNativeCanGoBack,
|
|
136
|
-
useNormalizedSharedValue,
|
|
137
|
-
};
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { useWindowDimensions } from 'react-native';
|
|
2
|
-
import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
3
|
-
import { Radius, Spacing } from '../Consts';
|
|
4
|
-
import { ReservedRegion, useHinge } from '../Layout/ReservedRegions';
|
|
5
|
-
import { isIPhoneDuo } from './utils';
|
|
6
|
-
|
|
7
|
-
// Foldable modal spec, shared with the Compose / SwiftUI kits
|
|
8
|
-
const POPUP_MAX_WIDTH = 450;
|
|
9
|
-
const POPUP_MIN_WIDTH = 280;
|
|
10
|
-
const POPUP_MAX_HEIGHT = 600;
|
|
11
|
-
const SHEET_MAX_WIDTH = 653;
|
|
12
|
-
const SHEET_MIN_WIDTH = 296;
|
|
13
|
-
const SHEET_MIN_HEIGHT = 230;
|
|
14
|
-
const FOLDABLE_MIN_WIDTH = 600;
|
|
15
|
-
|
|
16
|
-
const SCRIM_OPACITY = 0.6;
|
|
17
|
-
const FOLDABLE_SCRIM_OPACITY = 0.2;
|
|
18
|
-
|
|
19
|
-
export type ModalRect = {
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
width: number;
|
|
23
|
-
height: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type ModalLayout = {
|
|
27
|
-
/**
|
|
28
|
-
* iPhone Duo, or a window whose short side is at least 600 (Galaxy Z Fold / Pixel
|
|
29
|
-
* Fold inner display). Phones, landscape included, keep the regular modal look.
|
|
30
|
-
*/
|
|
31
|
-
isFoldable: boolean;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Area popups and sheets are placed in: the safe area, left of the control column on
|
|
35
|
-
* the iPhone Duo outer display, the right half when iPhone Duo is half folded.
|
|
36
|
-
*/
|
|
37
|
-
placement: ModalRect;
|
|
38
|
-
|
|
39
|
-
popup: {
|
|
40
|
-
width: number;
|
|
41
|
-
minWidth: number;
|
|
42
|
-
maxWidth: number;
|
|
43
|
-
/**
|
|
44
|
-
* `undefined` on phones, the popup grows with its content.
|
|
45
|
-
*/
|
|
46
|
-
maxHeight?: number;
|
|
47
|
-
margin: number;
|
|
48
|
-
radius: number;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
sheet: {
|
|
52
|
-
/**
|
|
53
|
-
* `undefined` on phones, the sheet spans the window.
|
|
54
|
-
*/
|
|
55
|
-
width?: number;
|
|
56
|
-
maxHeight?: number;
|
|
57
|
-
minHeight?: number;
|
|
58
|
-
margin: number;
|
|
59
|
-
radius: number;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
scrimOpacity: number;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
type ModalLayoutInput = {
|
|
66
|
-
width: number;
|
|
67
|
-
height: number;
|
|
68
|
-
insets: EdgeInsets;
|
|
69
|
-
isDuo: boolean;
|
|
70
|
-
/**
|
|
71
|
-
* vertical division reported by the system, iPhone Duo half folded
|
|
72
|
-
*/
|
|
73
|
-
hinge?: ReservedRegion;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const clamp = (value: number, min: number, max: number) => {
|
|
77
|
-
return Math.min(Math.max(value, min), max);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Modal geometry for a window, pure so it can be tested without a device.
|
|
82
|
-
*/
|
|
83
|
-
const getModalLayout = ({
|
|
84
|
-
width,
|
|
85
|
-
height,
|
|
86
|
-
insets,
|
|
87
|
-
isDuo,
|
|
88
|
-
hinge,
|
|
89
|
-
}: ModalLayoutInput): ModalLayout => {
|
|
90
|
-
const shortSide = Math.min(width, height);
|
|
91
|
-
// short side, so a phone in landscape stays a phone
|
|
92
|
-
const isFoldable = isDuo || shortSide >= FOLDABLE_MIN_WIDTH;
|
|
93
|
-
const isDuoOuter = isDuo && shortSide < FOLDABLE_MIN_WIDTH;
|
|
94
|
-
const hingeRight = hinge ? hinge.x + hinge.width : 0;
|
|
95
|
-
const hasHinge = !!hinge && hinge.x > 0;
|
|
96
|
-
const isHingeInWindow = hingeRight < width - insets.right;
|
|
97
|
-
const isHalfFolded = isDuo && hasHinge && isHingeInWindow;
|
|
98
|
-
|
|
99
|
-
const safeLeft = isHalfFolded ? hingeRight : insets.left;
|
|
100
|
-
const placement = {
|
|
101
|
-
x: safeLeft,
|
|
102
|
-
y: insets.top,
|
|
103
|
-
width: width - insets.right - safeLeft,
|
|
104
|
-
height: height - insets.top - insets.bottom,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
if (!isFoldable) {
|
|
108
|
-
const popupWidth = width - Spacing.XL * 2;
|
|
109
|
-
return {
|
|
110
|
-
isFoldable,
|
|
111
|
-
placement,
|
|
112
|
-
popup: {
|
|
113
|
-
width: popupWidth,
|
|
114
|
-
minWidth: popupWidth,
|
|
115
|
-
maxWidth: popupWidth,
|
|
116
|
-
margin: Spacing.XL,
|
|
117
|
-
radius: Radius.XL,
|
|
118
|
-
},
|
|
119
|
-
sheet: { margin: 0, radius: Radius.XL },
|
|
120
|
-
scrimOpacity: SCRIM_OPACITY,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const popupMargin = isDuoOuter || isHalfFolded ? Spacing.M : Spacing.XL;
|
|
125
|
-
const popupSpace = placement.width - popupMargin * 2;
|
|
126
|
-
const popupMinWidth = Math.min(POPUP_MIN_WIDTH, popupSpace);
|
|
127
|
-
|
|
128
|
-
const sheetMargin = Spacing.M;
|
|
129
|
-
const sheetSpace = placement.width - sheetMargin * 2;
|
|
130
|
-
const sheetMinWidth = Math.min(SHEET_MIN_WIDTH, sheetSpace);
|
|
131
|
-
const sheetMaxHeight = height - insets.top - Spacing.M;
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
isFoldable,
|
|
135
|
-
placement,
|
|
136
|
-
popup: {
|
|
137
|
-
width: clamp(popupSpace, popupMinWidth, POPUP_MAX_WIDTH),
|
|
138
|
-
minWidth: popupMinWidth,
|
|
139
|
-
maxWidth: POPUP_MAX_WIDTH,
|
|
140
|
-
maxHeight: Math.min(POPUP_MAX_HEIGHT, placement.height - Spacing.XL * 2),
|
|
141
|
-
margin: popupMargin,
|
|
142
|
-
radius: Radius.XL,
|
|
143
|
-
},
|
|
144
|
-
sheet: {
|
|
145
|
-
width: clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH),
|
|
146
|
-
maxHeight: sheetMaxHeight,
|
|
147
|
-
minHeight: Math.min(SHEET_MIN_HEIGHT, sheetMaxHeight),
|
|
148
|
-
margin: sheetMargin,
|
|
149
|
-
radius: Radius.XL,
|
|
150
|
-
},
|
|
151
|
-
scrimOpacity: FOLDABLE_SCRIM_OPACITY,
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Modal geometry for the current window; follows fold, unfold, rotation and
|
|
157
|
-
* the iPhone Duo hinge.
|
|
158
|
-
*/
|
|
159
|
-
const useModalLayout = (): ModalLayout => {
|
|
160
|
-
const { width, height } = useWindowDimensions();
|
|
161
|
-
const insets = useSafeAreaInsets();
|
|
162
|
-
const hinge = useHinge();
|
|
163
|
-
return getModalLayout({ width, height, insets, isDuo: isIPhoneDuo(), hinge });
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export {
|
|
167
|
-
getModalLayout,
|
|
168
|
-
useModalLayout,
|
|
169
|
-
POPUP_MAX_WIDTH,
|
|
170
|
-
POPUP_MIN_WIDTH,
|
|
171
|
-
POPUP_MAX_HEIGHT,
|
|
172
|
-
SHEET_MAX_WIDTH,
|
|
173
|
-
SHEET_MIN_WIDTH,
|
|
174
|
-
SHEET_MIN_HEIGHT,
|
|
175
|
-
FOLDABLE_MIN_WIDTH,
|
|
176
|
-
};
|