Skip to content

Commit 840dd3e

Browse files
committed
Fix issues with types in SearchBar.tsx
1 parent e26330e commit 840dd3e

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/components/SearchBar.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import {
44
SearchBarCommands,
55
SearchBarProps,
66
} from 'react-native-screens';
7-
import { View, NativeSyntheticEvent, TargetedEvent, TextInputFocusEventData } from 'react-native';
7+
import { View } from 'react-native';
88

99
// Native components
1010
import SearchBarNativeComponent, {
1111
Commands as SearchBarNativeCommands,
12-
SearchBarNativeProps,
12+
NativeProps as SearchBarNativeProps,
1313
SearchBarEvent,
1414
SearchButtonPressedEvent,
1515
ChangeTextEvent,
1616
} from '../fabric/SearchBarNativeComponent';
1717
import { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
1818

19-
export const NativeSearchBar: React.ComponentType<SearchBarNativeProps> &
19+
export const NativeSearchBar: React.ComponentType<
20+
SearchBarNativeProps & { ref?: React.RefObject<SearchBarCommands> }
21+
> &
2022
typeof NativeSearchBarCommands =
2123
SearchBarNativeComponent as unknown as React.ComponentType<SearchBarNativeProps> &
2224
SearchBarCommandsType;
@@ -83,17 +85,17 @@ function SearchBar(props: SearchBarProps, ref: React.Ref<SearchBarCommands>) {
8385

8486
return (
8587
<NativeSearchBar
88+
ref={searchBarRef}
89+
{...props}
8690
onSearchFocus={props.onFocus as DirectEventHandler<SearchBarEvent>}
8791
onSearchBlur={props.onBlur as DirectEventHandler<SearchBarEvent>}
8892
onSearchButtonPress={
89-
props.onSearchButtonPress as DirectEventHandler<TextInputFocusEventData>
93+
props.onSearchButtonPress as DirectEventHandler<SearchButtonPressedEvent>
9094
}
9195
onCancelButtonPress={
9296
props.onCancelButtonPress as DirectEventHandler<SearchBarEvent>
9397
}
9498
onChangeText={props.onChangeText as DirectEventHandler<ChangeTextEvent>}
95-
{...props}
96-
ref={searchBarRef}
9799
/>
98100
);
99101
}

src/fabric/SearchBarNativeComponent.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type SearchBarPlacement = 'automatic' | 'inline' | 'stacked';
2121

2222
type AutoCapitalizeType = 'none' | 'words' | 'sentences' | 'characters';
2323

24-
export interface SearchBarNativeProps extends ViewProps {
24+
export interface NativeProps extends ViewProps {
2525
onSearchFocus?: DirectEventHandler<SearchBarEvent> | null;
2626
onSearchBlur?: DirectEventHandler<SearchBarEvent> | null;
2727
onSearchButtonPress?: DirectEventHandler<SearchButtonPressedEvent> | null;
@@ -50,7 +50,7 @@ export interface SearchBarNativeProps extends ViewProps {
5050
shouldShowHintSearchIcon?: WithDefault<boolean, true>;
5151
}
5252

53-
type ComponentType = HostComponent<SearchBarNativeProps>;
53+
type ComponentType = HostComponent<NativeProps>;
5454

5555
interface SearchBarNativeCommands {
5656
blur: (viewRef: React.ElementRef<ComponentType>) => void;
@@ -76,4 +76,4 @@ export const Commands: SearchBarNativeCommands =
7676
],
7777
});
7878

79-
export default codegenNativeComponent<SearchBarNativeProps>('RNSSearchBar', {});
79+
export default codegenNativeComponent<NativeProps>('RNSSearchBar', {});

src/native-stack/views/HeaderConfig.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ScreenStackHeaderRightView,
1010
ScreenStackHeaderSearchBarView,
1111
SearchBar,
12+
SearchBarProps,
1213
isSearchBarAvailableForCurrentPlatform,
1314
executeNativeBackPress,
1415
} from 'react-native-screens';

0 commit comments

Comments
 (0)