forked from liaoxd/asLockApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
103 lines (97 loc) · 2.56 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
'use strict';
import React from 'react';
import Storage from 'react-native-storage';
import { AsyncStorage } from 'react-native';
import {
AppRegistry,
StyleSheet,
Text,
TextInput,
View,
TouchableHighlight,
DeviceEventEmitter,
NativeModules,
ToastAndroid
} from 'react-native';
class HelloWorld extends React.Component {
constructor(props) {
super(props);
this.state = {
oldPWD: '',
newPWD: ''
};
}
_onPressButton() {
console.log("You tapped the button!");
}
/**
*
*/
componentDidMout(){
DeviceEventEmitter.addListener('nativeCallRN',(msg) =>{
title = "React Native界面,接收到数据:"+global.patchImgNames;
ToastAndroid.show("发送成功",ToastAndroid.SHORT);
})
}
/**
* 调用原生代码
*/
skipNativeCall() {
let phone = '18380429225';
NativeModules.TransMissionModule.rnCallNative(phone);
}
/**
* Callback 通信方式
*/
callbackTrans(msg) {
NativeModules.TransMissionModule.rnCallNativeFromCallback(msg,(result) => {
ToastAndroid.show("CallBack收到消息:" + result, ToastAndroid.SHORT);
})
}
/**
* Promise 通信方式
*/
promiseTrans(msg) {
NativeModules.TransMissionModule.rnCallNativeFromPromise(msg).then(
(result) =>{
ToastAndroid.show("Promise收到消息:" + result, ToastAndroid.SHORT)
}
).catch((error) =>{console.log(error)});
}
render() {
return (
<View style={{padding: 10}}>
<TextInput
style={{height: 40}}
placeholder="Type old password!"
onChangeText={(oldPWD) => this.setState({oldPWD})}
/>
<TextInput
style={{height: 40}}
placeholder="Type new password!"
onChangeText={(newPWD) => this.setState({newPWD})}
/>
<TouchableHighlight onPress={this.skipNativeCall.bind(this)}>
<Text>确定</Text>
</TouchableHighlight>
</View>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
hello: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});
AppRegistry.registerComponent('HelloWorld', () => HelloWorld);