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

feat: add cancel button text #1108

Merged
merged 1 commit into from
Sep 6, 2021
Merged
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
1 change: 1 addition & 0 deletions TestsExample/src/Test758.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function First({navigation}: NativeStackScreenProps<ParamListBase>) {
hideNavigationBar: false,
autoCapitalize: 'sentences',
placeholder: 'Some text',
cancelButtonText: 'Some text',
onChangeText: (e: NativeSyntheticEvent<{text: string}>) =>
setSearch(e.nativeEvent.text),
onCancelButtonPress: () => console.warn('Cancel button pressed'),
Expand Down
4 changes: 4 additions & 0 deletions createNativeStackNavigator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ The search field background color.

By default bar tint color is translucent.

#### `cancelButtonText`

The text to be used instead of default `Cancel` button text.

#### `hideNavigationBar`

Boolean indicating whether to hide the navigation bar during searching.
Expand Down
1 change: 1 addition & 0 deletions guides/GUIDE_FOR_LIBRARY_AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ To render a search bar use `ScreenStackHeaderSearchBarView` with `<SearchBar>` c

- `autoCapitalize` - Controls whether the text is automatically auto-capitalized as it is entered by the user. Can be one of these: `none`, `words`, `sentences`, `characters`. Defaults to `sentences`.
- `barTintColor` - The search field background color. By default bar tint color is translucent.
- `cancelButtonText` - The text to be used instead of default `Cancel` button text.
- `hideNavigationBar` - Boolean indicating whether to hide the navigation bar during searching. Defaults to `true`.
- `hideWhenScrolling` - Boolean indicating whether to hide the search bar when scrolling. Defaults to `true`.
- `obscureBackground` - Boolean indicating whether to obscure the underlying content with semi-transparent overlay. Defaults to `true`.
Expand Down
6 changes: 6 additions & 0 deletions ios/RNSSearchBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ - (void)setTextColor:(UIColor *)textColor
#endif
}

- (void)setCancelButtonText:(NSString *)text
{
[_controller.searchBar setValue:text forKey:@"cancelButtonText"];
}

- (void)hideCancelButton
{
#if !TARGET_OS_TV
Expand Down Expand Up @@ -182,6 +187,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(placeholder, NSString)
RCT_EXPORT_VIEW_PROPERTY(barTintColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(textColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(cancelButtonText, NSString)

RCT_EXPORT_VIEW_PROPERTY(onChangeText, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onCancelButtonPress, RCTBubblingEventBlock)
Expand Down
4 changes: 4 additions & 0 deletions native-stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ The search field background color.

By default bar tint color is translucent.

#### `cancelButtonText`

The text to be used instead of default `Cancel` button text.

#### `hideNavigationBar`

Boolean indicating whether to hide the navigation bar during searching.
Expand Down
40 changes: 24 additions & 16 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,18 @@ export interface ScreenStackHeaderConfigProps extends ViewProps {

export interface SearchBarProps {
/**
* Indicates whether to to obscure the underlying content
* The auto-capitalization behavior
*/
obscureBackground?: boolean;
autoCapitalize?: 'none' | 'words' | 'sentences' | 'characters';
/**
* The search field background color
*/
barTintColor?: string;
/**
* The text to be used instead of default `Cancel` button text
*/
cancelButtonText?: string;

/**
* Indicates whether to hide the navigation bar
*/
Expand All @@ -361,40 +370,39 @@ export interface SearchBarProps {
* Indicates whether to hide the search bar when scrolling
*/
hideWhenScrolling?: boolean;

/**
* The auto-capitalization behavior
* Indicates whether to to obscure the underlying content
*/
autoCapitalize?: 'none' | 'words' | 'sentences' | 'characters';
obscureBackground?: boolean;
/**
* Text displayed when search field is empty
* A callback that gets called when search bar has lost focus
*/
placeholder?: string;
onBlur?: (e: NativeSyntheticEvent<TargetedEvent>) => void;
/**
* The search field background color
* A callback that gets called when the cancel button is pressed
*/
barTintColor?: string;
onCancelButtonPress?: (e: NativeSyntheticEvent<TargetedEvent>) => void;

/**
* A callback that gets called when the text changes. It receives the current text value of the search bar.
*/
onChangeText?: (e: NativeSyntheticEvent<TextInputFocusEventData>) => void;

/**
* A callback that gets called when the cancel button is pressed
* A callback that gets called when search bar has received focus
*/
onCancelButtonPress?: (e: NativeSyntheticEvent<TargetedEvent>) => void;
onFocus?: (e: NativeSyntheticEvent<TargetedEvent>) => void;
/**
* A callback that gets called when the search button is pressed. It receives the current text value of the search bar.
*/
onSearchButtonPress?: (
e: NativeSyntheticEvent<TextInputFocusEventData>
) => void;
/**
* A callback that gets called when search bar has received focus
*/
onFocus?: (e: NativeSyntheticEvent<TargetedEvent>) => void;
/**
* A callback that gets called when search bar has lost focus
* Text displayed when search field is empty
*/
onBlur?: (e: NativeSyntheticEvent<TargetedEvent>) => void;
placeholder?: string;
/**
* The search field text color
*/
Expand Down