docs: add example

This commit is contained in:
Jakub Grzywacz 2021-07-28 18:56:38 +02:00
parent bc68650c6a
commit 5060399165
No known key found for this signature in database
GPG Key ID: 5BBB685871FF63C4
3 changed files with 51 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import StaticModal from './StaticModal/StaticModal';
import Static from './Static/Static'; import Static from './Static/Static';
import TopCategory from './TopCategory/TopCategory'; import TopCategory from './TopCategory/TopCategory';
import BottomCategory from './BottomCategory/BottomCategory'; import BottomCategory from './BottomCategory/BottomCategory';
import SearchBar from './SearchBar/SearchBar';
const Stack = createStackNavigator(); const Stack = createStackNavigator();
export default () => { export default () => {
@ -29,6 +30,7 @@ export default () => {
<Stack.Screen name="Static" component={Static} /> <Stack.Screen name="Static" component={Static} />
<Stack.Screen name="TopCategory" component={TopCategory} /> <Stack.Screen name="TopCategory" component={TopCategory} />
<Stack.Screen name="BottomCategory" component={BottomCategory} /> <Stack.Screen name="BottomCategory" component={BottomCategory} />
<Stack.Screen name="SearchBar" component={SearchBar} />
</Stack.Navigator> </Stack.Navigator>
</NavigationContainer> </NavigationContainer>
); );

View File

@ -13,6 +13,7 @@ type RootStackParamList = {
Static: undefined; Static: undefined;
TopCategory: undefined; TopCategory: undefined;
BottomCategory: undefined; BottomCategory: undefined;
SearchBar: undefined;
}; };
type Props = StackScreenProps<RootStackParamList, 'Examples'>; type Props = StackScreenProps<RootStackParamList, 'Examples'>;
@ -47,6 +48,10 @@ const Examples = ({ navigation }: Props) => {
title="Category Bottom" title="Category Bottom"
onPress={() => navigation.navigate('BottomCategory')} onPress={() => navigation.navigate('BottomCategory')}
/> />
<Button
title="Search Bar"
onPress={() => navigation.navigate('SearchBar')}
/>
</View> </View>
</SafeAreaView> </SafeAreaView>
); );

View File

@ -0,0 +1,44 @@
import * as React from 'react';
import { StyleSheet, Text, TouchableOpacity } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import EmojiPicker from 'rn-emoji-keyboard';
import type { EmojiType } from 'src/types';
const SearchBar = () => {
const [result, setResult] = React.useState<string>();
const [isModalOpen, setIsModalOpen] = React.useState<boolean>(false);
const handlePick = (emoji: EmojiType) => {
console.log(emoji);
setResult(emoji.emoji);
setIsModalOpen((prev) => !prev);
};
return (
<SafeAreaView style={styles.container}>
<Text style={styles.text}>Result: {result}</Text>
<TouchableOpacity onPress={() => setIsModalOpen(true)}>
<Text style={styles.text}>Open</Text>
</TouchableOpacity>
<EmojiPicker
onEmojiSelected={handlePick}
open={isModalOpen}
onClose={() => setIsModalOpen(false)}
enableSearchBar
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
text: {
textAlign: 'center',
margin: 64,
fontSize: 18,
},
});
export default SearchBar;