@momo-kits/foundation 0.167.1-beta.3 → 0.167.1-beta.7
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/Components/HeaderTitle.tsx +16 -6
- package/Application/NavigationContainer.tsx +6 -1
- package/Application/WidgetContainer.tsx +9 -1
- package/Consts/designSystemFont.ts +12 -25
- package/Consts/theme.ts +2 -2
- package/Input/InputMoney.tsx +192 -50
- package/Text/index.tsx +6 -5
- package/package.json +1 -1
|
@@ -7,7 +7,13 @@ import Animated, {
|
|
|
7
7
|
} from 'react-native-reanimated';
|
|
8
8
|
import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
9
9
|
import { exportFontFamily, Text, useScaleSize } from '../../Text';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
Colors,
|
|
12
|
+
Radius,
|
|
13
|
+
Spacing,
|
|
14
|
+
Styles,
|
|
15
|
+
useHeaderFontFamily,
|
|
16
|
+
} from '../../Consts';
|
|
11
17
|
import {
|
|
12
18
|
TitleJourneyProps,
|
|
13
19
|
TitleLocationProps,
|
|
@@ -37,6 +43,7 @@ const HeaderTitle: React.FC<
|
|
|
37
43
|
HeaderTitleExtraProps & { [key: string]: any }
|
|
38
44
|
> = props => {
|
|
39
45
|
const context = useContext<any>(MiniAppContext);
|
|
46
|
+
const headerFontFamily = useHeaderFontFamily();
|
|
40
47
|
|
|
41
48
|
const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
|
|
42
49
|
|
|
@@ -85,7 +92,7 @@ const HeaderTitle: React.FC<
|
|
|
85
92
|
fontFamily: exportFontFamily(
|
|
86
93
|
'bold',
|
|
87
94
|
'action_xs_bold',
|
|
88
|
-
|
|
95
|
+
headerFontFamily,
|
|
89
96
|
),
|
|
90
97
|
color: props.tintColor,
|
|
91
98
|
},
|
|
@@ -130,6 +137,7 @@ const TitleUser: React.FC<TitleUserProps> = ({
|
|
|
130
137
|
isLoading,
|
|
131
138
|
}) => {
|
|
132
139
|
const { theme } = useContext(ApplicationContext);
|
|
140
|
+
const headerFontFamily = useHeaderFontFamily();
|
|
133
141
|
const maxWidth = Dimensions.get('window').width - 172;
|
|
134
142
|
const getShortName = (name: string) => {
|
|
135
143
|
const words = name.split(' ');
|
|
@@ -378,7 +386,7 @@ const TitleUser: React.FC<TitleUserProps> = ({
|
|
|
378
386
|
<View style={Styles.row}>
|
|
379
387
|
<Text
|
|
380
388
|
typography="action_xs_bold"
|
|
381
|
-
fontFamily=
|
|
389
|
+
fontFamily={headerFontFamily}
|
|
382
390
|
color={tintColor}
|
|
383
391
|
numberOfLines={1}
|
|
384
392
|
>
|
|
@@ -412,6 +420,7 @@ const TitleLocation: React.FC<TitleLocationProps> = ({
|
|
|
412
420
|
onPress,
|
|
413
421
|
isLoading,
|
|
414
422
|
}) => {
|
|
423
|
+
const headerFontFamily = useHeaderFontFamily();
|
|
415
424
|
const maxWidth = Dimensions.get('window').width - 172;
|
|
416
425
|
const renderShimmer = () => {
|
|
417
426
|
return (
|
|
@@ -449,7 +458,7 @@ const TitleLocation: React.FC<TitleLocationProps> = ({
|
|
|
449
458
|
)}
|
|
450
459
|
<View style={Styles.row}>
|
|
451
460
|
<Text typography="action_xs_bold"
|
|
452
|
-
fontFamily=
|
|
461
|
+
fontFamily={headerFontFamily}
|
|
453
462
|
color={tintColor} numberOfLines={1}>
|
|
454
463
|
{location}
|
|
455
464
|
</Text>
|
|
@@ -477,6 +486,7 @@ const TitleJourney: React.FC<TitleJourneyProps> = ({
|
|
|
477
486
|
onPress,
|
|
478
487
|
isLoading,
|
|
479
488
|
}) => {
|
|
489
|
+
const headerFontFamily = useHeaderFontFamily();
|
|
480
490
|
const { width } = Dimensions.get('screen');
|
|
481
491
|
const maxWidth = Dimensions.get('window').width - 172;
|
|
482
492
|
const startWidth = width * 0.25;
|
|
@@ -512,7 +522,7 @@ const TitleJourney: React.FC<TitleJourneyProps> = ({
|
|
|
512
522
|
style={{ maxWidth: startWidth }}
|
|
513
523
|
color={tintColor}
|
|
514
524
|
numberOfLines={1}
|
|
515
|
-
fontFamily=
|
|
525
|
+
fontFamily={headerFontFamily}
|
|
516
526
|
|
|
517
527
|
>
|
|
518
528
|
{start}
|
|
@@ -529,7 +539,7 @@ const TitleJourney: React.FC<TitleJourneyProps> = ({
|
|
|
529
539
|
typography="action_xs_bold"
|
|
530
540
|
color={tintColor}
|
|
531
541
|
numberOfLines={1}
|
|
532
|
-
fontFamily=
|
|
542
|
+
fontFamily={headerFontFamily}
|
|
533
543
|
|
|
534
544
|
>
|
|
535
545
|
{end}
|
|
@@ -20,7 +20,10 @@ import Navigator from './Navigator';
|
|
|
20
20
|
import { getModalOptions, getStackOptions, useNativeCanGoBack } from './utils';
|
|
21
21
|
import { NavigationContainerProps } from './types';
|
|
22
22
|
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
useDefaultRegularFontFamily,
|
|
25
|
+
useResolvedFontFamily,
|
|
26
|
+
} from '../Consts/designSystemFont';
|
|
24
27
|
import Localize from './Localize';
|
|
25
28
|
import { Colors, defaultTheme } from '../Consts';
|
|
26
29
|
import { HeaderLeft } from './Components/HeaderLeft';
|
|
@@ -104,6 +107,7 @@ const Navigation: React.FC<any> = ({
|
|
|
104
107
|
const [showGrid, setShowGrid] = useState(false);
|
|
105
108
|
const insets = useSafeAreaInsets();
|
|
106
109
|
const defaultRegularFontFamily = useDefaultRegularFontFamily();
|
|
110
|
+
const themeFont = useResolvedFontFamily(theme.font);
|
|
107
111
|
const syncCanGoBack = useNativeCanGoBack();
|
|
108
112
|
let headerBackground = context?.designSystemConfig?.config?.headerBar;
|
|
109
113
|
let headerGradient = theme.colors?.gradient;
|
|
@@ -156,6 +160,7 @@ const Navigation: React.FC<any> = ({
|
|
|
156
160
|
navigator: navigator.current,
|
|
157
161
|
theme: {
|
|
158
162
|
...theme,
|
|
163
|
+
font: themeFont,
|
|
159
164
|
colors: {
|
|
160
165
|
...theme.colors,
|
|
161
166
|
gradient: headerGradient,
|
|
@@ -3,7 +3,10 @@ import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
|
3
3
|
import Navigator from './Navigator';
|
|
4
4
|
import { WidgetContainerProps } from './types';
|
|
5
5
|
import { ApplicationContext, MiniAppContext } from '../Context';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
resolveFontFamily,
|
|
8
|
+
useDefaultRegularFontFamily,
|
|
9
|
+
} from '../Consts/designSystemFont';
|
|
7
10
|
import Localize from './Localize';
|
|
8
11
|
import { defaultTheme } from '../Consts';
|
|
9
12
|
import {
|
|
@@ -90,6 +93,11 @@ const WidgetContainer: React.FC<WidgetContainerProps> = ({
|
|
|
90
93
|
navigator: navigator.current,
|
|
91
94
|
theme: {
|
|
92
95
|
...theme,
|
|
96
|
+
font: resolveFontFamily(
|
|
97
|
+
theme.font,
|
|
98
|
+
mergedContext?.designSystemConfig?.isWhiteListDesignSystem ===
|
|
99
|
+
true,
|
|
100
|
+
),
|
|
93
101
|
colors: {
|
|
94
102
|
...theme.colors,
|
|
95
103
|
gradient: headerGradient,
|
|
@@ -3,36 +3,23 @@ import { MiniAppContext } from '../Context';
|
|
|
3
3
|
|
|
4
4
|
export const NEW_DEFAULT_FONT_FAMILY = 'MomoTrustSans';
|
|
5
5
|
export const LEGACY_DEFAULT_FONT_FAMILY = 'SFProText';
|
|
6
|
+
const HEADER_FONT_FAMILY = 'MoMoTrustDisplay';
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
* Font thuoc bo design system moi. Ngoai whitelist thi ha het ve font cu:
|
|
9
|
-
* MoMoTrustDisplay chi duoc dung tu commit header title 5bfde6251 (DS-791),
|
|
10
|
-
* truoc do header lay font theo theme.
|
|
11
|
-
*/
|
|
12
|
-
const NEW_FONT_FAMILIES = [NEW_DEFAULT_FONT_FAMILY, 'MoMoTrustDisplay'];
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Cờ whitelist design system, host đẩy xuống qua `decorateProps`
|
|
16
|
-
* (`designSystemConfig.isWhiteListDesignSystem`). Ngoài whitelist thì kit giữ
|
|
17
|
-
* nguyên font cũ.
|
|
18
|
-
*/
|
|
19
8
|
export const useIsDesignSystemWhiteList = (): boolean => {
|
|
20
9
|
const context = useContext<any>(MiniAppContext);
|
|
21
10
|
return context?.designSystemConfig?.isWhiteListDesignSystem === true;
|
|
22
11
|
};
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const isWhiteList = useIsDesignSystemWhiteList();
|
|
30
|
-
if (NEW_FONT_FAMILIES.includes(font) && !isWhiteList) {
|
|
31
|
-
return LEGACY_DEFAULT_FONT_FAMILY;
|
|
32
|
-
}
|
|
33
|
-
return font;
|
|
34
|
-
};
|
|
13
|
+
export const resolveFontFamily = (font: string, isWhiteList: boolean): string =>
|
|
14
|
+
isWhiteList ? NEW_DEFAULT_FONT_FAMILY : font;
|
|
15
|
+
|
|
16
|
+
export const useResolvedFontFamily = (font: string): string =>
|
|
17
|
+
resolveFontFamily(font, useIsDesignSystemWhiteList());
|
|
35
18
|
|
|
36
|
-
/** Tên file font Regular tương ứng với nhánh whitelist đang áp dụng. */
|
|
37
19
|
export const useDefaultRegularFontFamily = (): string =>
|
|
38
|
-
`${useResolvedFontFamily(
|
|
20
|
+
`${useResolvedFontFamily(LEGACY_DEFAULT_FONT_FAMILY)}-Regular`;
|
|
21
|
+
|
|
22
|
+
export const useHeaderFontFamily = (): string =>
|
|
23
|
+
useIsDesignSystemWhiteList()
|
|
24
|
+
? HEADER_FONT_FAMILY
|
|
25
|
+
: LEGACY_DEFAULT_FONT_FAMILY;
|
package/Consts/theme.ts
CHANGED
|
@@ -51,7 +51,7 @@ const defaultTheme: Theme = {
|
|
|
51
51
|
container: Colors.blue_08,
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
|
-
font: '
|
|
54
|
+
font: 'SFProText',
|
|
55
55
|
assets: {},
|
|
56
56
|
};
|
|
57
57
|
|
|
@@ -105,7 +105,7 @@ const defaultDarkTheme: Theme = {
|
|
|
105
105
|
container: Colors.blue_08,
|
|
106
106
|
},
|
|
107
107
|
},
|
|
108
|
-
font: '
|
|
108
|
+
font: 'SFProText',
|
|
109
109
|
assets: {},
|
|
110
110
|
};
|
|
111
111
|
|
package/Input/InputMoney.tsx
CHANGED
|
@@ -4,13 +4,16 @@ import React, {
|
|
|
4
4
|
useContext,
|
|
5
5
|
useEffect,
|
|
6
6
|
useImperativeHandle,
|
|
7
|
+
useLayoutEffect,
|
|
7
8
|
useRef,
|
|
8
9
|
useState,
|
|
9
10
|
} from 'react';
|
|
10
11
|
import {
|
|
11
12
|
NativeSyntheticEvent,
|
|
13
|
+
Platform,
|
|
12
14
|
TextInput,
|
|
13
15
|
TextInputFocusEventData,
|
|
16
|
+
TextInputSelectionChangeEventData,
|
|
14
17
|
TouchableOpacity,
|
|
15
18
|
View,
|
|
16
19
|
} from 'react-native';
|
|
@@ -32,9 +35,124 @@ import {
|
|
|
32
35
|
} from './common';
|
|
33
36
|
import { InputMoneyProps } from './index';
|
|
34
37
|
import styles from './styles';
|
|
35
|
-
import { formatNumberToMoney } from './utils';
|
|
36
38
|
import SystemTextInput from './SystemTextInput';
|
|
37
39
|
|
|
40
|
+
type Selection = { start: number; end: number };
|
|
41
|
+
type Edit = { start: number; end: number; inserted: string };
|
|
42
|
+
|
|
43
|
+
const countDigits = (text: string) => text.replace(/\D/g, '').length;
|
|
44
|
+
|
|
45
|
+
const groupDigits = (digits: string) =>
|
|
46
|
+
digits.replace(/\B(?=(\d{3})+(?!\d))/g, '.');
|
|
47
|
+
|
|
48
|
+
// Caret position right after the `digitIndex`-th digit of `display`.
|
|
49
|
+
const caretFromDigitIndex = (display: string, digitIndex: number) => {
|
|
50
|
+
let count = 0;
|
|
51
|
+
for (let i = 0; i < display.length && count < digitIndex; i++) {
|
|
52
|
+
if (/\d/.test(display[i])) {
|
|
53
|
+
count += 1;
|
|
54
|
+
if (count === digitIndex) return i + 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return 0;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Finds which range of `old` was replaced to produce `next`. `selection` is
|
|
61
|
+
// the pre-edit selection on iOS and already the post-edit caret on Android,
|
|
62
|
+
// where onSelectionChange fires before onChangeText.
|
|
63
|
+
const detectEdit = (old: string, next: string, selection: Selection): Edit => {
|
|
64
|
+
const { start, end } = selection;
|
|
65
|
+
const removed = old.length - next.length;
|
|
66
|
+
const preEdit: Edit[] = [
|
|
67
|
+
{
|
|
68
|
+
start,
|
|
69
|
+
end,
|
|
70
|
+
inserted: next.slice(start, next.length - (old.length - end)),
|
|
71
|
+
},
|
|
72
|
+
{ start: start - removed, end: start, inserted: '' },
|
|
73
|
+
{ start, end: start + removed, inserted: '' },
|
|
74
|
+
];
|
|
75
|
+
const postEdit: Edit[] = [];
|
|
76
|
+
const tail = next.length - start;
|
|
77
|
+
if (start === end && tail <= old.length) {
|
|
78
|
+
let prefix = 0;
|
|
79
|
+
while (
|
|
80
|
+
prefix < Math.min(start, old.length - tail) &&
|
|
81
|
+
old[prefix] === next[prefix]
|
|
82
|
+
) {
|
|
83
|
+
prefix += 1;
|
|
84
|
+
}
|
|
85
|
+
postEdit.push({
|
|
86
|
+
start: prefix,
|
|
87
|
+
end: old.length - tail,
|
|
88
|
+
inserted: next.slice(prefix, start),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const candidates =
|
|
92
|
+
Platform.OS === 'android'
|
|
93
|
+
? [...postEdit, ...preEdit]
|
|
94
|
+
: [...preEdit, ...postEdit];
|
|
95
|
+
const match = candidates.find(
|
|
96
|
+
e =>
|
|
97
|
+
e.start >= 0 &&
|
|
98
|
+
e.end >= e.start &&
|
|
99
|
+
e.end <= old.length &&
|
|
100
|
+
old.slice(0, e.start) + e.inserted + old.slice(e.end) === next,
|
|
101
|
+
);
|
|
102
|
+
if (match) return match;
|
|
103
|
+
|
|
104
|
+
let prefix = 0;
|
|
105
|
+
while (
|
|
106
|
+
prefix < Math.min(old.length, next.length) &&
|
|
107
|
+
old[prefix] === next[prefix]
|
|
108
|
+
) {
|
|
109
|
+
prefix += 1;
|
|
110
|
+
}
|
|
111
|
+
let suffix = 0;
|
|
112
|
+
while (
|
|
113
|
+
suffix < Math.min(old.length, next.length) - prefix &&
|
|
114
|
+
old[old.length - 1 - suffix] === next[next.length - 1 - suffix]
|
|
115
|
+
) {
|
|
116
|
+
suffix += 1;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
start: prefix,
|
|
120
|
+
end: old.length - suffix,
|
|
121
|
+
inserted: next.slice(prefix, next.length - suffix),
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Applies `edit` to the digits of `display`. Separators and currency are never
|
|
126
|
+
// deleted: removing a separator deletes the digit before it instead, removing
|
|
127
|
+
// only the currency leaves the digits untouched.
|
|
128
|
+
const applyEdit = (display: string, edit: Edit, digitLimit: number) => {
|
|
129
|
+
const digits = display.replace(/\D/g, '');
|
|
130
|
+
let left = countDigits(display.slice(0, edit.start));
|
|
131
|
+
let removed = countDigits(display.slice(edit.start, edit.end));
|
|
132
|
+
const inserted = edit.inserted.replace(/\D/g, '');
|
|
133
|
+
if (
|
|
134
|
+
!removed &&
|
|
135
|
+
!inserted &&
|
|
136
|
+
left > 0 &&
|
|
137
|
+
display.slice(edit.start, edit.end).includes('.')
|
|
138
|
+
) {
|
|
139
|
+
left -= 1;
|
|
140
|
+
removed = 1;
|
|
141
|
+
}
|
|
142
|
+
const next = digits.slice(0, left) + inserted + digits.slice(left + removed);
|
|
143
|
+
const trimmed = next.replace(/^0+(?=\d)/, '');
|
|
144
|
+
if ((!removed && !inserted) || trimmed.length > digitLimit) {
|
|
145
|
+
return { digits, caretDigit: left };
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
digits: trimmed,
|
|
149
|
+
caretDigit: Math.max(
|
|
150
|
+
0,
|
|
151
|
+
left + inserted.length - (next.length - trimmed.length),
|
|
152
|
+
),
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
38
156
|
const InputMoney = forwardRef(
|
|
39
157
|
(
|
|
40
158
|
{
|
|
@@ -73,7 +191,14 @@ const InputMoney = forwardRef(
|
|
|
73
191
|
const [focused, setFocused] = useState(false);
|
|
74
192
|
const [displayValue, setDisplayValue] = useState('');
|
|
75
193
|
const [numericValue, setNumericValue] = useState('');
|
|
76
|
-
const [
|
|
194
|
+
const [commitCount, setCommitCount] = useState(0);
|
|
195
|
+
const displayRef = useRef('');
|
|
196
|
+
const selectionRef = useRef<Selection>({ start: 0, end: 0 });
|
|
197
|
+
// Caret to push to native once the committed text is rendered.
|
|
198
|
+
const pendingCaretRef = useRef<number | null>(null);
|
|
199
|
+
// Caret the native input reports for the raw, unformatted text. On iOS that
|
|
200
|
+
// event lands after onChangeText and must not override the formatted caret.
|
|
201
|
+
const rawCaretRef = useRef<number | null>(null);
|
|
77
202
|
const inputRef = useRef<TextInput>(null);
|
|
78
203
|
const componentName = 'InputMoney';
|
|
79
204
|
|
|
@@ -91,25 +216,36 @@ const InputMoney = forwardRef(
|
|
|
91
216
|
|
|
92
217
|
useEffect(() => {
|
|
93
218
|
if (value !== undefined && typeof value === 'string') {
|
|
94
|
-
const cleanValue = value.replace(/\D/g, '');
|
|
219
|
+
const cleanValue = value.replace(/\D/g, '').replace(/^0+(?=\d)/, '');
|
|
95
220
|
if (cleanValue !== numericValue) {
|
|
96
|
-
|
|
97
|
-
updateDisplayValue(cleanValue);
|
|
221
|
+
commit(cleanValue, cleanValue.length);
|
|
98
222
|
}
|
|
99
223
|
}
|
|
100
224
|
}, [value]);
|
|
101
225
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
226
|
+
// Always set the caret imperatively: a controlled `selection` prop is only
|
|
227
|
+
// sent to native when it differs from the last native selection, so it is
|
|
228
|
+
// skipped whenever a stale selection event already reported the same value.
|
|
229
|
+
useLayoutEffect(() => {
|
|
230
|
+
const caret = pendingCaretRef.current;
|
|
231
|
+
if (caret === null) return;
|
|
232
|
+
pendingCaretRef.current = null;
|
|
233
|
+
if (inputRef.current?.isFocused()) {
|
|
234
|
+
inputRef.current.setSelection(caret, caret);
|
|
110
235
|
}
|
|
111
|
-
|
|
112
|
-
|
|
236
|
+
}, [commitCount]);
|
|
237
|
+
|
|
238
|
+
const commit = (digits: string, caretDigit: number) => {
|
|
239
|
+
const display = digits ? `${groupDigits(digits)}${currency}` : '';
|
|
240
|
+
const caret = caretFromDigitIndex(display, caretDigit);
|
|
241
|
+
const changed = digits !== numericValue;
|
|
242
|
+
displayRef.current = display;
|
|
243
|
+
selectionRef.current = { start: caret, end: caret };
|
|
244
|
+
pendingCaretRef.current = caret;
|
|
245
|
+
setCommitCount(count => count + 1);
|
|
246
|
+
setDisplayValue(display);
|
|
247
|
+
setNumericValue(digits);
|
|
248
|
+
return changed;
|
|
113
249
|
};
|
|
114
250
|
|
|
115
251
|
const parseInputText = (text: string): string => {
|
|
@@ -119,47 +255,49 @@ const InputMoney = forwardRef(
|
|
|
119
255
|
return textWithoutCurrency.replace(/[^\d]/g, '');
|
|
120
256
|
};
|
|
121
257
|
|
|
122
|
-
const updateNumericValue = (val: string) => {
|
|
123
|
-
let next = val.replace(/[^\d]/g, '');
|
|
124
|
-
if (next.length > digitLimit) next = next.slice(0, digitLimit);
|
|
125
|
-
if (/^\d*$/.test(next)) {
|
|
126
|
-
setNumericValue(next);
|
|
127
|
-
updateDisplayValue(next);
|
|
128
|
-
onChangeText?.(next);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
258
|
const onClearText = () => {
|
|
133
259
|
inputRef?.current?.clear();
|
|
134
260
|
inputRef.current?.setNativeProps({ text: '' });
|
|
135
|
-
|
|
136
|
-
setNumericValue('');
|
|
261
|
+
commit('', 0);
|
|
137
262
|
onChangeText?.('');
|
|
138
263
|
};
|
|
139
264
|
|
|
140
265
|
const _onChangeText = (text: string) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
266
|
+
let digits = '';
|
|
267
|
+
let caretDigit = 0;
|
|
268
|
+
rawCaretRef.current = 0;
|
|
269
|
+
if (text) {
|
|
270
|
+
const edit = detectEdit(displayRef.current, text, selectionRef.current);
|
|
271
|
+
rawCaretRef.current = edit.start + edit.inserted.length;
|
|
272
|
+
({ digits, caretDigit } = applyEdit(
|
|
273
|
+
displayRef.current,
|
|
274
|
+
edit,
|
|
275
|
+
digitLimit,
|
|
276
|
+
));
|
|
277
|
+
}
|
|
278
|
+
if (commit(digits, caretDigit)) {
|
|
279
|
+
onChangeText?.(digits);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// Keeps the caret out of the currency suffix.
|
|
284
|
+
const _onSelectionChange = (
|
|
285
|
+
e: NativeSyntheticEvent<TextInputSelectionChangeEventData>,
|
|
286
|
+
) => {
|
|
287
|
+
props.onSelectionChange?.(e);
|
|
288
|
+
const { start, end } = e.nativeEvent.selection;
|
|
289
|
+
const rawCaret = rawCaretRef.current;
|
|
290
|
+
rawCaretRef.current = null;
|
|
291
|
+
if (start === end && start === rawCaret) {
|
|
145
292
|
return;
|
|
146
293
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const currentNumericValue = numericValue;
|
|
154
|
-
if (currentNumericValue.length > 0) {
|
|
155
|
-
const newNumericValue = currentNumericValue.slice(0, -1);
|
|
156
|
-
updateNumericValue(newNumericValue);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
294
|
+
const display = displayRef.current;
|
|
295
|
+
const max = display ? display.length - currency.length : 0;
|
|
296
|
+
const clamped = { start: Math.min(start, max), end: Math.min(end, max) };
|
|
297
|
+
selectionRef.current = clamped;
|
|
298
|
+
if (clamped.start !== start || clamped.end !== end) {
|
|
299
|
+
inputRef.current?.setSelection(clamped.start, clamped.end);
|
|
160
300
|
}
|
|
161
|
-
const newNumericValue = parseInputText(text);
|
|
162
|
-
updateNumericValue(newNumericValue);
|
|
163
301
|
};
|
|
164
302
|
|
|
165
303
|
const _onFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
@@ -174,13 +312,16 @@ const InputMoney = forwardRef(
|
|
|
174
312
|
|
|
175
313
|
const _setText = (text: string) => {
|
|
176
314
|
if (!text) {
|
|
177
|
-
|
|
178
|
-
setNumericValue('');
|
|
315
|
+
commit('', 0);
|
|
179
316
|
onChangeText?.('');
|
|
180
317
|
return;
|
|
181
318
|
}
|
|
182
|
-
const
|
|
183
|
-
|
|
319
|
+
const digits = parseInputText(text)
|
|
320
|
+
.replace(/^0+(?=\d)/, '')
|
|
321
|
+
.slice(0, digitLimit);
|
|
322
|
+
if (commit(digits, digits.length)) {
|
|
323
|
+
onChangeText?.(digits);
|
|
324
|
+
}
|
|
184
325
|
};
|
|
185
326
|
|
|
186
327
|
useImperativeHandle(ref, () => {
|
|
@@ -247,6 +388,7 @@ const InputMoney = forwardRef(
|
|
|
247
388
|
textBreakStrategy="highQuality"
|
|
248
389
|
value={displayValue}
|
|
249
390
|
onChangeText={_onChangeText}
|
|
391
|
+
onSelectionChange={_onSelectionChange}
|
|
250
392
|
onFocus={_onFocus}
|
|
251
393
|
onBlur={_onBlur}
|
|
252
394
|
placeholder={placeholder}
|
package/Text/index.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
SkeletonContext,
|
|
9
9
|
} from '../Context';
|
|
10
10
|
import {
|
|
11
|
+
LEGACY_DEFAULT_FONT_FAMILY,
|
|
11
12
|
NEW_DEFAULT_FONT_FAMILY,
|
|
12
13
|
useResolvedFontFamily,
|
|
13
14
|
} from '../Consts/designSystemFont';
|
|
@@ -118,8 +119,11 @@ const TypoStyles = (typo: Typography, newFontFamily?: string) => {
|
|
|
118
119
|
const typoStyle = styleSheet[typo] ?? styleSheet.paragraph_default;
|
|
119
120
|
const { fontWeight, fontSize, fontStyle, lineHeight } = typoStyle;
|
|
120
121
|
const style = FontStyle[fontStyle ?? 'normal'];
|
|
121
|
-
const
|
|
122
|
-
const
|
|
122
|
+
const defaultFontFamily = useResolvedFontFamily(theme.font);
|
|
123
|
+
const font = newFontFamily ?? defaultFontFamily;
|
|
124
|
+
const resolvedDefaultFamily = useResolvedFontFamily(
|
|
125
|
+
LEGACY_DEFAULT_FONT_FAMILY,
|
|
126
|
+
);
|
|
123
127
|
let fontFamily: string;
|
|
124
128
|
|
|
125
129
|
switch (font) {
|
|
@@ -162,9 +166,6 @@ const TypoStyles = (typo: Typography, newFontFamily?: string) => {
|
|
|
162
166
|
fontSize: useScaleSize(fontSize),
|
|
163
167
|
lineHeight: useScaleSize(lineHeight),
|
|
164
168
|
fontStyle,
|
|
165
|
-
// fontFamily da mang san weight. Tren Android, ReactFontManager doi
|
|
166
|
-
// `fonts/<family>_bold.ttf` khi fontWeight >= 700; file do khong ton tai nen
|
|
167
|
-
// font se roi ve font he thong. Bo fontWeight de Android dung dung file.
|
|
168
169
|
fontWeight: undefined,
|
|
169
170
|
};
|
|
170
171
|
};
|