|
18 | 18 | - 例子 |
19 | 19 |
|
20 | 20 |
|
21 | | - import React, { Component } from 'react'; |
22 | | - import { |
23 | | - AppRegistry, |
24 | | - StyleSheet, |
25 | | - Text, |
26 | | - View, |
27 | | - Platform, |
28 | | - Button |
29 | | - } from 'react-native'; |
30 | | - |
31 | | - import {StackNavigator} from 'react-navigation'; |
32 | | - |
33 | | - class HomeScreen extends Component { |
34 | | - static navigationOptions={ |
35 | | - title:'Home' |
| 21 | + import React, { Component } from 'react'; |
| 22 | + import { |
| 23 | + AppRegistry, |
| 24 | + StyleSheet, |
| 25 | + Text, |
| 26 | + View, |
| 27 | + Platform, |
| 28 | + Button |
| 29 | + } from 'react-native'; |
| 30 | + |
| 31 | + import {StackNavigator} from 'react-navigation'; |
| 32 | + |
| 33 | + class HomeScreen extends Component { |
| 34 | + static navigationOptions={ |
| 35 | + title:'Home' |
| 36 | + } |
| 37 | + |
| 38 | + render() { |
| 39 | + const {navigate}=this.props.navigation; |
| 40 | + return ( |
| 41 | + <View> |
| 42 | + <Text>home</Text> |
| 43 | + <Button onPress={()=>navigate('Chat',{user:'lucy',password:'123'})} title='go to chat'></Button> |
| 44 | + </View> |
| 45 | + ); |
| 46 | + } |
36 | 47 | } |
37 | | - |
38 | | - render() { |
39 | | - const {navigate}=this.props.navigation; |
40 | | - return ( |
41 | | - <View> |
42 | | - <Text>home</Text> |
43 | | - <Button onPress={()=>navigate('Chat',{user:'lucy',password:'123'})} title='go to chat'></Button> |
44 | | - </View> |
45 | | - ); |
46 | | - } |
47 | | - } |
48 | | - |
49 | | - class ChatScreen extends Component{ |
50 | | - static navigationOptions=({navigation})=>{ |
51 | | - title:`Chat with ${navigation.state.params.user}` |
52 | | - }; |
53 | | - |
54 | | - render(){ |
55 | | - const {params}=this.props.navigation.state |
56 | | - return ( |
57 | | - <View> |
58 | | - <Text>chat with {params.user} ;password:{params.password}</Text> |
59 | | - </View> |
60 | | - ); |
| 48 | + |
| 49 | + class ChatScreen extends Component{ |
| 50 | + static navigationOptions=({navigation})=>{ |
| 51 | + title:`Chat with ${navigation.state.params.user}` |
| 52 | + }; |
| 53 | + |
| 54 | + render(){ |
| 55 | + const {params}=this.props.navigation.state |
| 56 | + return ( |
| 57 | + <View> |
| 58 | + <Text>chat with {params.user} ;password:{params.password}</Text> |
| 59 | + </View> |
| 60 | + ); |
| 61 | + } |
61 | 62 | } |
62 | | - } |
63 | | - |
64 | | - const styles = StyleSheet.create({ |
65 | | - container: { |
66 | | - flex: 1, |
67 | | - justifyContent: 'center', |
68 | | - alignItems: 'center', |
69 | | - backgroundColor: '#F5FCFF', |
70 | | - }, |
71 | | - |
72 | | - }); |
73 | | - |
74 | | - const SimpleApp=StackNavigator({ |
75 | | - Home:{screen:HomeScreen}, |
76 | | - Chat:{screen:ChatScreen} |
77 | | - }) |
78 | | - |
79 | | - AppRegistry.registerComponent('NavigationDemo', () => SimpleApp); |
| 63 | + |
| 64 | + const styles = StyleSheet.create({ |
| 65 | + container: { |
| 66 | + flex: 1, |
| 67 | + justifyContent: 'center', |
| 68 | + alignItems: 'center', |
| 69 | + backgroundColor: '#F5FCFF', |
| 70 | + }, |
| 71 | + |
| 72 | + }); |
| 73 | + |
| 74 | + const SimpleApp=StackNavigator({ |
| 75 | + Home:{screen:HomeScreen}, |
| 76 | + Chat:{screen:ChatScreen} |
| 77 | + }) |
| 78 | + |
| 79 | + AppRegistry.registerComponent('NavigationDemo', () => SimpleApp); |
80 | 80 |
|
0 commit comments