-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
124 lines (110 loc) · 3.12 KB
/
index.ios.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
TextInput,
View,
NativeModules
} from 'react-native';
class zxtRn extends Component {
constructor(props) {
super(props);
this.state = {
TEXT: 'Input Text',//这里放你自己定义的state变量及初始值
tonative: 'test',
};
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions} onPress={() => { NativeModules.CalendarManager.addEvent('One', 'Two', 3); } } >
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<View style={{height: 40, }} />
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1,margin:20,}}
onChangeText={(text) => this.setState({TEXT:text})}
value={this.state.TEXT} />
<Text style={styles.button} onPress={() => { NativeModules.CalendarManager.addEvent('One', 'Two', 3); } } >
Call Swift Module
</Text>
<Text style={styles.button} onPress={() => { NativeModules.CalendarManager.pushView('Test', 'page2',"dddd"); } } >
pushView
</Text>
<Text style={styles.button} onPress={() => this.pushPage2() } >
push Page2 with callback
</Text>
<Text style={styles.button} onPress={() => this.updateEvents() } >
callback promise
</Text>
<Text style={styles.button} onPress={() => { NativeModules.CalendarManager.pushNative('Test', 'page2',{}); } } >
Enter Swift Page2
</Text>
</View>
);
}
pushPage2() {
NativeModules.CalendarManager.pushPage2('Test', 'page2', this.state.TEXT, (error, events) => {
if (error) {
console.log("111111111");
console.log(error);
} else {
console.log("2222222");
console.log(events);
this.setState({TEXT: events[0]});
}
});
}
//获取Promise对象处理
async updateEvents(){
try{
var events=await NativeModules.CalendarManager.RNInvokeOCPromise({'name':'jiangqq'});
console.log(events);
this.setState({TEXT: events});
}catch(e){
this.setState({TEXT: e.message});
console.log(e.message);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
button: {
textAlign: 'center',
color: 'teal',
fontSize: 24,
margin: 5,
padding: 5,
borderWidth:1, //安卓Text好像还不支持边框,需要View嵌套,坑
borderColor:'blue',
},
});
AppRegistry.registerComponent('zxtRn', () => zxtRn);