Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test test search bar types #2159

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import { View } from 'react-native';

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

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

return <NativeSearchBar {...props} ref={searchBarRef} />;
return (
<NativeSearchBar
{...props}
ref={searchBarRef}
onSearchButtonPress={
props.onSearchButtonPress as DirectEventHandler<SearchBarEvent>
}
onCancelButtonPress={
props.onCancelButtonPress as DirectEventHandler<SearchButtonPressedEvent>
}
onSearchBlur={props.onBlur as DirectEventHandler<SearchBarEvent>}
onSearchFocus={props.onFocus as DirectEventHandler<SearchBarEvent>}
onChangeText={props.onChangeText as DirectEventHandler<ChangeTextEvent>}
/>
);
}

export default React.forwardRef<SearchBarCommands, SearchBarProps>(SearchBar);
12 changes: 6 additions & 6 deletions src/fabric/SearchBarNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import type {
} from 'react-native/Libraries/Types/CodegenTypes';
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';

type SearchBarEvent = Readonly<{}>;
export type SearchBarEvent = Readonly<{}>;

type SearchButtonPressedEvent = Readonly<{
export type SearchButtonPressedEvent = Readonly<{
text?: string;
}>;

type ChangeTextEvent = Readonly<{
export type ChangeTextEvent = Readonly<{
text?: string;
}>;

type SearchBarPlacement = 'automatic' | 'inline' | 'stacked';

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

interface NativeProps extends ViewProps {
onFocus?: DirectEventHandler<SearchBarEvent> | null;
onBlur?: DirectEventHandler<SearchBarEvent> | null;
export interface NativeProps extends ViewProps {
onSearchFocus?: DirectEventHandler<SearchBarEvent> | null;
onSearchBlur?: DirectEventHandler<SearchBarEvent> | null;
onSearchButtonPress?: DirectEventHandler<SearchButtonPressedEvent> | null;
onCancelButtonPress?: DirectEventHandler<SearchBarEvent> | null;
onChangeText?: DirectEventHandler<ChangeTextEvent> | null;
Expand Down
Loading