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 imperative API for search bar #1610

Merged
merged 47 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8d64467
Add API for imperative actions on RNSSearchBar
egegunes Jul 9, 2022
0585cda
chore: add search bar imp api test screen
kkafar Sep 26, 2022
503e419
chore: add Test1097 to TestsExample/App.js
kkafar Sep 26, 2022
458a6bb
chore: update node_modules in main lib directory
kkafar Sep 26, 2022
6efcefb
chore: reinstall dependencies in TE
kkafar Sep 26, 2022
e9840bf
chore: pod install in TE
kkafar Sep 27, 2022
f52ad1c
chore: reinstall library deps
kkafar Oct 3, 2022
36134b1
chore: add Test1097 to FTE
kkafar Oct 4, 2022
d18ddcf
chore: codegen native commands on Fabric
kkafar Oct 4, 2022
7605c91
chore: label #endif with comment
kkafar Oct 11, 2022
1cb1df0
chore: make RNSSearchBar implement RCTRNSSearchBarViewProtocol on Fabric
kkafar Oct 11, 2022
c9c9890
chore: add mock native code
kkafar Oct 11, 2022
9a9504f
chore: import Test1097 in FTE/App.js
kkafar Oct 11, 2022
afea4c8
TEMP!: change presented test number in FTE/App.js
kkafar Oct 11, 2022
341320d
Merge branch 'main' into @kkafar/ios-searchbar-imp-api
kkafar Feb 8, 2023
d75c05a
Reinstall library deps
kkafar Feb 8, 2023
c9bb17d
iOS native side for Fabric
kkafar Feb 9, 2023
770d836
Remove flow codegen spec for SearchBar
kkafar Feb 9, 2023
56128fe
Add native commands spec
kkafar Feb 9, 2023
d776605
First working JS impl
kkafar Feb 9, 2023
1a18d71
Remove some unused imports from index.native.tsx
kkafar Feb 13, 2023
bcf0323
Fix typing
kkafar Feb 13, 2023
19100d6
Linter
kkafar Feb 13, 2023
4a6001f
Implement Android code (first impl)
kkafar Feb 14, 2023
3c49f44
Cleanup Android implementation
kkafar Feb 14, 2023
582b6e3
Duplicate few buttons to workaround header bugs
kkafar Feb 14, 2023
e798497
Restore Test42 in FTE
kkafar Feb 14, 2023
6511706
Make typescript work
kkafar Feb 20, 2023
af621f8
Cleanup examples
kkafar Feb 20, 2023
0dee08a
Add comment in Android code
kkafar Feb 20, 2023
f19df4c
Refactor method names in Android implementation
kkafar Feb 20, 2023
7c284a8
Cleanup iOS implementation
kkafar Feb 20, 2023
268b53a
Update guide for library authors
kkafar Feb 20, 2023
7711fcc
Update native stack's readme
kkafar Feb 20, 2023
d65db1f
Remove unused code & console logs from JS
kkafar Feb 21, 2023
cd87356
Add docs for search bar ref in src/types.tsx
kkafar Feb 21, 2023
9aca379
Rename `flag` parameter in toggleCancelButton to `show`
kkafar Feb 21, 2023
24d8527
Modify TS types
kkafar Feb 21, 2023
cb39da0
Align examples on both architectures
kkafar Feb 21, 2023
0b98135
Improve native stack's readme
kkafar Feb 21, 2023
3ec1534
Fix bad import in Example
kkafar Feb 21, 2023
a519ff6
Cleanup in index.native.tsx
kkafar Feb 21, 2023
920a03f
Merge branch 'main' into @kkafar/ios-searchbar-imp-api
kkafar Feb 22, 2023
d68ed3f
Fix flag name to new one
kkafar Feb 24, 2023
752244b
Print warning message on null ref & refact impl
kkafar Feb 24, 2023
d5392f1
Fix TVOS
kkafar Feb 24, 2023
c7b19ec
Do not export module methods on Fabric
kkafar Feb 24, 2023
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
21 changes: 19 additions & 2 deletions Example/src/screens/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useLayoutEffect, useState } from 'react';
import React, { useLayoutEffect, useRef, useState } from 'react';
import { I18nManager, ScrollView, Text, StyleSheet } from 'react-native';
import { SearchBarProps } from 'react-native-screens';
import { SearchBarCommands, SearchBarProps } from 'react-native-screens';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
Expand Down Expand Up @@ -46,10 +46,12 @@ const MainScreen = ({ navigation }: MainScreenProps): JSX.Element => {
const [autoCapitalize, setAutoCapitalize] =
useState<AutoCapitalize>('sentences');
const [inputType, setInputType] = useState<InputType>('text');
const searchBarRef = useRef<SearchBarCommands>(null);

useLayoutEffect(() => {
navigation.setOptions({
searchBar: {
ref: searchBarRef,
barTintColor,
hintTextColor,
headerIconColor,
Expand Down Expand Up @@ -170,6 +172,21 @@ const MainScreen = ({ navigation }: MainScreenProps): JSX.Element => {
value={shouldShowHintSearchIcon}
onValueChange={setShouldShowHintSearchIcon}
/>
<Text style={styles.heading}>Imperative actions</Text>
<Button onPress={() => searchBarRef.current?.blur()} title="Blur" />
<Button onPress={() => searchBarRef.current?.focus()} title="Focus" />
<Button
onPress={() => searchBarRef.current?.clearText()}
title="Clear Text"
/>
<Button
onPress={() => searchBarRef.current?.toggleCancelButton(true)}
title="Show cancel"
/>
<Button
onPress={() => searchBarRef.current?.toggleCancelButton(false)}
title="Hide cancel"
/>
<Text style={styles.heading}>Other</Text>
<Button
onPress={() => navigation.navigate('Search')}
Expand Down
1 change: 1 addition & 0 deletions FabricTestExample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import Test1072 from './src/Test1072';
import Test1084 from './src/Test1084';
import Test1091 from './src/Test1091';
import Test1096 from './src/Test1096';
import Test1097 from './src/Test1097';
import Test1153 from './src/Test1153';
import Test1157 from './src/Test1157';
import Test1162 from './src/Test1162';
Expand Down
201 changes: 201 additions & 0 deletions FabricTestExample/src/Test1097.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import * as React from 'react';
import {Button, NativeSyntheticEvent, ScrollView} from 'react-native';
import {
NavigationContainer,
NavigationProp,
ParamListBase,
} from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackScreenProps,
} from 'react-native-screens/native-stack';
import {SearchBarProps, SearchBarCommands} from 'react-native-screens';

const AppStack = createNativeStackNavigator();

export default function App(): JSX.Element {
return (
<NavigationContainer>
<AppStack.Navigator
screenOptions={{
headerLargeTitle: true,
headerTranslucent: true,
}}>
<AppStack.Screen name="First" component={First} />
<AppStack.Screen name="Second" component={Second} />
<AppStack.Screen name="Third" component={Third} />
</AppStack.Navigator>
</NavigationContainer>
);
}

function First({navigation}: NativeStackScreenProps<ParamListBase>) {
const searchBarRef = React.useRef<SearchBarCommands>();

React.useEffect(() => {
navigation.setOptions({
searchBar: searchBarOptions,
});
}, [navigation]);

const [search, setSearch] = React.useState('');

const searchBarOptions: SearchBarProps = {
// @ts-ignore
ref: searchBarRef,
barTintColor: 'powderblue',
hideWhenScrolling: true,
obscureBackground: false,
hideNavigationBar: false,
autoCapitalize: 'sentences',
placeholder: 'Some text',
onChangeText: (e: NativeSyntheticEvent<{text: string}>) =>
setSearch(e.nativeEvent.text),
onCancelButtonPress: () => console.warn('Cancel button pressed'),
onSearchButtonPress: () => console.warn('Search button pressed'),
onFocus: () => console.warn('onFocus event'),
onBlur: () => console.warn('onBlur event'),
};

const items = [
'Apples',
'Pie',
'Juice',
'Cake',
'Nuggets',
'Some',
'Other',
'Stuff',
'To',
'Fill',
'The',
'Scrolling',
'Space',
];

return (
<ScrollView
contentInsetAdjustmentBehavior="automatic"
keyboardDismissMode="on-drag">
<Button
title="Tap me for second screen"
onPress={() => navigation.navigate('Second')}
/>
<Button
title="Tap me for third screen"
onPress={() => navigation.navigate('Third')}
/>
<Button
title="Tap me for ref"
onPress={() => searchBarRef.current?.focus()}
/>
{items
.filter(
(item) => item.toLowerCase().indexOf(search.toLowerCase()) !== -1,
)
.map((item) => (
<Button
title={item}
key={item}
onPress={() => {
console.warn(`${item} clicked`);
}}
/>
))}
<Button
title="Tap me for second screen"
onPress={() => navigation.navigate('Second')}
/>
<Button
title="Tap me for third screen"
onPress={() => navigation.navigate('Third')}
/>
<Button
title="Tap me for ref"
onPress={() => searchBarRef.current?.focus()}
/>
</ScrollView>
);
}

function Second({navigation}: {navigation: NavigationProp<ParamListBase>}) {
return (
<ScrollView contentInsetAdjustmentBehavior="automatic">
<Button
title="Tap me for first screen"
onPress={() => navigation.navigate('First')}
/>
<Button
title="Tap me for third screen"
onPress={() => navigation.navigate('Third')}
/>
</ScrollView>
);
}

function Third({navigation}: {navigation: NavigationProp<ParamListBase>}) {
const searchBarRef = React.useRef<SearchBarCommands>();

const searchBarProps: SearchBarProps = {
// @ts-ignore
ref: searchBarRef,
barTintColor: 'powderblue',
hideWhenScrolling: true,
obscureBackground: false,
hideNavigationBar: false,
autoCapitalize: 'sentences',
placeholder: 'Some text',
onChangeText: (e: NativeSyntheticEvent<{text: string}>) => console.warn(`Text changed to ${e.nativeEvent.text}`),
onCancelButtonPress: () => console.warn('Cancel button pressed'),
onSearchButtonPress: () => console.warn('Search button pressed'),
onFocus: () => console.warn('onFocus event'),
onBlur: () => console.warn('onBlur event'),
}

React.useEffect(() => {
navigation.setOptions({
searchBar: searchBarProps
})
}, [navigation]);


return (
<ScrollView
contentInsetAdjustmentBehavior="automatic"
keyboardDismissMode="on-drag">
<Button
title="Tap me for the first screen"
onPress={() => navigation.navigate('First')}
/>
<Button
title="Focus search bar"
onPress={() => searchBarRef.current?.focus()}
/>
<Button
title="Remove focus from search bar"
onPress={() => searchBarRef.current?.blur()}
/>
<Button
title="Clear text in search bar"
onPress={() => searchBarRef.current?.clearText()}
/>
<Button
title="Show cancel button"
onPress={() => searchBarRef.current?.toggleCancelButton(true)}
/>
<Button
title="Hide cancel button"
onPress={() => searchBarRef.current?.toggleCancelButton(false)}
/>
<Button
title="Tap me for the first screen"
onPress={() => navigation.navigate('First')}
/>
<Button
title="Focus search bar"
onPress={() => searchBarRef.current?.focus()}
/>
</ScrollView>
)
}
1 change: 1 addition & 0 deletions TestsExample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import Test1072 from './src/Test1072';
import Test1084 from './src/Test1084';
import Test1091 from './src/Test1091';
import Test1096 from './src/Test1096';
import Test1097 from './src/Test1097';
import Test1153 from './src/Test1153';
import Test1157 from './src/Test1157';
import Test1162 from './src/Test1162';
Expand Down
Loading