-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.js
203 lines (173 loc) · 5.24 KB
/
index.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
* Sample React Native App
* require("./img/ic_launcher.png")
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
//navigation 1.
import { StackNavigator, TabNavigator } from 'react-navigation';
import {
Alert,
ScrollView,
AppRegistry,
Platform,
Text,
View,
TextInput,
Button,
TouchableHighlight,
TouchableNativeFeedback,
TouchableOpacity,
TouchableWithoutFeedback,
FlatList,
SectionList,
Image
} from 'react-native';
import { indexStyle } from './styles/index.js';
export default class MyProject extends Component {
//navigation 3.
static navigationOptions = {
title: 'navigator',
};
constructor(props) {
super(props);
this.state = {text: ''};
}
_onPressButton() {
Alert.alert('You tapped the button!')
}
_onLongPressButton() {
Alert.alert('You long-pressed the button!')
}
render() {
//navigation 4.
// const { navigate } = this.props.navigation.navigate;
return (
<ScrollView>
<Image
source={require("./img/ic_launcher.png")}
style={{width: 40, height: 40}}
/>
<Image
source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
style={{width: 40, height: 40}}
/>
<View>
<Text>Hello, Chat App!</Text>
<Button
onPress={() => this.props.navigation.navigate('Chat')}
title="Chat with Lucy"
/>
</View>
<View style={indexStyle.container}>
<Text style={indexStyle.welcome}>
Welcome to React Native!!!!
</Text>
<TextInput
style={indexStyle.myInput}
placeholder="请输入姓名"
onChangeText={(text) => {this.setState({text})}}
/>
<Text>{this.state.text}</Text>
<Button onPress={()=>{alert('check me')}} title="check me" />
<TouchableHighlight onPress={this._onPressButton} underlayColor="white">
<View style={indexStyle.button}>
<Text style={indexStyle.buttonText}>TouchableHighlight</Text>
</View>
</TouchableHighlight>
<TouchableOpacity onPress={this._onPressButton}>
<View style={indexStyle.button}>
<Text style={indexStyle.buttonText}>TouchableOpacity</Text>
</View>
</TouchableOpacity>
<TouchableNativeFeedback
onPress={this._onPressButton}
background={Platform.OS === 'android' ? TouchableNativeFeedback.SelectableBackground() : ''}>
<View style={indexStyle.button}>
<Text style={indexStyle.buttonText}>TouchableNativeFeedback</Text>
</View>
</TouchableNativeFeedback>
<TouchableWithoutFeedback
onPress={this._onPressButton}
>
<View style={indexStyle.button}>
<Text style={indexStyle.buttonText}>TouchableWithoutFeedback</Text>
</View>
</TouchableWithoutFeedback>
<TouchableHighlight onPress={this._onPressButton} onLongPress={this._onLongPressButton} underlayColor="white">
<View style={indexStyle.button}>
<Text style={indexStyle.buttonText}>Touchable with Long Press</Text>
</View>
</TouchableHighlight>
<FlatList
data = {[
{key: 'Devin'},
{key: 'Jackson'},
{key: 'James'},
{key: 'Joel'},
{key: 'John'},
{key: 'Jillian'},
{key: 'Jimmy'},
{key: 'Julie'},
]}
renderItem = {({item}) => <Text>{item.key}</Text>}
/>
<SectionList
sections={[
{
title:"A",
data:['阿拉善', "屋换"]
},
{
title:"C",
data:["成都"]
}
]}
renderSectionHeader={({section}) => <Text>{section.title}</Text>}
renderItem={({item}) => <Text>SectionList:{item}</Text>}
/>
</View>
</ScrollView>
);
}
}
class ChatScreen extends Component {
static navigationOptions = {
title: 'Chat',
};
render() {
return (
<View>
<Button
onPress={() => this.props.navigation.navigate('Home')}
title="Home"
/>
<Text>Chat with</Text>
</View>
);
}
}
//navigation 2.
const App = StackNavigator({
Home: {screen: MyProject},
Chat: {screen: ChatScreen},
},
{
initialRouteName: 'Chat'
});
class RecentChatsScreen extends React.Component {
render() {
return <Text>List of recent chats</Text>
}
}
class AllContactsScreen extends React.Component {
render() {
return <Text>List of all contacts</Text>
}
}
const MainScreenNavigator = TabNavigator({
Recent: { screen: RecentChatsScreen },
All: { screen: AllContactsScreen },
});
AppRegistry.registerComponent('MyProject', () => App);