Skip to content

Commit

Permalink
Fix issues with types in SearchBar.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
tboba committed Jun 10, 2024
1 parent e26330e commit 840dd3e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import {
SearchBarCommands,
SearchBarProps,
} from 'react-native-screens';
import { View, NativeSyntheticEvent, TargetedEvent, TextInputFocusEventData } from 'react-native';
import { View } from 'react-native';

// Native components
import SearchBarNativeComponent, {
Commands as SearchBarNativeCommands,
SearchBarNativeProps,
NativeProps as SearchBarNativeProps,
SearchBarEvent,
SearchButtonPressedEvent,
ChangeTextEvent,
} from '../fabric/SearchBarNativeComponent';
import { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';

export const NativeSearchBar: React.ComponentType<SearchBarNativeProps> &
export const NativeSearchBar: React.ComponentType<
SearchBarNativeProps & { ref?: React.RefObject<SearchBarCommands> }
> &
typeof NativeSearchBarCommands =
SearchBarNativeComponent as unknown as React.ComponentType<SearchBarNativeProps> &
SearchBarCommandsType;
Expand Down Expand Up @@ -83,17 +85,17 @@ function SearchBar(props: SearchBarProps, ref: React.Ref<SearchBarCommands>) {

return (
<NativeSearchBar
ref={searchBarRef}
{...props}
onSearchFocus={props.onFocus as DirectEventHandler<SearchBarEvent>}
onSearchBlur={props.onBlur as DirectEventHandler<SearchBarEvent>}
onSearchButtonPress={
props.onSearchButtonPress as DirectEventHandler<TextInputFocusEventData>
props.onSearchButtonPress as DirectEventHandler<SearchButtonPressedEvent>
}
onCancelButtonPress={
props.onCancelButtonPress as DirectEventHandler<SearchBarEvent>
}
onChangeText={props.onChangeText as DirectEventHandler<ChangeTextEvent>}
{...props}
ref={searchBarRef}
/>
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/fabric/SearchBarNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type SearchBarPlacement = 'automatic' | 'inline' | 'stacked';

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

export interface SearchBarNativeProps extends ViewProps {
export interface NativeProps extends ViewProps {
onSearchFocus?: DirectEventHandler<SearchBarEvent> | null;
onSearchBlur?: DirectEventHandler<SearchBarEvent> | null;
onSearchButtonPress?: DirectEventHandler<SearchButtonPressedEvent> | null;
Expand Down Expand Up @@ -50,7 +50,7 @@ export interface SearchBarNativeProps extends ViewProps {
shouldShowHintSearchIcon?: WithDefault<boolean, true>;
}

type ComponentType = HostComponent<SearchBarNativeProps>;
type ComponentType = HostComponent<NativeProps>;

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

export default codegenNativeComponent<SearchBarNativeProps>('RNSSearchBar', {});
export default codegenNativeComponent<NativeProps>('RNSSearchBar', {});
1 change: 1 addition & 0 deletions src/native-stack/views/HeaderConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ScreenStackHeaderRightView,
ScreenStackHeaderSearchBarView,
SearchBar,
SearchBarProps,
isSearchBarAvailableForCurrentPlatform,
executeNativeBackPress,
} from 'react-native-screens';
Expand Down

0 comments on commit 840dd3e

Please sign in to comment.