Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit 7e0ccc2

Browse files
chore: add example with react navigation 5
1 parent 222285e commit 7e0ccc2

File tree

13 files changed

+5885
-0
lines changed

13 files changed

+5885
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules
2+
example/node_modules/**/*
3+
example/.expo/*

example/.expo-shared/assets.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
3+
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
4+
}

example/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules/**/*
2+
.expo/*
3+
npm-debug.*
4+
*.jks
5+
*.p8
6+
*.p12
7+
*.key
8+
*.mobileprovision
9+
*.orig.*
10+
web-build/
11+
12+
# macOS
13+
.DS_Store

example/App.tsx

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import React, { useState } from 'react';
2+
import { View, Text, Platform, StyleSheet } from 'react-native';
3+
import { NavigationContainer, useNavigation, RouteProp } from '@react-navigation/native';
4+
import { createStackNavigator } from '@react-navigation/stack';
5+
import { RectButton, BorderlessButton } from 'react-native-gesture-handler';
6+
import SearchLayout from 'react-navigation-addon-search-layout';
7+
import { Ionicons } from '@expo/vector-icons';
8+
9+
type RootStackParamList = {
10+
Home: undefined;
11+
Search: undefined;
12+
Result: { text: string };
13+
};
14+
15+
type ResultScreenRouteProp = RouteProp<RootStackParamList, 'Result'>;
16+
17+
function HomeScreen() {
18+
return (
19+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
20+
<Text>Hello there!!!</Text>
21+
</View>
22+
);
23+
}
24+
25+
function SearchScreen () {
26+
27+
const [ searchText, setSearchText ] = useState('');
28+
const navigation = useNavigation();
29+
30+
const _handleQueryChange = ( searchText: string ) => {
31+
setSearchText(searchText);
32+
};
33+
34+
const _executeSearch = () => {
35+
alert('do search!');
36+
};
37+
38+
return (
39+
<SearchLayout
40+
onChangeQuery={_handleQueryChange}
41+
onSubmit={_executeSearch}>
42+
{searchText ? (
43+
<RectButton
44+
style={{
45+
borderBottomWidth: StyleSheet.hairlineWidth,
46+
borderBottomColor: '#eee',
47+
paddingVertical: 20,
48+
paddingHorizontal: 15,
49+
}}
50+
onPress={() =>
51+
navigation.navigate('Result', {
52+
text: searchText,
53+
})
54+
}>
55+
<Text style={{ fontSize: 14 }}>{searchText}!</Text>
56+
</RectButton>
57+
) : null}
58+
</SearchLayout>
59+
);
60+
}
61+
62+
function ResultScreen (props: ResultScreenRouteProp) {
63+
return (
64+
<View style={styles.container}>
65+
<Text>{props.params.text} result!</Text>
66+
</View>
67+
);
68+
}
69+
70+
const Stack = createStackNavigator();
71+
72+
export default function App() {
73+
return (
74+
<NavigationContainer>
75+
<Stack.Navigator>
76+
<Stack.Screen
77+
name="Home"
78+
component={HomeScreen}
79+
options={{
80+
headerRight: (props) => {
81+
const navigation = useNavigation();
82+
return (
83+
<BorderlessButton
84+
onPress={() => navigation.navigate('Search')}
85+
style={{ marginRight: 15 }}>
86+
<Ionicons
87+
name="md-search"
88+
size={Platform.OS === 'ios' ? 22 : 25}
89+
color={SearchLayout.DefaultTintColor}
90+
/>
91+
</BorderlessButton>
92+
)},
93+
}}
94+
/>
95+
<Stack.Screen
96+
name="Search"
97+
component={SearchScreen}
98+
options={{
99+
headerShown: false,
100+
gestureEnabled: false,
101+
animationEnabled:false
102+
}}
103+
/>
104+
105+
<Stack.Screen
106+
name="Result"
107+
component={ResultScreen}
108+
/>
109+
</Stack.Navigator>
110+
</NavigationContainer>
111+
);
112+
}
113+
114+
const styles = StyleSheet.create({
115+
container: {
116+
flex: 1,
117+
justifyContent: 'center',
118+
alignItems: 'center'
119+
}
120+
});

example/app.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"expo": {
3+
"name": "example",
4+
"slug": "example",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"splash": {
9+
"image": "./assets/splash.png",
10+
"resizeMode": "contain",
11+
"backgroundColor": "#ffffff"
12+
},
13+
"updates": {
14+
"fallbackToCacheTimeout": 0
15+
},
16+
"assetBundlePatterns": [
17+
"**/*"
18+
],
19+
"ios": {
20+
"supportsTablet": true
21+
},
22+
"android": {
23+
"adaptiveIcon": {
24+
"foregroundImage": "./assets/adaptive-icon.png",
25+
"backgroundColor": "#FFFFFF"
26+
}
27+
},
28+
"web": {
29+
"favicon": "./assets/favicon.png"
30+
}
31+
}
32+
}

example/assets/adaptive-icon.png

17.1 KB
Loading

example/assets/favicon.png

1.43 KB
Loading

example/assets/icon.png

21.9 KB
Loading

example/assets/splash.png

47.3 KB
Loading

example/babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
};
6+
};

0 commit comments

Comments
 (0)