@momo-kits/foundation 0.169.19-beta.2 → 0.169.19-beta.3
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 +2 -1
- package/Application/Components/SearchHeader.tsx +2 -0
- package/Application/ModalIconButton.tsx +13 -15
- package/Application/ModalScreen.tsx +13 -4
- package/Application/modalLayout.ts +43 -3
- 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/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
|
|
@@ -69,7 +69,8 @@ const HeaderExtendHeader: React.FC<{
|
|
|
69
69
|
const headerBackground = customBackground ?? theme.assets?.headerBackground;
|
|
70
70
|
const layout = useScreenLayout();
|
|
71
71
|
const headerLayout = useHeaderLayout(contentLayout);
|
|
72
|
-
// collapsed into the bar, the search follows back and the right cluster into the
|
|
72
|
+
// collapsed into the bar, the search follows back and the right cluster into the
|
|
73
|
+
// frame; both already sit `sidePadding` from the edge on large iOS windows
|
|
73
74
|
const frameShift = headerLayout.frameInset - sidePadding;
|
|
74
75
|
|
|
75
76
|
const backLeft = buttonSize + sidePadding + titleGap;
|
|
@@ -46,6 +46,8 @@ const SearchHeader = React.forwardRef<InputRef, SearchHeaderProps>(
|
|
|
46
46
|
const headerRightWidth = props?.headerRightWidth ?? defaultRightWidth;
|
|
47
47
|
|
|
48
48
|
// iPhone Duo side bar holds back: the search shares the content width with the buttons only
|
|
49
|
+
// back ends at leftPosition and the measured right cluster counts from the window
|
|
50
|
+
// edge, so the large iOS header row margin is already netted out on both sides
|
|
49
51
|
const rowWidth = layout.width - leftPosition - sidePadding;
|
|
50
52
|
let searchMaxWidth = rowWidth - headerRightWidth;
|
|
51
53
|
if (layout.sideBar) {
|
|
@@ -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
|
},
|
|
@@ -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,
|
|
@@ -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 = {
|