@momo-kits/foundation 0.169.16 → 0.169.17-beta.2
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/ModalIconButton.tsx +13 -15
- package/Application/modalLayout.ts +22 -2
- package/Input/InputPhoneNumber.tsx +38 -20
- package/Input/index.tsx +1 -14
- package/package.json +1 -1
- package/Input/CountryCodeView.tsx +0 -93
|
@@ -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
|
|
@@ -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
|
|
|
@@ -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;
|
|
@@ -53,6 +53,12 @@ export type ModalLayout = {
|
|
|
53
53
|
* `undefined` on phones, the sheet spans the window.
|
|
54
54
|
*/
|
|
55
55
|
width?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Window x of the sheet's left edge, `undefined` on phones. Centered on the
|
|
58
|
+
* window, but kept a margin clear of the iPhone Duo control column / system
|
|
59
|
+
* insets; half folded it is centered in the right half.
|
|
60
|
+
*/
|
|
61
|
+
x?: number;
|
|
56
62
|
maxHeight?: number;
|
|
57
63
|
minHeight?: number;
|
|
58
64
|
margin: number;
|
|
@@ -130,6 +136,19 @@ const getModalLayout = ({
|
|
|
130
136
|
const sheetSpace = placement.width - sheetMargin * 2;
|
|
131
137
|
const sheetMinWidth = Math.min(SHEET_MIN_WIDTH, sheetSpace);
|
|
132
138
|
const sheetMaxHeight = height - insets.top - Spacing.M;
|
|
139
|
+
const sheetWidth = clamp(sheetSpace, sheetMinWidth, SHEET_MAX_WIDTH);
|
|
140
|
+
// the window center, not the placement's, so an inset on one side (control column) does not push it off center
|
|
141
|
+
let sheetCenter = width / 2;
|
|
142
|
+
if (isHalfFolded) {
|
|
143
|
+
sheetCenter = placement.x + placement.width / 2;
|
|
144
|
+
}
|
|
145
|
+
const sheetX = Math.max(
|
|
146
|
+
placement.x + sheetMargin,
|
|
147
|
+
Math.min(
|
|
148
|
+
sheetCenter - sheetWidth / 2,
|
|
149
|
+
placement.x + placement.width - sheetMargin - sheetWidth,
|
|
150
|
+
),
|
|
151
|
+
);
|
|
133
152
|
|
|
134
153
|
return {
|
|
135
154
|
isFoldable,
|
|
@@ -143,7 +162,8 @@ const getModalLayout = ({
|
|
|
143
162
|
radius: Radius.XL,
|
|
144
163
|
},
|
|
145
164
|
sheet: {
|
|
146
|
-
width:
|
|
165
|
+
width: sheetWidth,
|
|
166
|
+
x: sheetX,
|
|
147
167
|
maxHeight: sheetMaxHeight,
|
|
148
168
|
minHeight: Math.min(SHEET_MIN_HEIGHT, sheetMaxHeight),
|
|
149
169
|
margin: sheetMargin,
|
|
@@ -6,6 +6,7 @@ import React, {
|
|
|
6
6
|
useState,
|
|
7
7
|
} from 'react';
|
|
8
8
|
import {
|
|
9
|
+
StyleSheet,
|
|
9
10
|
TextInput,
|
|
10
11
|
TextInputFocusEvent,
|
|
11
12
|
TouchableOpacity,
|
|
@@ -17,11 +18,12 @@ import {
|
|
|
17
18
|
ComponentContext,
|
|
18
19
|
MiniAppContext,
|
|
19
20
|
} from '../Context';
|
|
21
|
+
import { Colors, Spacing, Styles } from '../Consts';
|
|
20
22
|
import { Icon } from '../Icon';
|
|
21
|
-
import {
|
|
23
|
+
import { Image } from '../Image';
|
|
24
|
+
import { useScaleSize, Text, exportFontFamily } from '../Text';
|
|
22
25
|
import { Typography } from '../Text/types';
|
|
23
26
|
import { CLEAR_ICON_SIZE } from './constants';
|
|
24
|
-
import { CountryCodeView } from './CountryCodeView';
|
|
25
27
|
import { ErrorView } from './ErrorView';
|
|
26
28
|
import { InputPhoneNumberProps } from './index';
|
|
27
29
|
import { RenderTrailing } from './RenderTrailing';
|
|
@@ -34,13 +36,11 @@ const LARGE_FONT_SIZE = 18;
|
|
|
34
36
|
const SMALL_DIVIDER_HEIGHT = 24;
|
|
35
37
|
const LARGE_DIVIDER_HEIGHT = 32;
|
|
36
38
|
const FOCUSED_BORDER_WIDTH = 1.5;
|
|
37
|
-
const
|
|
38
|
-
const DEFAULT_COUNTRY_FLAG =
|
|
39
|
-
'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png';
|
|
39
|
+
const FLAG_SIZE = 24;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* Vietnamese phone number input with a fixed flag and `+84` prefix, number pad
|
|
43
|
+
* by default, plus clear and trailing icons.
|
|
44
44
|
*/
|
|
45
45
|
const InputPhoneNumber = forwardRef(
|
|
46
46
|
(
|
|
@@ -66,9 +66,6 @@ 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,
|
|
72
69
|
...props
|
|
73
70
|
}: InputPhoneNumberProps,
|
|
74
71
|
ref,
|
|
@@ -185,16 +182,29 @@ const InputPhoneNumber = forwardRef(
|
|
|
185
182
|
]}
|
|
186
183
|
>
|
|
187
184
|
<View style={styles.inputView}>
|
|
188
|
-
<
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
185
|
+
<View style={[styles.leadingIconContainer, Styles.row]}>
|
|
186
|
+
<Image
|
|
187
|
+
source={{
|
|
188
|
+
uri: 'https://static.momocdn.net/app/img/icon/ic-qrcode-package/ic_vn_flag.png',
|
|
189
|
+
}}
|
|
190
|
+
style={innerStyle.iconFlag}
|
|
191
|
+
resizeMode="contain"
|
|
192
|
+
accessibilityLabel={`${componentId}|leading-icon`}
|
|
193
|
+
/>
|
|
194
|
+
<View style={{ width: Spacing.XS }} />
|
|
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>
|
|
198
208
|
<SystemTextInput
|
|
199
209
|
{...props}
|
|
200
210
|
accessibilityLabel={`${componentId}`}
|
|
@@ -292,4 +302,12 @@ const InputPhoneNumber = forwardRef(
|
|
|
292
302
|
},
|
|
293
303
|
);
|
|
294
304
|
|
|
305
|
+
const innerStyle = StyleSheet.create({
|
|
306
|
+
iconFlag: {
|
|
307
|
+
width: FLAG_SIZE,
|
|
308
|
+
height: FLAG_SIZE,
|
|
309
|
+
marginHorizontal: Spacing.XXS,
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
|
|
295
313
|
export default InputPhoneNumber;
|
package/Input/index.tsx
CHANGED
|
@@ -351,22 +351,9 @@ export interface InputDropDownProps extends TouchableOpacityProps {
|
|
|
351
351
|
|
|
352
352
|
export interface InputPhoneNumberProps extends InputProps {
|
|
353
353
|
/**
|
|
354
|
-
* Optional.
|
|
355
|
-
* Defaults to `+84` if not provided.
|
|
354
|
+
* Optional. Currently unused: the displayed prefix is always `+84`.
|
|
356
355
|
*/
|
|
357
356
|
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. Ignored while `disabled` or `editable={false}`.
|
|
368
|
-
*/
|
|
369
|
-
onPressLeadingIcon?: () => void;
|
|
370
357
|
}
|
|
371
358
|
|
|
372
359
|
export type InputRef = {
|
package/package.json
CHANGED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
3
|
-
import { Colors, Spacing, Styles } from '../Consts';
|
|
4
|
-
import { Image } from '../Image';
|
|
5
|
-
import { Text } from '../Text';
|
|
6
|
-
import { Typography } from '../Text/types';
|
|
7
|
-
import styles from './styles';
|
|
8
|
-
|
|
9
|
-
const FLAG_SIZE = 24;
|
|
10
|
-
|
|
11
|
-
type CountryCodeViewProps = {
|
|
12
|
-
countryCode: string;
|
|
13
|
-
countryFlag: string;
|
|
14
|
-
typography: Typography;
|
|
15
|
-
textColor: string;
|
|
16
|
-
dividerHeight: number;
|
|
17
|
-
componentId: string;
|
|
18
|
-
isDisabled: boolean;
|
|
19
|
-
onPress?: () => void;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Flag, dial code and divider ahead of a phone number. Only becomes a button
|
|
24
|
-
* when `onPress` is given, so the default render stays a plain view.
|
|
25
|
-
*/
|
|
26
|
-
const CountryCodeView: React.FC<CountryCodeViewProps> = ({
|
|
27
|
-
countryCode,
|
|
28
|
-
countryFlag,
|
|
29
|
-
typography,
|
|
30
|
-
textColor,
|
|
31
|
-
dividerHeight,
|
|
32
|
-
componentId,
|
|
33
|
-
isDisabled,
|
|
34
|
-
onPress,
|
|
35
|
-
}) => {
|
|
36
|
-
const content = (
|
|
37
|
-
<>
|
|
38
|
-
<Image
|
|
39
|
-
source={{ uri: countryFlag }}
|
|
40
|
-
style={innerStyle.iconFlag}
|
|
41
|
-
resizeMode="contain"
|
|
42
|
-
accessibilityLabel={`${componentId}|leading-icon`}
|
|
43
|
-
/>
|
|
44
|
-
<View style={{ width: Spacing.XS }} />
|
|
45
|
-
<Text typography={typography} color={textColor}>
|
|
46
|
-
{countryCode}
|
|
47
|
-
</Text>
|
|
48
|
-
</>
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const renderContent = () => {
|
|
52
|
-
if (!onPress) {
|
|
53
|
-
return content;
|
|
54
|
-
}
|
|
55
|
-
return (
|
|
56
|
-
<TouchableOpacity
|
|
57
|
-
style={Styles.row}
|
|
58
|
-
onPress={onPress}
|
|
59
|
-
disabled={isDisabled}
|
|
60
|
-
accessibilityRole="button"
|
|
61
|
-
accessibilityLabel={`${componentId}|leading-icon-touch|${countryCode}`}
|
|
62
|
-
accessibilityState={{ disabled: isDisabled }}
|
|
63
|
-
>
|
|
64
|
-
{content}
|
|
65
|
-
</TouchableOpacity>
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<View style={[styles.leadingIconContainer, Styles.row]}>
|
|
71
|
-
{renderContent()}
|
|
72
|
-
<View
|
|
73
|
-
style={[
|
|
74
|
-
styles.phoneNumberDivider,
|
|
75
|
-
{
|
|
76
|
-
height: dividerHeight,
|
|
77
|
-
backgroundColor: Colors.black_04,
|
|
78
|
-
},
|
|
79
|
-
]}
|
|
80
|
-
/>
|
|
81
|
-
</View>
|
|
82
|
-
);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const innerStyle = StyleSheet.create({
|
|
86
|
-
iconFlag: {
|
|
87
|
-
width: FLAG_SIZE,
|
|
88
|
-
height: FLAG_SIZE,
|
|
89
|
-
marginHorizontal: Spacing.XXS,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
export { CountryCodeView };
|