@react-navigation/elements 2.0.3 → 2.1.0
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/lib/commonjs/Header/Header.js +9 -2
- package/lib/commonjs/Header/Header.js.map +1 -1
- package/lib/commonjs/Header/HeaderBackground.js +3 -1
- package/lib/commonjs/Header/HeaderBackground.js.map +1 -1
- package/lib/commonjs/Header/HeaderSearchBar.js +29 -11
- package/lib/commonjs/Header/HeaderSearchBar.js.map +1 -1
- package/lib/module/Header/Header.js +9 -2
- package/lib/module/Header/Header.js.map +1 -1
- package/lib/module/Header/HeaderBackground.js +3 -1
- package/lib/module/Header/HeaderBackground.js.map +1 -1
- package/lib/module/Header/HeaderSearchBar.js +28 -10
- package/lib/module/Header/HeaderSearchBar.js.map +1 -1
- package/lib/typescript/commonjs/src/Header/Header.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/Header/HeaderBackground.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/Header/HeaderSearchBar.d.ts +4 -5
- package/lib/typescript/commonjs/src/Header/HeaderSearchBar.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +27 -4
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/Header/Header.d.ts.map +1 -1
- package/lib/typescript/module/src/Header/HeaderBackground.d.ts.map +1 -1
- package/lib/typescript/module/src/Header/HeaderSearchBar.d.ts +4 -5
- package/lib/typescript/module/src/Header/HeaderSearchBar.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +27 -4
- package/lib/typescript/module/src/types.d.ts.map +1 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Header/Header.tsx +8 -1
- package/src/Header/HeaderBackground.tsx +5 -1
- package/src/Header/HeaderSearchBar.tsx +51 -28
- package/src/types.tsx +28 -3
|
@@ -17,11 +17,11 @@ import closeIcon from '../assets/close-icon.png';
|
|
|
17
17
|
import searchIcon from '../assets/search-icon.png';
|
|
18
18
|
import { PlatformPressable } from '../PlatformPressable';
|
|
19
19
|
import { Text } from '../Text';
|
|
20
|
-
import type {
|
|
20
|
+
import type { HeaderSearchBarOptions, HeaderSearchBarRef } from '../types';
|
|
21
21
|
import { HeaderButton } from './HeaderButton';
|
|
22
22
|
import { HeaderIcon } from './HeaderIcon';
|
|
23
23
|
|
|
24
|
-
type Props =
|
|
24
|
+
type Props = Omit<HeaderSearchBarOptions, 'ref'> & {
|
|
25
25
|
visible: boolean;
|
|
26
26
|
onClose: () => void;
|
|
27
27
|
style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
|
|
@@ -34,17 +34,20 @@ const INPUT_TYPE_TO_MODE = {
|
|
|
34
34
|
email: 'email',
|
|
35
35
|
} as const;
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
function HeaderSearchBarInternal(
|
|
38
|
+
{
|
|
39
|
+
visible,
|
|
40
|
+
inputType,
|
|
41
|
+
autoFocus = true,
|
|
42
|
+
placeholder = 'Search',
|
|
43
|
+
cancelButtonText = 'Cancel',
|
|
44
|
+
onChangeText,
|
|
45
|
+
onClose,
|
|
46
|
+
style,
|
|
47
|
+
...rest
|
|
48
|
+
}: Props,
|
|
49
|
+
ref: React.ForwardedRef<HeaderSearchBarRef>
|
|
50
|
+
) {
|
|
48
51
|
const navigation = useNavigation();
|
|
49
52
|
const { dark, colors, fonts } = useTheme();
|
|
50
53
|
const [value, setValue] = React.useState('');
|
|
@@ -98,22 +101,46 @@ export function HeaderSearchBar({
|
|
|
98
101
|
});
|
|
99
102
|
}, [clearVisibleAnim, hasText]);
|
|
100
103
|
|
|
101
|
-
const
|
|
104
|
+
const clearText = React.useCallback(() => {
|
|
102
105
|
inputRef.current?.clear();
|
|
103
106
|
inputRef.current?.focus();
|
|
104
107
|
setValue('');
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
const onClear = React.useCallback(() => {
|
|
111
|
+
clearText();
|
|
105
112
|
// FIXME: figure out how to create a SyntheticEvent
|
|
106
113
|
// @ts-expect-error: we don't have the native event here
|
|
107
114
|
onChangeText?.({ nativeEvent: { text: '' } });
|
|
108
|
-
}, [onChangeText]);
|
|
115
|
+
}, [clearText, onChangeText]);
|
|
116
|
+
|
|
117
|
+
const cancelSearch = React.useCallback(() => {
|
|
118
|
+
onClear();
|
|
119
|
+
onClose();
|
|
120
|
+
}, [onClear, onClose]);
|
|
109
121
|
|
|
110
122
|
React.useEffect(
|
|
111
|
-
() =>
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
() => navigation?.addListener('blur', cancelSearch),
|
|
124
|
+
[cancelSearch, navigation]
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
React.useImperativeHandle(
|
|
128
|
+
ref,
|
|
129
|
+
() => ({
|
|
130
|
+
focus: () => {
|
|
131
|
+
inputRef.current?.focus();
|
|
132
|
+
},
|
|
133
|
+
blur: () => {
|
|
134
|
+
inputRef.current?.blur();
|
|
135
|
+
},
|
|
136
|
+
setText: (text: string) => {
|
|
137
|
+
inputRef.current?.setNativeProps({ text });
|
|
138
|
+
setValue(text);
|
|
139
|
+
},
|
|
140
|
+
clearText,
|
|
141
|
+
cancelSearch,
|
|
142
|
+
}),
|
|
143
|
+
[cancelSearch, clearText]
|
|
117
144
|
);
|
|
118
145
|
|
|
119
146
|
if (!visible && !rendered) {
|
|
@@ -189,13 +216,7 @@ export function HeaderSearchBar({
|
|
|
189
216
|
</HeaderButton>
|
|
190
217
|
) : null}
|
|
191
218
|
{Platform.OS === 'ios' ? (
|
|
192
|
-
<PlatformPressable
|
|
193
|
-
onPress={() => {
|
|
194
|
-
onClear();
|
|
195
|
-
onClose();
|
|
196
|
-
}}
|
|
197
|
-
style={styles.cancelButton}
|
|
198
|
-
>
|
|
219
|
+
<PlatformPressable onPress={cancelSearch} style={styles.cancelButton}>
|
|
199
220
|
<Text
|
|
200
221
|
style={[
|
|
201
222
|
fonts.regular,
|
|
@@ -281,3 +302,5 @@ const styles = StyleSheet.create({
|
|
|
281
302
|
},
|
|
282
303
|
}),
|
|
283
304
|
});
|
|
305
|
+
|
|
306
|
+
export const HeaderSearchBar = React.forwardRef(HeaderSearchBarInternal);
|
package/src/types.tsx
CHANGED
|
@@ -11,7 +11,26 @@ export type HeaderBackButtonDisplayMode = 'default' | 'generic' | 'minimal';
|
|
|
11
11
|
|
|
12
12
|
export type Layout = { width: number; height: number };
|
|
13
13
|
|
|
14
|
-
type
|
|
14
|
+
export type HeaderSearchBarRef = {
|
|
15
|
+
focus: () => void;
|
|
16
|
+
blur: () => void;
|
|
17
|
+
setText: (text: string) => void;
|
|
18
|
+
clearText: () => void;
|
|
19
|
+
cancelSearch: () => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type HeaderSearchBarOptions = {
|
|
23
|
+
/**
|
|
24
|
+
* Ref to imperatively update the search bar.
|
|
25
|
+
*
|
|
26
|
+
* Supported operations:
|
|
27
|
+
* - `focus` - focuses the search bar
|
|
28
|
+
* - `blur` - removes focus from the search bar
|
|
29
|
+
* - `setText` - sets the search bar's content to given value
|
|
30
|
+
* - `clearText` - removes any text present in the search bar input field
|
|
31
|
+
* - `cancelSearch` - cancel the search and close the search bar
|
|
32
|
+
*/
|
|
33
|
+
ref?: React.Ref<HeaderSearchBarRef>;
|
|
15
34
|
/**
|
|
16
35
|
* The auto-capitalization behavior
|
|
17
36
|
*/
|
|
@@ -273,8 +292,14 @@ export type HeaderBackButtonProps = Omit<HeaderButtonProps, 'children'> & {
|
|
|
273
292
|
*/
|
|
274
293
|
truncatedLabel?: string;
|
|
275
294
|
/**
|
|
276
|
-
*
|
|
277
|
-
*
|
|
295
|
+
* How the back button displays icon and title.
|
|
296
|
+
*
|
|
297
|
+
* Supported values:
|
|
298
|
+
* - "default" - Displays one of the following depending on the available space: previous screen's title, truncated title (e.g. 'Back') or no title (only icon).
|
|
299
|
+
* - "generic" – Displays one of the following depending on the available space: truncated title (e.g. 'Back') or no title (only icon).
|
|
300
|
+
* - "minimal" – Always displays only the icon without a title.
|
|
301
|
+
*
|
|
302
|
+
* Defaults to "default" on iOS, and "minimal" on other platforms.
|
|
278
303
|
*/
|
|
279
304
|
displayMode?: HeaderBackButtonDisplayMode;
|
|
280
305
|
/**
|