@momo-kits/foundation 0.169.19-beta.2 → 0.169.19-beta.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/Application/BottomSheet.parts.tsx +4 -4
- package/Application/BottomSheet.tsx +6 -16
- package/Application/Components/HeaderExtendHeader.tsx +7 -2
- package/Application/Components/HeaderLeft.tsx +9 -5
- package/Application/Components/HeaderRight.styles.ts +5 -1
- package/Application/Components/HeaderRight.tsx +7 -21
- package/Application/Components/SearchHeader.tsx +5 -1
- package/Application/Components/useHeaderRightWidth.ts +2 -2
- package/Application/ModalIconButton.tsx +13 -15
- package/Application/ModalScreen.tsx +13 -4
- package/Application/__tests__/headerLayout.test.ts +2 -1
- package/Application/headerLayout.ts +10 -13
- package/Application/modalLayout.ts +43 -3
- package/Application/navigationOptions.tsx +5 -12
- package/Input/CountryCodeView.tsx +109 -0
- package/Input/ErrorView.tsx +1 -1
- package/Input/InputMoneyView.tsx +6 -14
- package/Input/InputPhoneNumber.tsx +20 -38
- package/Input/index.tsx +15 -1
- package/Layout/FloatingButton.tsx +19 -7
- package/Layout/screenHeader.tsx +16 -20
- package/package.json +1 -1
|
@@ -120,9 +120,9 @@ type SheetStyleParams = {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
* Sheet container style. On foldables the sheet
|
|
124
|
-
*
|
|
125
|
-
* folded; the keyboard lift comes off its max height.
|
|
123
|
+
* Sheet container style. On foldables the sheet sits at `sheet.x`: centered on
|
|
124
|
+
* the window, clear of the iPhone Duo control column, and on the right half when
|
|
125
|
+
* half folded; the keyboard lift comes off its max height.
|
|
126
126
|
*/
|
|
127
127
|
export const getSheetStyle = ({
|
|
128
128
|
backgroundColor,
|
|
@@ -138,7 +138,7 @@ export const getSheetStyle = ({
|
|
|
138
138
|
if (isFoldable && width !== undefined && maxHeight !== undefined) {
|
|
139
139
|
foldableStyle = {
|
|
140
140
|
width,
|
|
141
|
-
marginLeft: placement.x + (placement.width - width) / 2,
|
|
141
|
+
marginLeft: sheet.x ?? placement.x + (placement.width - width) / 2,
|
|
142
142
|
maxHeight: maxHeight - keyboardLift,
|
|
143
143
|
minHeight: sheet.minHeight,
|
|
144
144
|
};
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
Pressable,
|
|
8
8
|
StyleSheet,
|
|
9
9
|
View,
|
|
10
|
+
ViewStyle,
|
|
10
11
|
} from 'react-native';
|
|
11
12
|
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
12
13
|
import { BottomSheetParams } from './types';
|
|
@@ -190,22 +191,10 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
190
191
|
/>
|
|
191
192
|
);
|
|
192
193
|
|
|
193
|
-
|
|
194
|
+
// same tree on every layout so fold / unfold keeps the screen mounted (state, scroll)
|
|
195
|
+
let contentStyle: ViewStyle | undefined;
|
|
194
196
|
if (isFoldable) {
|
|
195
|
-
|
|
196
|
-
content = (
|
|
197
|
-
<View style={styles.shrink}>
|
|
198
|
-
{renderSheetHeader(headerParams)}
|
|
199
|
-
<View style={styles.shrink}>{screen}</View>
|
|
200
|
-
</View>
|
|
201
|
-
);
|
|
202
|
-
} else {
|
|
203
|
-
content = (
|
|
204
|
-
<>
|
|
205
|
-
{renderSheetHeader(headerParams)}
|
|
206
|
-
{screen}
|
|
207
|
-
</>
|
|
208
|
-
);
|
|
197
|
+
contentStyle = styles.shrink;
|
|
209
198
|
}
|
|
210
199
|
|
|
211
200
|
return (
|
|
@@ -253,7 +242,8 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
253
242
|
}),
|
|
254
243
|
]}
|
|
255
244
|
>
|
|
256
|
-
{
|
|
245
|
+
{renderSheetHeader(headerParams)}
|
|
246
|
+
<View style={contentStyle}>{screen}</View>
|
|
257
247
|
{renderSheetFooter({ footerComponent, theme })}
|
|
258
248
|
{useBottomInset && (
|
|
259
249
|
<View
|
|
@@ -17,6 +17,7 @@ import BackgroundImageView from './BackgroundImageView';
|
|
|
17
17
|
import { type AnimatedCompatValue } from '../utils';
|
|
18
18
|
import { useNormalizedSharedValue } from '../hooks';
|
|
19
19
|
import { useScreenLayout } from '../../Layout';
|
|
20
|
+
import { getHeaderMargin } from '../../Layout/utils';
|
|
20
21
|
import {
|
|
21
22
|
HeaderBarMetrics,
|
|
22
23
|
type HeaderContentLayout,
|
|
@@ -69,8 +70,12 @@ const HeaderExtendHeader: React.FC<{
|
|
|
69
70
|
const headerBackground = customBackground ?? theme.assets?.headerBackground;
|
|
70
71
|
const layout = useScreenLayout();
|
|
71
72
|
const headerLayout = useHeaderLayout(contentLayout);
|
|
72
|
-
// collapsed into the bar, the search follows back and the right cluster into the
|
|
73
|
-
|
|
73
|
+
// collapsed into the bar, the search follows back and the right cluster into the
|
|
74
|
+
// frame, or the side margin React Navigation adds on large iOS windows (the larger)
|
|
75
|
+
let frameShift = headerLayout.frameInset - sidePadding;
|
|
76
|
+
if (!layout.sideBar) {
|
|
77
|
+
frameShift = Math.max(frameShift, getHeaderMargin(layout.width));
|
|
78
|
+
}
|
|
74
79
|
|
|
75
80
|
const backLeft = buttonSize + sidePadding + titleGap;
|
|
76
81
|
const defaultLeft = layout.sideBar ? SCREEN_PADDING : backLeft;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BackHandler,
|
|
1
|
+
import { BackHandler, StyleSheet, View } from 'react-native';
|
|
2
2
|
import type { HeaderBackProps } from '../types';
|
|
3
3
|
import React, { useCallback, useContext, useEffect } from 'react';
|
|
4
4
|
import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
@@ -8,12 +8,11 @@ import { SideBarButton } from './SideBarButton';
|
|
|
8
8
|
import Animated from 'react-native-reanimated';
|
|
9
9
|
import { useSideBarItemStyle } from '../../Layout/utils';
|
|
10
10
|
import { useSideBarCounterStyle } from './DuoQuickReturnHeader';
|
|
11
|
-
import {
|
|
11
|
+
import { HeaderBarMetrics } from '../headerLayout';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Header back button, also bound to the Android hardware back. `preventBack`
|
|
15
15
|
* confirms in a popup first; the iPhone Duo side bar uses the 48pt side bar button.
|
|
16
|
-
* In the bar it sits `sidePadding` from the window edge on every iPhone width.
|
|
17
16
|
*/
|
|
18
17
|
const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
19
18
|
tintColor,
|
|
@@ -26,7 +25,6 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
26
25
|
const { navigator } = useContext(ApplicationContext);
|
|
27
26
|
const sideBarStyle = useSideBarItemStyle('left', 0);
|
|
28
27
|
const counterStyle = useSideBarCounterStyle();
|
|
29
|
-
const { width } = useWindowDimensions();
|
|
30
28
|
|
|
31
29
|
const goBack = useCallback(() => {
|
|
32
30
|
const canGoBack = navigator?.ref?.current?.canGoBack?.();
|
|
@@ -100,7 +98,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
return (
|
|
103
|
-
<View style={
|
|
101
|
+
<View style={styles.headerLeft}>
|
|
104
102
|
<NavigationButton
|
|
105
103
|
accessibilityLabel="btn_navigation_back"
|
|
106
104
|
icon="arrow-back"
|
|
@@ -111,4 +109,10 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
111
109
|
);
|
|
112
110
|
};
|
|
113
111
|
|
|
112
|
+
const styles = StyleSheet.create({
|
|
113
|
+
headerLeft: {
|
|
114
|
+
marginLeft: HeaderBarMetrics.sidePadding,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
114
118
|
export { HeaderLeft };
|
|
@@ -2,7 +2,7 @@ import { Platform, StyleSheet } from 'react-native';
|
|
|
2
2
|
import { Colors, Spacing } from '../../Consts';
|
|
3
3
|
import { HeaderBarMetrics } from '../headerLayout';
|
|
4
4
|
|
|
5
|
-
const { buttonSize, pillWidth, pillHeight } = HeaderBarMetrics;
|
|
5
|
+
const { buttonSize, pillWidth, pillHeight, sidePadding } = HeaderBarMetrics;
|
|
6
6
|
|
|
7
7
|
export const styles = StyleSheet.create({
|
|
8
8
|
navigationButton: {
|
|
@@ -48,6 +48,7 @@ export const styles = StyleSheet.create({
|
|
|
48
48
|
flexDirection: 'row',
|
|
49
49
|
justifyContent: 'center',
|
|
50
50
|
alignItems: 'center',
|
|
51
|
+
paddingRight: sidePadding,
|
|
51
52
|
},
|
|
52
53
|
toolkitContainer: {
|
|
53
54
|
height: pillHeight,
|
|
@@ -133,6 +134,9 @@ export const styles = StyleSheet.create({
|
|
|
133
134
|
},
|
|
134
135
|
}),
|
|
135
136
|
},
|
|
137
|
+
onBoarding: {
|
|
138
|
+
marginRight: Spacing.M,
|
|
139
|
+
},
|
|
136
140
|
toolkitWide: {
|
|
137
141
|
width: pillWidth,
|
|
138
142
|
},
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import React, { useCallback, useContext, useEffect } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
type LayoutChangeEvent,
|
|
4
|
-
TouchableOpacity,
|
|
5
|
-
useWindowDimensions,
|
|
6
|
-
View,
|
|
7
|
-
} from 'react-native';
|
|
2
|
+
import { type LayoutChangeEvent, TouchableOpacity, View } from 'react-native';
|
|
8
3
|
import { NavigationRouteContext } from '@react-navigation/native';
|
|
9
4
|
import { ApplicationContext } from '../../Context';
|
|
10
5
|
import { Text } from '../../Text';
|
|
11
6
|
import Animated from 'react-native-reanimated';
|
|
12
|
-
import {
|
|
13
|
-
import { getHeaderRowInset } from '../headerLayout';
|
|
7
|
+
import { useSideBarItemStyle } from '../../Layout/utils';
|
|
14
8
|
import { useSideBarCounterStyle } from './DuoQuickReturnHeader';
|
|
15
9
|
import { HeaderToolkitAction } from './HeaderToolkitAction';
|
|
16
10
|
import { styles } from './HeaderRight.styles';
|
|
@@ -19,8 +13,7 @@ import { setHeaderRightWidth } from './useHeaderRightWidth';
|
|
|
19
13
|
/**
|
|
20
14
|
* Header right slot: a custom `headerRight` render function, the onboarding skip
|
|
21
15
|
* button, or the toolkit (stacked vertically in the floating iPhone Duo side bar).
|
|
22
|
-
* The bar toolkit
|
|
23
|
-
* from that edge so header searches stop short of it.
|
|
16
|
+
* The bar toolkit reports its width so header searches stop short of it.
|
|
24
17
|
*/
|
|
25
18
|
const HeaderRight: React.FC<any> = props => {
|
|
26
19
|
const { translate } = useContext(ApplicationContext);
|
|
@@ -29,18 +22,14 @@ const HeaderRight: React.FC<any> = props => {
|
|
|
29
22
|
const sideBarStyle = useSideBarItemStyle('right', 1);
|
|
30
23
|
const counterStyle = useSideBarCounterStyle();
|
|
31
24
|
const routeKey = useContext(NavigationRouteContext)?.key;
|
|
32
|
-
const { width } = useWindowDimensions();
|
|
33
|
-
const rowMargin = getHeaderMargin(width);
|
|
34
|
-
const rowInset = getHeaderRowInset(width);
|
|
35
25
|
|
|
36
26
|
const handleToolkitLayout = useCallback(
|
|
37
27
|
(event: LayoutChangeEvent) => {
|
|
38
28
|
if (routeKey) {
|
|
39
|
-
|
|
40
|
-
setHeaderRightWidth(routeKey, toolkitWidth);
|
|
29
|
+
setHeaderRightWidth(routeKey, event.nativeEvent.layout.width);
|
|
41
30
|
}
|
|
42
31
|
},
|
|
43
|
-
[routeKey
|
|
32
|
+
[routeKey],
|
|
44
33
|
);
|
|
45
34
|
|
|
46
35
|
useEffect(() => {
|
|
@@ -57,7 +46,7 @@ const HeaderRight: React.FC<any> = props => {
|
|
|
57
46
|
|
|
58
47
|
if (useOnBoarding && onPress) {
|
|
59
48
|
return (
|
|
60
|
-
<TouchableOpacity onPress={onPress} style={
|
|
49
|
+
<TouchableOpacity onPress={onPress} style={styles.onBoarding}>
|
|
61
50
|
<Text typography={'action_s_bold'}>
|
|
62
51
|
{buttonOnBoarding || translate?.('skip')}
|
|
63
52
|
</Text>
|
|
@@ -81,10 +70,7 @@ const HeaderRight: React.FC<any> = props => {
|
|
|
81
70
|
}
|
|
82
71
|
|
|
83
72
|
return (
|
|
84
|
-
<View
|
|
85
|
-
style={[styles.headerRightButton, { paddingRight: rowInset }]}
|
|
86
|
-
onLayout={handleToolkitLayout}
|
|
87
|
-
>
|
|
73
|
+
<View style={styles.headerRightButton} onLayout={handleToolkitLayout}>
|
|
88
74
|
<HeaderToolkitAction {...props.headerRight} tintColor={props.tintColor} />
|
|
89
75
|
</View>
|
|
90
76
|
);
|
|
@@ -8,6 +8,7 @@ import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
|
8
8
|
import { Text } from '../../Text';
|
|
9
9
|
import { useNormalizedSharedValue } from '../hooks';
|
|
10
10
|
import { useScreenLayout } from '../../Layout';
|
|
11
|
+
import { getHeaderMargin } from '../../Layout/utils';
|
|
11
12
|
import { HeaderBarMetrics } from '../headerLayout';
|
|
12
13
|
import { useHeaderRightWidth } from './useHeaderRightWidth';
|
|
13
14
|
|
|
@@ -46,7 +47,10 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
46
47
|
const headerRightWidth = props?.headerRightWidth ?? defaultRightWidth;
|
|
47
48
|
|
|
48
49
|
// iPhone Duo side bar holds back: the search shares the content width with the buttons only
|
|
49
|
-
|
|
50
|
+
// large iOS windows: React Navigation narrows the header row by a margin each side
|
|
51
|
+
const headerMargin = getHeaderMargin(layout.width);
|
|
52
|
+
const rowWidth =
|
|
53
|
+
layout.width - leftPosition - sidePadding - headerMargin * 2;
|
|
50
54
|
let searchMaxWidth = rowWidth - headerRightWidth;
|
|
51
55
|
if (layout.sideBar) {
|
|
52
56
|
searchMaxWidth = layout.contentWidth - Spacing.M * 2 - headerRightWidth;
|
|
@@ -16,8 +16,8 @@ const subscribe = (listener: () => void) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Records
|
|
20
|
-
*
|
|
19
|
+
* Records the laid out width of a route's header right, side padding included;
|
|
20
|
+
* `undefined` clears it when the header right unmounts.
|
|
21
21
|
*/
|
|
22
22
|
const setHeaderRightWidth = (routeKey: string, width?: number) => {
|
|
23
23
|
if (widths.get(routeKey) === width) {
|
|
@@ -6,12 +6,14 @@ import {
|
|
|
6
6
|
ViewStyle,
|
|
7
7
|
} from 'react-native';
|
|
8
8
|
import { ApplicationContext } from '../Context';
|
|
9
|
-
import {
|
|
9
|
+
import { Colors } from '../Consts';
|
|
10
10
|
import { Icon } from '../Icon';
|
|
11
|
+
import { HeaderBarMetrics } from './headerLayout';
|
|
11
12
|
|
|
12
|
-
//
|
|
13
|
-
const MODAL_ICON_BUTTON_SIZE =
|
|
14
|
-
const MODAL_ICON_SIZE =
|
|
13
|
+
// same round button as the Top nav (NavigationButton), shared with the Compose / SwiftUI kits
|
|
14
|
+
const MODAL_ICON_BUTTON_SIZE = HeaderBarMetrics.buttonSize;
|
|
15
|
+
const MODAL_ICON_SIZE = HeaderBarMetrics.iconSize;
|
|
16
|
+
const MODAL_ICON_BUTTON_BORDER_WIDTH = 0.2;
|
|
15
17
|
|
|
16
18
|
type ModalIconButtonProps = {
|
|
17
19
|
icon: string;
|
|
@@ -21,7 +23,8 @@ type ModalIconButtonProps = {
|
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
|
-
* Close / back button of popups and bottom sheet headers
|
|
26
|
+
* Close / back button of popups and bottom sheet headers, drawn like the round
|
|
27
|
+
* Top nav icon button so modals and headers share one look.
|
|
25
28
|
*/
|
|
26
29
|
const ModalIconButton: React.FC<ModalIconButtonProps> = ({
|
|
27
30
|
icon,
|
|
@@ -34,14 +37,7 @@ const ModalIconButton: React.FC<ModalIconButtonProps> = ({
|
|
|
34
37
|
<TouchableOpacity
|
|
35
38
|
accessibilityLabel={accessibilityLabel}
|
|
36
39
|
onPress={onPress}
|
|
37
|
-
style={[
|
|
38
|
-
styles.button,
|
|
39
|
-
{
|
|
40
|
-
backgroundColor: theme.colors.background.surface,
|
|
41
|
-
borderColor: theme.colors.border.default,
|
|
42
|
-
},
|
|
43
|
-
style,
|
|
44
|
-
]}
|
|
40
|
+
style={[styles.button, style]}
|
|
45
41
|
>
|
|
46
42
|
<Icon
|
|
47
43
|
source={icon}
|
|
@@ -56,10 +52,12 @@ const styles = StyleSheet.create({
|
|
|
56
52
|
button: {
|
|
57
53
|
width: MODAL_ICON_BUTTON_SIZE,
|
|
58
54
|
height: MODAL_ICON_BUTTON_SIZE,
|
|
59
|
-
borderRadius:
|
|
60
|
-
borderWidth:
|
|
55
|
+
borderRadius: MODAL_ICON_BUTTON_SIZE / 2,
|
|
56
|
+
borderWidth: MODAL_ICON_BUTTON_BORDER_WIDTH,
|
|
61
57
|
alignItems: 'center',
|
|
62
58
|
justifyContent: 'center',
|
|
59
|
+
backgroundColor: Colors.black_01 + '99',
|
|
60
|
+
borderColor: Colors.black_20 + '33',
|
|
63
61
|
},
|
|
64
62
|
});
|
|
65
63
|
|
|
@@ -46,7 +46,8 @@ const ModalScreen: React.FC<any> = props => {
|
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Centered popup that fades and scales in over a scrim. On foldables it is
|
|
49
|
-
* centered
|
|
49
|
+
* centered on the window (`popup.x`), clear of the iPhone Duo control column,
|
|
50
|
+
* at most a popup wide.
|
|
50
51
|
*/
|
|
51
52
|
const Modal: React.FC<ModalParams> = props => {
|
|
52
53
|
const { navigator } = useContext(ApplicationContext);
|
|
@@ -156,6 +157,14 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
156
157
|
return () => backHandler.remove();
|
|
157
158
|
}, [barrierDismissible, handleDismiss]);
|
|
158
159
|
|
|
160
|
+
// popup.x centers it on the window; without it, centered in the placement
|
|
161
|
+
let popupLeft = placement.x;
|
|
162
|
+
let popupRight = width - placement.x - placement.width;
|
|
163
|
+
if (popup.x !== undefined) {
|
|
164
|
+
popupLeft = popup.x;
|
|
165
|
+
popupRight = Math.max(width - popup.x - popup.width, 0);
|
|
166
|
+
}
|
|
167
|
+
|
|
159
168
|
return (
|
|
160
169
|
<Container
|
|
161
170
|
transparent
|
|
@@ -181,13 +190,13 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
181
190
|
opacity,
|
|
182
191
|
transform: [{ scale }],
|
|
183
192
|
},
|
|
184
|
-
// centered
|
|
193
|
+
// centered on the window at popup.x, clear of the control column, at most a popup wide
|
|
185
194
|
isFoldable && styles.shrink,
|
|
186
195
|
isFoldable && {
|
|
187
196
|
marginTop: placement.y,
|
|
188
197
|
marginBottom: height - placement.y - placement.height,
|
|
189
|
-
marginLeft:
|
|
190
|
-
marginRight:
|
|
198
|
+
marginLeft: popupLeft,
|
|
199
|
+
marginRight: popupRight,
|
|
191
200
|
maxWidth: popup.width,
|
|
192
201
|
maxHeight: popup.maxHeight,
|
|
193
202
|
},
|
|
@@ -69,7 +69,7 @@ describe('getHeaderFrameOptions', () => {
|
|
|
69
69
|
isDuo: false,
|
|
70
70
|
contentLayout,
|
|
71
71
|
});
|
|
72
|
-
return { layout, isDuo: false, edgePadding: NO_EDGE };
|
|
72
|
+
return { layout, isDuo: false, headerMargin: 0, edgePadding: NO_EDGE };
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
it('leaves the options alone when contentLayout is unset', () => {
|
|
@@ -103,6 +103,7 @@ describe('getHeaderFrameOptions', () => {
|
|
|
103
103
|
const options = getHeaderFrameOptions({
|
|
104
104
|
layout,
|
|
105
105
|
isDuo: true,
|
|
106
|
+
headerMargin: 0,
|
|
106
107
|
edgePadding: DUO_EDGE,
|
|
107
108
|
contentLayout: 'stretch',
|
|
108
109
|
});
|
|
@@ -85,6 +85,8 @@ type EdgePadding = { left: number; right: number };
|
|
|
85
85
|
type HeaderFrameInput = {
|
|
86
86
|
layout: HeaderLayout;
|
|
87
87
|
isDuo: boolean;
|
|
88
|
+
// side margin @react-navigation/elements already adds to the row
|
|
89
|
+
headerMargin: number;
|
|
88
90
|
// padding of the plain row containers: the iPhone Duo status bar clearance, else 0
|
|
89
91
|
edgePadding: EdgePadding;
|
|
90
92
|
contentLayout?: HeaderContentLayout;
|
|
@@ -121,14 +123,6 @@ const getHeaderLayout = ({
|
|
|
121
123
|
};
|
|
122
124
|
};
|
|
123
125
|
|
|
124
|
-
/**
|
|
125
|
-
* Inset from the React Navigation header row that puts an item `sidePadding` from
|
|
126
|
-
* the window edge: large iOS windows already inset that row by `getHeaderMargin`.
|
|
127
|
-
*/
|
|
128
|
-
const getHeaderRowInset = (width: number) => {
|
|
129
|
-
return HeaderBarMetrics.sidePadding - getHeaderMargin(width);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
126
|
/**
|
|
133
127
|
* Widest a title can be between back and the right cluster of the header row.
|
|
134
128
|
*/
|
|
@@ -195,6 +189,7 @@ const getEdgeFrameOptions = (
|
|
|
195
189
|
const getHeaderFrameOptions = ({
|
|
196
190
|
layout,
|
|
197
191
|
isDuo,
|
|
192
|
+
headerMargin,
|
|
198
193
|
edgePadding,
|
|
199
194
|
contentLayout,
|
|
200
195
|
}: HeaderFrameInput): StackNavigationOptions | undefined => {
|
|
@@ -204,11 +199,12 @@ const getHeaderFrameOptions = ({
|
|
|
204
199
|
if (contentLayout !== 'stretch' || isDuo) {
|
|
205
200
|
return getEdgeFrameOptions(edgePadding);
|
|
206
201
|
}
|
|
207
|
-
//
|
|
202
|
+
// the header content row already sits this far in on large iOS windows
|
|
208
203
|
const shift = layout.frameInset - layout.sidePadding;
|
|
204
|
+
const containerShift = Math.max(0, shift - headerMargin);
|
|
209
205
|
return {
|
|
210
|
-
headerLeftContainerStyle: { paddingLeft:
|
|
211
|
-
headerRightContainerStyle: { paddingRight:
|
|
206
|
+
headerLeftContainerStyle: { paddingLeft: containerShift },
|
|
207
|
+
headerRightContainerStyle: { paddingRight: containerShift },
|
|
212
208
|
headerTitleContainerStyle: {
|
|
213
209
|
...TITLE_CONTAINER_RESET,
|
|
214
210
|
left: layout.titleGap,
|
|
@@ -229,15 +225,17 @@ const useHeaderFrameOptions = (
|
|
|
229
225
|
const rowOptions = getHeaderRowOptions(screenLayout);
|
|
230
226
|
const edgeLeft = rowOptions.headerLeftContainerStyle?.paddingLeft ?? 0;
|
|
231
227
|
const edgeRight = rowOptions.headerRightContainerStyle?.paddingRight ?? 0;
|
|
228
|
+
const headerMargin = getHeaderMargin(screenLayout.width);
|
|
232
229
|
const isDuo = isIPhoneDuo();
|
|
233
230
|
return useMemo(() => {
|
|
234
231
|
return getHeaderFrameOptions({
|
|
235
232
|
layout,
|
|
236
233
|
isDuo,
|
|
234
|
+
headerMargin,
|
|
237
235
|
edgePadding: { left: edgeLeft, right: edgeRight },
|
|
238
236
|
contentLayout,
|
|
239
237
|
});
|
|
240
|
-
}, [contentLayout, isDuo, layout, edgeLeft, edgeRight]);
|
|
238
|
+
}, [contentLayout, isDuo, layout, headerMargin, edgeLeft, edgeRight]);
|
|
241
239
|
};
|
|
242
240
|
|
|
243
241
|
export type { HeaderContentLayout, HeaderLayout };
|
|
@@ -249,7 +247,6 @@ export {
|
|
|
249
247
|
getHeaderFrameOptions,
|
|
250
248
|
getHeaderLayout,
|
|
251
249
|
getSearchHeaderHeight,
|
|
252
|
-
getHeaderRowInset,
|
|
253
250
|
getTitleBudget,
|
|
254
251
|
useHeaderLayout,
|
|
255
252
|
useHeaderFrameOptions,
|
|
@@ -8,7 +8,7 @@ import { isIPhoneDuo } from './utils';
|
|
|
8
8
|
const POPUP_MAX_WIDTH = 450;
|
|
9
9
|
const POPUP_MIN_WIDTH = 280;
|
|
10
10
|
const POPUP_MAX_HEIGHT = 600;
|
|
11
|
-
const SHEET_MAX_WIDTH =
|
|
11
|
+
const SHEET_MAX_WIDTH = 600;
|
|
12
12
|
const SHEET_MIN_WIDTH = 296;
|
|
13
13
|
const SHEET_MIN_HEIGHT = 230;
|
|
14
14
|
const FOLDABLE_MIN_WIDTH = 600;
|
|
@@ -46,6 +46,12 @@ export type ModalLayout = {
|
|
|
46
46
|
maxHeight?: number;
|
|
47
47
|
margin: number;
|
|
48
48
|
radius: number;
|
|
49
|
+
/**
|
|
50
|
+
* Window x of the left edge of a `width` wide popup, `undefined` on phones.
|
|
51
|
+
* Centered on the window, but a margin clear of the iPhone Duo control
|
|
52
|
+
* column / system insets; half folded it is centered in the right half.
|
|
53
|
+
*/
|
|
54
|
+
x?: number;
|
|
49
55
|
};
|
|
50
56
|
|
|
51
57
|
sheet: {
|
|
@@ -53,6 +59,12 @@ export type ModalLayout = {
|
|
|
53
59
|
* `undefined` on phones, the sheet spans the window.
|
|
54
60
|
*/
|
|
55
61
|
width?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Window x of the sheet's left edge, `undefined` on phones. Centered on the
|
|
64
|
+
* window, but kept a margin clear of the iPhone Duo control column / system
|
|
65
|
+
* insets; half folded it is centered in the right half.
|
|
66
|
+
*/
|
|
67
|
+
x?: number;
|
|
56
68
|
maxHeight?: number;
|
|
57
69
|
minHeight?: number;
|
|
58
70
|
margin: number;
|
|
@@ -78,6 +90,25 @@ const clamp = (value: number, min: number, max: number) => {
|
|
|
78
90
|
return Math.min(Math.max(value, min), max);
|
|
79
91
|
};
|
|
80
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Window x of a `boxWidth` wide overlay: centered on `center` (the window, so
|
|
95
|
+
* an inset on one side does not push it off center) but `margin` inside the
|
|
96
|
+
* placement; centered in the placement when it does not fit with the margins.
|
|
97
|
+
*/
|
|
98
|
+
const overlayX = (
|
|
99
|
+
center: number,
|
|
100
|
+
placement: ModalRect,
|
|
101
|
+
boxWidth: number,
|
|
102
|
+
margin: number,
|
|
103
|
+
) => {
|
|
104
|
+
const min = placement.x + margin;
|
|
105
|
+
const max = placement.x + placement.width - margin - boxWidth;
|
|
106
|
+
if (max < min) {
|
|
107
|
+
return placement.x + (placement.width - boxWidth) / 2;
|
|
108
|
+
}
|
|
109
|
+
return clamp(center - boxWidth / 2, min, max);
|
|
110
|
+
};
|
|
111
|
+
|
|
81
112
|
/**
|
|
82
113
|
* Modal geometry for a window, pure so it can be tested without a device.
|
|
83
114
|
*/
|
|
@@ -130,12 +161,20 @@ const getModalLayout = ({
|
|
|
130
161
|
const sheetSpace = placement.width - sheetMargin * 2;
|
|
131
162
|
const sheetMinWidth = Math.min(SHEET_MIN_WIDTH, sheetSpace);
|
|
132
163
|
const sheetMaxHeight = height - insets.top - Spacing.M;
|
|
164
|
+
const sheetWidth = clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH);
|
|
165
|
+
const popupWidth = clamp(popupSpace, popupMinWidth, POPUP_MAX_WIDTH);
|
|
166
|
+
// the window center; half folded, the right half's
|
|
167
|
+
let overlayCenter = width / 2;
|
|
168
|
+
if (isHalfFolded) {
|
|
169
|
+
overlayCenter = placement.x + placement.width / 2;
|
|
170
|
+
}
|
|
133
171
|
|
|
134
172
|
return {
|
|
135
173
|
isFoldable,
|
|
136
174
|
placement,
|
|
137
175
|
popup: {
|
|
138
|
-
width:
|
|
176
|
+
width: popupWidth,
|
|
177
|
+
x: overlayX(overlayCenter, placement, popupWidth, popupMargin),
|
|
139
178
|
minWidth: popupMinWidth,
|
|
140
179
|
maxWidth: POPUP_MAX_WIDTH,
|
|
141
180
|
maxHeight: Math.min(POPUP_MAX_HEIGHT, placement.height - Spacing.XL * 2),
|
|
@@ -143,7 +182,8 @@ const getModalLayout = ({
|
|
|
143
182
|
radius: Radius.XL,
|
|
144
183
|
},
|
|
145
184
|
sheet: {
|
|
146
|
-
width:
|
|
185
|
+
width: sheetWidth,
|
|
186
|
+
x: overlayX(overlayCenter, placement, sheetWidth, sheetMargin),
|
|
147
187
|
maxHeight: sheetMaxHeight,
|
|
148
188
|
minHeight: Math.min(SHEET_MIN_HEIGHT, sheetMaxHeight),
|
|
149
189
|
margin: sheetMargin,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
3
|
import {
|
|
4
4
|
CardStyleInterpolators,
|
|
5
5
|
type StackCardInterpolatedStyle,
|
|
@@ -13,11 +13,7 @@ import { HeaderBackground } from './Components/HeaderBackground';
|
|
|
13
13
|
import { HeaderLeft } from './Components/HeaderLeft';
|
|
14
14
|
import { HeaderRight } from './Components/HeaderRight';
|
|
15
15
|
import { HeaderTitle, TitleCustom } from './Components/HeaderTitle';
|
|
16
|
-
import {
|
|
17
|
-
getHeaderRowInset,
|
|
18
|
-
HeaderBarMetrics,
|
|
19
|
-
TITLE_CONTAINER_RESET,
|
|
20
|
-
} from './headerLayout';
|
|
16
|
+
import { HeaderBarMetrics, TITLE_CONTAINER_RESET } from './headerLayout';
|
|
21
17
|
import type { HeaderTitleProps, NavigationOptions } from './types';
|
|
22
18
|
|
|
23
19
|
const CARD_SHADOW_OPACITY = 0.3;
|
|
@@ -148,9 +144,8 @@ const exportHeaderTitle = (
|
|
|
148
144
|
};
|
|
149
145
|
|
|
150
146
|
/**
|
|
151
|
-
* React Navigation options from screen params: design system header left,
|
|
152
|
-
*
|
|
153
|
-
* off for screens that own their back flow.
|
|
147
|
+
* React Navigation options from screen params: design system header left,
|
|
148
|
+
* title and right, and swipe back off for screens that own their back flow.
|
|
154
149
|
*/
|
|
155
150
|
const getOptions = (
|
|
156
151
|
params: NavigationOptions,
|
|
@@ -172,11 +167,9 @@ const getOptions = (
|
|
|
172
167
|
};
|
|
173
168
|
if (params.hiddenBack) {
|
|
174
169
|
headerLeft = null;
|
|
175
|
-
// options are static, so the window width is read once when they are built
|
|
176
|
-
const { width } = Dimensions.get('window');
|
|
177
170
|
options.headerTitleContainerStyle = {
|
|
178
171
|
...TITLE_CONTAINER_RESET,
|
|
179
|
-
left:
|
|
172
|
+
left: HeaderBarMetrics.sidePadding,
|
|
180
173
|
};
|
|
181
174
|
}
|
|
182
175
|
options = {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import { Colors, Spacing, Styles } from '../Consts';
|
|
4
|
+
import { Icon } from '../Icon';
|
|
5
|
+
import { Image } from '../Image';
|
|
6
|
+
import { Text } from '../Text';
|
|
7
|
+
import { Typography } from '../Text/types';
|
|
8
|
+
import styles from './styles';
|
|
9
|
+
|
|
10
|
+
const FLAG_SIZE = 24;
|
|
11
|
+
const CHEVRON_SIZE = 16;
|
|
12
|
+
|
|
13
|
+
type CountryCodeViewProps = {
|
|
14
|
+
countryCode: string;
|
|
15
|
+
countryFlag: string;
|
|
16
|
+
typography: Typography;
|
|
17
|
+
textColor: string;
|
|
18
|
+
dividerHeight: number;
|
|
19
|
+
componentId: string;
|
|
20
|
+
isDisabled: boolean;
|
|
21
|
+
onPress?: () => void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Flag, dial code and divider ahead of a phone number. Only becomes a button,
|
|
26
|
+
* with a chevron after the code, when `onPress` is given, so the default
|
|
27
|
+
* render stays a plain view.
|
|
28
|
+
*/
|
|
29
|
+
const CountryCodeView: React.FC<CountryCodeViewProps> = ({
|
|
30
|
+
countryCode,
|
|
31
|
+
countryFlag,
|
|
32
|
+
typography,
|
|
33
|
+
textColor,
|
|
34
|
+
dividerHeight,
|
|
35
|
+
componentId,
|
|
36
|
+
isDisabled,
|
|
37
|
+
onPress,
|
|
38
|
+
}) => {
|
|
39
|
+
const content = (
|
|
40
|
+
<>
|
|
41
|
+
<Image
|
|
42
|
+
source={{ uri: countryFlag }}
|
|
43
|
+
style={innerStyle.iconFlag}
|
|
44
|
+
resizeMode="contain"
|
|
45
|
+
accessibilityLabel={`${componentId}|leading-icon`}
|
|
46
|
+
/>
|
|
47
|
+
<View style={{ width: Spacing.XS }} />
|
|
48
|
+
<Text typography={typography} color={textColor}>
|
|
49
|
+
{countryCode}
|
|
50
|
+
</Text>
|
|
51
|
+
{/* Kept while disabled (greyed by textColor) so the layout doesn't shift. */}
|
|
52
|
+
{onPress && (
|
|
53
|
+
<Icon
|
|
54
|
+
source="arrow_chevron_down_small"
|
|
55
|
+
size={CHEVRON_SIZE}
|
|
56
|
+
color={textColor}
|
|
57
|
+
style={innerStyle.chevron}
|
|
58
|
+
accessibilityLabel={`${componentId}|leading-chevron`}
|
|
59
|
+
/>
|
|
60
|
+
)}
|
|
61
|
+
</>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const renderContent = () => {
|
|
65
|
+
if (!onPress) {
|
|
66
|
+
return content;
|
|
67
|
+
}
|
|
68
|
+
return (
|
|
69
|
+
<TouchableOpacity
|
|
70
|
+
style={Styles.row}
|
|
71
|
+
onPress={onPress}
|
|
72
|
+
disabled={isDisabled}
|
|
73
|
+
accessibilityRole="button"
|
|
74
|
+
accessibilityLabel={`${componentId}|leading-icon-touch|${countryCode}`}
|
|
75
|
+
accessibilityState={{ disabled: isDisabled }}
|
|
76
|
+
>
|
|
77
|
+
{content}
|
|
78
|
+
</TouchableOpacity>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<View style={[styles.leadingIconContainer, Styles.row]}>
|
|
84
|
+
{renderContent()}
|
|
85
|
+
<View
|
|
86
|
+
style={[
|
|
87
|
+
styles.phoneNumberDivider,
|
|
88
|
+
{
|
|
89
|
+
height: dividerHeight,
|
|
90
|
+
backgroundColor: Colors.black_04,
|
|
91
|
+
},
|
|
92
|
+
]}
|
|
93
|
+
/>
|
|
94
|
+
</View>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const innerStyle = StyleSheet.create({
|
|
99
|
+
iconFlag: {
|
|
100
|
+
width: FLAG_SIZE,
|
|
101
|
+
height: FLAG_SIZE,
|
|
102
|
+
marginHorizontal: Spacing.XXS,
|
|
103
|
+
},
|
|
104
|
+
chevron: {
|
|
105
|
+
marginLeft: Spacing.XS,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export { CountryCodeView };
|
package/Input/ErrorView.tsx
CHANGED
package/Input/InputMoneyView.tsx
CHANGED
|
@@ -53,8 +53,8 @@ type InputMoneyViewProps = Pick<
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* Presentational body of InputMoney: bordered field, currency suffix (
|
|
57
|
-
*
|
|
56
|
+
* Presentational body of InputMoney: bordered field, currency suffix (shown
|
|
57
|
+
* once there is a value) and the clear/trailing icons.
|
|
58
58
|
*/
|
|
59
59
|
export const InputMoneyView = ({
|
|
60
60
|
size,
|
|
@@ -101,13 +101,8 @@ export const InputMoneyView = ({
|
|
|
101
101
|
fontSize: scaledFontSize,
|
|
102
102
|
fontFamily: inputFontFamily,
|
|
103
103
|
};
|
|
104
|
-
const
|
|
105
|
-
const shouldShowCurrency = !!displayValue || hasCurrencyInPlaceholder;
|
|
104
|
+
const hasValue = displayValue.length > 0;
|
|
106
105
|
const shouldShowClearIcon = !!(showClearIcon && focused && displayValue);
|
|
107
|
-
let inputPlaceholder = placeholder;
|
|
108
|
-
if (hasCurrencyInPlaceholder) {
|
|
109
|
-
inputPlaceholder = placeholder.slice(0, -currency.length);
|
|
110
|
-
}
|
|
111
106
|
return (
|
|
112
107
|
<View
|
|
113
108
|
style={[
|
|
@@ -148,18 +143,15 @@ export const InputMoneyView = ({
|
|
|
148
143
|
onChangeText={onChangeText}
|
|
149
144
|
onFocus={onFocus}
|
|
150
145
|
onBlur={onBlur}
|
|
151
|
-
placeholder={
|
|
146
|
+
placeholder={placeholder}
|
|
152
147
|
selectionColor={theme.colors.primary}
|
|
153
148
|
placeholderTextColor={placeholderColor}
|
|
154
149
|
keyboardType={'numeric'}
|
|
155
150
|
maxLength={undefined}
|
|
156
151
|
/>
|
|
157
|
-
{
|
|
152
|
+
{hasValue && (
|
|
158
153
|
<Text
|
|
159
|
-
style={[
|
|
160
|
-
textStyle,
|
|
161
|
-
{ color: displayValue ? textColor : placeholderColor },
|
|
162
|
-
]}
|
|
154
|
+
style={[textStyle, { color: textColor }]}
|
|
163
155
|
allowFontScaling={false}
|
|
164
156
|
>
|
|
165
157
|
{currency}
|
|
@@ -6,7 +6,6 @@ import React, {
|
|
|
6
6
|
useState,
|
|
7
7
|
} from 'react';
|
|
8
8
|
import {
|
|
9
|
-
StyleSheet,
|
|
10
9
|
TextInput,
|
|
11
10
|
TextInputFocusEvent,
|
|
12
11
|
TouchableOpacity,
|
|
@@ -18,12 +17,11 @@ import {
|
|
|
18
17
|
ComponentContext,
|
|
19
18
|
MiniAppContext,
|
|
20
19
|
} from '../Context';
|
|
21
|
-
import { Colors, Spacing, Styles } from '../Consts';
|
|
22
20
|
import { Icon } from '../Icon';
|
|
23
|
-
import {
|
|
24
|
-
import { useScaleSize, Text, exportFontFamily } from '../Text';
|
|
21
|
+
import { useScaleSize, exportFontFamily } from '../Text';
|
|
25
22
|
import { Typography } from '../Text/types';
|
|
26
23
|
import { CLEAR_ICON_SIZE } from './constants';
|
|
24
|
+
import { CountryCodeView } from './CountryCodeView';
|
|
27
25
|
import { ErrorView } from './ErrorView';
|
|
28
26
|
import { InputPhoneNumberProps } from './index';
|
|
29
27
|
import { RenderTrailing } from './RenderTrailing';
|
|
@@ -36,11 +34,13 @@ const LARGE_FONT_SIZE = 18;
|
|
|
36
34
|
const SMALL_DIVIDER_HEIGHT = 24;
|
|
37
35
|
const LARGE_DIVIDER_HEIGHT = 32;
|
|
38
36
|
const FOCUSED_BORDER_WIDTH = 1.5;
|
|
39
|
-
const
|
|
37
|
+
const DEFAULT_COUNTRY_CODE = '+84';
|
|
38
|
+
const DEFAULT_COUNTRY_FLAG =
|
|
39
|
+
'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png';
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
* by default, plus clear and trailing icons.
|
|
42
|
+
* Phone number input behind a country flag and dial code (Vietnam `+84` by
|
|
43
|
+
* default), number pad by default, plus clear and trailing icons.
|
|
44
44
|
*/
|
|
45
45
|
const InputPhoneNumber = forwardRef(
|
|
46
46
|
(
|
|
@@ -66,6 +66,9 @@ const InputPhoneNumber = forwardRef(
|
|
|
66
66
|
editable = true,
|
|
67
67
|
showClearIcon = true,
|
|
68
68
|
defaultValue,
|
|
69
|
+
countryCode = DEFAULT_COUNTRY_CODE,
|
|
70
|
+
countryFlag = DEFAULT_COUNTRY_FLAG,
|
|
71
|
+
onPressLeadingIcon,
|
|
69
72
|
...props
|
|
70
73
|
}: InputPhoneNumberProps,
|
|
71
74
|
ref,
|
|
@@ -182,29 +185,16 @@ const InputPhoneNumber = forwardRef(
|
|
|
182
185
|
]}
|
|
183
186
|
>
|
|
184
187
|
<View style={styles.inputView}>
|
|
185
|
-
<
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
<Text typography={typography} color={textColor}>
|
|
196
|
-
{'+84'}
|
|
197
|
-
</Text>
|
|
198
|
-
<View
|
|
199
|
-
style={[
|
|
200
|
-
styles.phoneNumberDivider,
|
|
201
|
-
{
|
|
202
|
-
height: dividerHeight,
|
|
203
|
-
backgroundColor: Colors.black_04,
|
|
204
|
-
},
|
|
205
|
-
]}
|
|
206
|
-
/>
|
|
207
|
-
</View>
|
|
188
|
+
<CountryCodeView
|
|
189
|
+
countryCode={countryCode}
|
|
190
|
+
countryFlag={countryFlag}
|
|
191
|
+
typography={typography}
|
|
192
|
+
textColor={textColor}
|
|
193
|
+
dividerHeight={dividerHeight}
|
|
194
|
+
componentId={componentId}
|
|
195
|
+
isDisabled={disabled || !editable}
|
|
196
|
+
onPress={onPressLeadingIcon}
|
|
197
|
+
/>
|
|
208
198
|
<SystemTextInput
|
|
209
199
|
{...props}
|
|
210
200
|
accessibilityLabel={`${componentId}`}
|
|
@@ -302,12 +292,4 @@ const InputPhoneNumber = forwardRef(
|
|
|
302
292
|
},
|
|
303
293
|
);
|
|
304
294
|
|
|
305
|
-
const innerStyle = StyleSheet.create({
|
|
306
|
-
iconFlag: {
|
|
307
|
-
width: FLAG_SIZE,
|
|
308
|
-
height: FLAG_SIZE,
|
|
309
|
-
marginHorizontal: Spacing.XXS,
|
|
310
|
-
},
|
|
311
|
-
});
|
|
312
|
-
|
|
313
295
|
export default InputPhoneNumber;
|
package/Input/index.tsx
CHANGED
|
@@ -351,9 +351,23 @@ export interface InputDropDownProps extends TouchableOpacityProps {
|
|
|
351
351
|
|
|
352
352
|
export interface InputPhoneNumberProps extends InputProps {
|
|
353
353
|
/**
|
|
354
|
-
* Optional.
|
|
354
|
+
* Optional. Dial code shown verbatim before the number.
|
|
355
|
+
* Defaults to `+84` if not provided.
|
|
355
356
|
*/
|
|
356
357
|
countryCode?: string;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Optional. URL of the flag image shown before the dial code.
|
|
361
|
+
* Defaults to the Vietnam flag if not provided.
|
|
362
|
+
*/
|
|
363
|
+
countryFlag?: string;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Optional. Called when the flag or dial code is pressed (e.g. to pick a country),
|
|
367
|
+
* which then reads as a button with a chevron after the code. Ignored while
|
|
368
|
+
* `disabled` or `editable={false}`.
|
|
369
|
+
*/
|
|
370
|
+
onPressLeadingIcon?: () => void;
|
|
357
371
|
}
|
|
358
372
|
|
|
359
373
|
export type InputRef = {
|
|
@@ -64,8 +64,11 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
64
64
|
const labelFontFamily = exportFontFamily('bold');
|
|
65
65
|
const maxWidth = useSharedValue(0);
|
|
66
66
|
const minWidth = size === 'small' ? SMALL_SIZE : LARGE_SIZE;
|
|
67
|
+
const iconSize = size === 'small' ? SMALL_ICON_SIZE : LARGE_ICON_SIZE;
|
|
67
68
|
const opacityAnimated = useSharedValue(0);
|
|
68
69
|
const widthAnimated = useSharedValue<number | null>(null);
|
|
70
|
+
const paddingLeftAnimated = useSharedValue(Spacing.M);
|
|
71
|
+
const collapsedPaddingLeft = useSharedValue(Spacing.M);
|
|
69
72
|
const lastOffset = useSharedValue(0);
|
|
70
73
|
const lastDirection = useSharedValue<string | null>(null);
|
|
71
74
|
const [isLabelShown, setIsLabelShown] = useState(true);
|
|
@@ -89,6 +92,9 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
89
92
|
opacityAnimated.value = withTiming(0, {
|
|
90
93
|
duration: ANIMATION_DURATION,
|
|
91
94
|
});
|
|
95
|
+
paddingLeftAnimated.value = withTiming(collapsedPaddingLeft.value, {
|
|
96
|
+
duration: ANIMATION_DURATION,
|
|
97
|
+
});
|
|
92
98
|
widthAnimated.value = withTiming(
|
|
93
99
|
minWidth,
|
|
94
100
|
{ duration: ANIMATION_DURATION },
|
|
@@ -100,6 +106,9 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
100
106
|
opacityAnimated.value = withTiming(1, {
|
|
101
107
|
duration: ANIMATION_DURATION,
|
|
102
108
|
});
|
|
109
|
+
paddingLeftAnimated.value = withTiming(Spacing.M, {
|
|
110
|
+
duration: ANIMATION_DURATION,
|
|
111
|
+
});
|
|
103
112
|
widthAnimated.value = withTiming(
|
|
104
113
|
maxWidth.value,
|
|
105
114
|
{ duration: ANIMATION_DURATION },
|
|
@@ -116,6 +125,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
116
125
|
|
|
117
126
|
const containerStyle = useAnimatedStyle(() => ({
|
|
118
127
|
width: widthAnimated.value ?? undefined,
|
|
128
|
+
paddingLeft: paddingLeftAnimated.value,
|
|
119
129
|
}));
|
|
120
130
|
|
|
121
131
|
const labelStyle = useAnimatedStyle(() => ({
|
|
@@ -125,8 +135,14 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
125
135
|
const handleLayout = (event: LayoutChangeEvent) => {
|
|
126
136
|
const layout = event.nativeEvent.layout;
|
|
127
137
|
if (widthAnimated.value != null) return;
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
// layout is already scaled: rescale by height/minWidth so `width` isn't scaled twice
|
|
139
|
+
const expandedWidth = (layout.width * minWidth) / layout.height;
|
|
140
|
+
maxWidth.value = expandedWidth;
|
|
141
|
+
widthAnimated.value = expandedWidth;
|
|
142
|
+
// collapsed it is a circle as wide as it is tall: center the icon from the
|
|
143
|
+
// rendered height so it stays centered when sizes are scaled but padding is not
|
|
144
|
+
collapsedPaddingLeft.value =
|
|
145
|
+
(layout.height - (layout.height * iconSize) / minWidth) / 2;
|
|
130
146
|
};
|
|
131
147
|
|
|
132
148
|
if (renderComponent) {
|
|
@@ -158,11 +174,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
158
174
|
]}
|
|
159
175
|
>
|
|
160
176
|
<TouchableOpacity style={styles.content} onPress={onPress}>
|
|
161
|
-
<Icon
|
|
162
|
-
source={icon}
|
|
163
|
-
size={size === 'small' ? SMALL_ICON_SIZE : LARGE_ICON_SIZE}
|
|
164
|
-
color={iconColor}
|
|
165
|
-
/>
|
|
177
|
+
<Icon source={icon} size={iconSize} color={iconColor} />
|
|
166
178
|
{isLabelShown && !!label && (
|
|
167
179
|
<Animated.Text
|
|
168
180
|
allowFontScaling={false}
|
package/Layout/screenHeader.tsx
CHANGED
|
@@ -13,11 +13,8 @@ import {
|
|
|
13
13
|
SearchHeader,
|
|
14
14
|
} from '../Application';
|
|
15
15
|
import { DuoGlassBackground } from '../Application/Components/DuoGlassBackground';
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
type HeaderContentLayout,
|
|
19
|
-
TITLE_CONTAINER_RESET,
|
|
20
|
-
} from '../Application/headerLayout';
|
|
16
|
+
import { type HeaderContentLayout } from '../Application/headerLayout';
|
|
17
|
+
import { getHeaderMargin } from './utils';
|
|
21
18
|
import { useHeaderBarOptions } from './useHeaderBarOptions';
|
|
22
19
|
import { HeaderType } from './types';
|
|
23
20
|
|
|
@@ -245,11 +242,10 @@ export const useScreenHeader = ({
|
|
|
245
242
|
// the search field spans the content, clear of the side bar and status bar
|
|
246
243
|
// clusters; kept as numbers so the setter below stays stable
|
|
247
244
|
let searchWidth = layout.width - Spacing.M * 2;
|
|
248
|
-
|
|
249
|
-
const rowStartLeft = getHeaderRowInset(layout.width);
|
|
250
|
-
const searchLeft = layout.sideBar ? rowStartLeft : Spacing.M;
|
|
245
|
+
let searchLeft = Spacing.M;
|
|
251
246
|
if (layout.sideBar) {
|
|
252
247
|
searchWidth = layout.contentWidth - Spacing.M * 2;
|
|
248
|
+
searchLeft = Spacing.M - getHeaderMargin(layout.width);
|
|
253
249
|
}
|
|
254
250
|
const clearance = layout.statusBarClearance;
|
|
255
251
|
if (clearance) {
|
|
@@ -263,18 +259,25 @@ export const useScreenHeader = ({
|
|
|
263
259
|
const setSearchHeader = useCallback(
|
|
264
260
|
(params: SearchHeaderProps) => {
|
|
265
261
|
searchHeaderParams.current = params;
|
|
266
|
-
const hasBack = !params?.hiddenBack;
|
|
267
262
|
const options: StackNavigationOptions = {
|
|
268
263
|
...searchOptions,
|
|
269
264
|
headerRight: undefined,
|
|
270
265
|
headerTitleContainerStyle: {
|
|
271
|
-
...TITLE_CONTAINER_RESET,
|
|
272
266
|
width: searchWidth,
|
|
273
267
|
maxWidth: searchWidth,
|
|
274
|
-
|
|
268
|
+
marginLeft: 0,
|
|
269
|
+
marginEnd: 0,
|
|
270
|
+
marginStart: 0,
|
|
271
|
+
marginHorizontal: 0,
|
|
272
|
+
marginVertical: 0,
|
|
273
|
+
margin: 0,
|
|
274
|
+
left: searchLeft,
|
|
275
275
|
},
|
|
276
276
|
headerLeft: (props: any) => {
|
|
277
|
-
|
|
277
|
+
if (params?.hiddenBack) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
return <HeaderLeft {...props} floating />;
|
|
278
281
|
},
|
|
279
282
|
headerTitle: () => (
|
|
280
283
|
<SearchHeader {...params} animatedValue={sharedValue} />
|
|
@@ -283,14 +286,7 @@ export const useScreenHeader = ({
|
|
|
283
286
|
|
|
284
287
|
navigation?.instance?.setOptions(options);
|
|
285
288
|
},
|
|
286
|
-
[
|
|
287
|
-
navigation?.instance,
|
|
288
|
-
sharedValue,
|
|
289
|
-
searchOptions,
|
|
290
|
-
searchWidth,
|
|
291
|
-
searchLeft,
|
|
292
|
-
rowStartLeft,
|
|
293
|
-
],
|
|
289
|
+
[navigation?.instance, sharedValue, searchOptions, searchWidth, searchLeft],
|
|
294
290
|
);
|
|
295
291
|
|
|
296
292
|
useEffect(() => {
|