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