@aws-amplify/ui-react-native 2.5.3 → 2.6.1
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/dist/Authenticator/hooks/types.d.ts +1 -0
- package/dist/Authenticator/hooks/useFieldValues/useFieldValues.js +19 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/lib/Authenticator/hooks/useFieldValues/useFieldValues.js +18 -4
- package/lib/version.js +1 -1
- package/package.json +4 -4
- package/src/Authenticator/hooks/types.ts +1 -0
- package/src/Authenticator/hooks/useFieldValues/useFieldValues.ts +24 -5
- package/src/version.ts +1 -1
|
@@ -4,6 +4,7 @@ export type AuthenticatorFieldTypeKey = 'email' | 'password' | 'phone' | 'defaul
|
|
|
4
4
|
type RadioFieldOnBlur = RadioProps<string>['onBlur'];
|
|
5
5
|
export type TextFieldOnBlur = TextFieldProps['onBlur'];
|
|
6
6
|
export type OnChangeText = TextFieldProps['onChangeText'];
|
|
7
|
+
export type OnChange = TextFieldProps['onChange'];
|
|
7
8
|
type FieldOptions<FieldProps, Type extends AuthenticatorFieldTypeKey> = {
|
|
8
9
|
name: string;
|
|
9
10
|
onBlur?: Type extends 'radio' ? RadioFieldOnBlur : TextFieldOnBlur;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react';
|
|
1
|
+
import { useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { ConsoleLogger as Logger } from 'aws-amplify/utils';
|
|
3
3
|
import { getSanitizedTextFields, isRadioFieldOptions, runFieldValidation, getSanitizedVerifyUserFields, getSanitizedSelectMfaTypeFields, } from './utils';
|
|
4
4
|
const logger = new Logger('Authenticator');
|
|
5
5
|
export default function useFieldValues({ componentName, fields = [], handleBlur, handleChange, handleSubmit, validationErrors, }) {
|
|
6
6
|
const [touched, setTouched] = useState({});
|
|
7
|
+
const lastProcessed = useRef();
|
|
7
8
|
const [fieldValidationErrors, setFieldValidationErrors] = useState({});
|
|
8
9
|
const isVerifyUserRoute = componentName === 'VerifyUser';
|
|
9
10
|
const isSelectMfaTypeRoute = componentName === 'SelectMfaType';
|
|
@@ -78,9 +79,10 @@ export default function useFieldValues({ componentName, fields = [], handleBlur,
|
|
|
78
79
|
[name]: runFieldValidation(field, values[name], validationErrors),
|
|
79
80
|
});
|
|
80
81
|
};
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const reportChange = (value) => {
|
|
83
|
+
if (lastProcessed.current === `${name}:${value}`) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
84
86
|
// call machine change handler
|
|
85
87
|
handleChange({ name, value });
|
|
86
88
|
if (touched[name]) {
|
|
@@ -89,12 +91,24 @@ export default function useFieldValues({ componentName, fields = [], handleBlur,
|
|
|
89
91
|
[name]: runFieldValidation(field, value, validationErrors),
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
|
-
|
|
94
|
+
lastProcessed.current = `${name}:${value}`;
|
|
95
|
+
setValues((prev) => ({ ...prev, [name]: value }));
|
|
96
|
+
};
|
|
97
|
+
const onChangeText = (value) => {
|
|
98
|
+
// call `onChangeText` passed as text `field` option
|
|
99
|
+
field.onChangeText?.(value);
|
|
100
|
+
reportChange(value);
|
|
101
|
+
};
|
|
102
|
+
const onChange = (event) => {
|
|
103
|
+
// call `onChange` passed as text `field` option
|
|
104
|
+
field.onChange?.(event);
|
|
105
|
+
reportChange(event.nativeEvent.text ?? '');
|
|
93
106
|
};
|
|
94
107
|
return {
|
|
95
108
|
...rest,
|
|
96
109
|
label: labelHidden ? undefined : label,
|
|
97
110
|
onBlur,
|
|
111
|
+
onChange,
|
|
98
112
|
onChangeText,
|
|
99
113
|
name,
|
|
100
114
|
value: values[name],
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.
|
|
1
|
+
export declare const VERSION = "2.6.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '2.
|
|
1
|
+
export const VERSION = '2.6.1';
|
|
@@ -6,6 +6,7 @@ const utils_2 = require("./utils");
|
|
|
6
6
|
const logger = new utils_1.ConsoleLogger('Authenticator');
|
|
7
7
|
function useFieldValues({ componentName, fields = [], handleBlur, handleChange, handleSubmit, validationErrors, }) {
|
|
8
8
|
const [touched, setTouched] = (0, react_1.useState)({});
|
|
9
|
+
const lastProcessed = (0, react_1.useRef)();
|
|
9
10
|
const [fieldValidationErrors, setFieldValidationErrors] = (0, react_1.useState)({});
|
|
10
11
|
const isVerifyUserRoute = componentName === 'VerifyUser';
|
|
11
12
|
const isSelectMfaTypeRoute = componentName === 'SelectMfaType';
|
|
@@ -80,9 +81,10 @@ function useFieldValues({ componentName, fields = [], handleBlur, handleChange,
|
|
|
80
81
|
[name]: (0, utils_2.runFieldValidation)(field, values[name], validationErrors),
|
|
81
82
|
});
|
|
82
83
|
};
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
const reportChange = (value) => {
|
|
85
|
+
if (lastProcessed.current === `${name}:${value}`) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
86
88
|
// call machine change handler
|
|
87
89
|
handleChange({ name, value });
|
|
88
90
|
if (touched[name]) {
|
|
@@ -91,12 +93,24 @@ function useFieldValues({ componentName, fields = [], handleBlur, handleChange,
|
|
|
91
93
|
[name]: (0, utils_2.runFieldValidation)(field, value, validationErrors),
|
|
92
94
|
});
|
|
93
95
|
}
|
|
94
|
-
|
|
96
|
+
lastProcessed.current = `${name}:${value}`;
|
|
97
|
+
setValues((prev) => ({ ...prev, [name]: value }));
|
|
98
|
+
};
|
|
99
|
+
const onChangeText = (value) => {
|
|
100
|
+
// call `onChangeText` passed as text `field` option
|
|
101
|
+
field.onChangeText?.(value);
|
|
102
|
+
reportChange(value);
|
|
103
|
+
};
|
|
104
|
+
const onChange = (event) => {
|
|
105
|
+
// call `onChange` passed as text `field` option
|
|
106
|
+
field.onChange?.(event);
|
|
107
|
+
reportChange(event.nativeEvent.text ?? '');
|
|
95
108
|
};
|
|
96
109
|
return {
|
|
97
110
|
...rest,
|
|
98
111
|
label: labelHidden ? undefined : label,
|
|
99
112
|
onBlur,
|
|
113
|
+
onChange,
|
|
100
114
|
onChangeText,
|
|
101
115
|
name,
|
|
102
116
|
value: values[name],
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react-native",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"react-native-safe-area-context": "^5.2.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@aws-amplify/ui": "6.
|
|
34
|
-
"@aws-amplify/ui-react-core": "3.4.
|
|
35
|
-
"@aws-amplify/ui-react-core-notifications": "2.2.
|
|
33
|
+
"@aws-amplify/ui": "6.11.0",
|
|
34
|
+
"@aws-amplify/ui-react-core": "3.4.4",
|
|
35
|
+
"@aws-amplify/ui-react-core-notifications": "2.2.10"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"aws-amplify": "^6.14.3",
|
|
@@ -16,6 +16,7 @@ export type AuthenticatorFieldTypeKey =
|
|
|
16
16
|
type RadioFieldOnBlur = RadioProps<string>['onBlur'];
|
|
17
17
|
export type TextFieldOnBlur = TextFieldProps['onBlur'];
|
|
18
18
|
export type OnChangeText = TextFieldProps['onChangeText'];
|
|
19
|
+
export type OnChange = TextFieldProps['onChange'];
|
|
19
20
|
|
|
20
21
|
type FieldOptions<FieldProps, Type extends AuthenticatorFieldTypeKey> = {
|
|
21
22
|
name: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react';
|
|
1
|
+
import { useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { ConsoleLogger as Logger } from 'aws-amplify/utils';
|
|
3
3
|
import type { ValidationError } from '@aws-amplify/ui';
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
|
+
OnChange,
|
|
6
7
|
OnChangeText,
|
|
7
8
|
RadioFieldOptions,
|
|
8
9
|
TextFieldOnBlur,
|
|
@@ -29,6 +30,7 @@ export default function useFieldValues<FieldType extends TypedField>({
|
|
|
29
30
|
validationErrors,
|
|
30
31
|
}: UseFieldValuesParams<FieldType>): UseFieldValues<FieldType> {
|
|
31
32
|
const [touched, setTouched] = useState<Record<string, boolean>>({});
|
|
33
|
+
const lastProcessed = useRef<string>();
|
|
32
34
|
const [fieldValidationErrors, setFieldValidationErrors] =
|
|
33
35
|
useState<ValidationError>({});
|
|
34
36
|
const isVerifyUserRoute = componentName === 'VerifyUser';
|
|
@@ -124,9 +126,10 @@ export default function useFieldValues<FieldType extends TypedField>({
|
|
|
124
126
|
});
|
|
125
127
|
};
|
|
126
128
|
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
const reportChange = (value: string) => {
|
|
130
|
+
if (lastProcessed.current === `${name}:${value}`) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
130
133
|
|
|
131
134
|
// call machine change handler
|
|
132
135
|
handleChange({ name, value });
|
|
@@ -138,13 +141,29 @@ export default function useFieldValues<FieldType extends TypedField>({
|
|
|
138
141
|
});
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
|
|
144
|
+
lastProcessed.current = `${name}:${value}`;
|
|
145
|
+
setValues((prev) => ({ ...prev, [name]: value }));
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const onChangeText: OnChangeText = (value) => {
|
|
149
|
+
// call `onChangeText` passed as text `field` option
|
|
150
|
+
field.onChangeText?.(value);
|
|
151
|
+
|
|
152
|
+
reportChange(value);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const onChange: OnChange = (event) => {
|
|
156
|
+
// call `onChange` passed as text `field` option
|
|
157
|
+
field.onChange?.(event);
|
|
158
|
+
|
|
159
|
+
reportChange(event.nativeEvent.text ?? '');
|
|
142
160
|
};
|
|
143
161
|
|
|
144
162
|
return {
|
|
145
163
|
...rest,
|
|
146
164
|
label: labelHidden ? undefined : label,
|
|
147
165
|
onBlur,
|
|
166
|
+
onChange,
|
|
148
167
|
onChangeText,
|
|
149
168
|
name,
|
|
150
169
|
value: values[name],
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '2.
|
|
1
|
+
export const VERSION = '2.6.1';
|