autobots-lib
Version:
汽车人基础库
81 lines (62 loc) • 1.3 kB
JavaScript
;
import React,{Component} from 'react';
import ReactNative from 'react-native';
const {
View,
Text,
Platform,
DeviceEventEmitter,
} = ReactNative;
class Me extends Component {
constructor (props) {
super(props);
}
componentWillMount() {
var that = this;
function cb_android(e:Event)
{
try
{
let received = JSON.parse(e.result);
if(received && received.needRefresh)
{
that.props.onNeedRefresh();
}
}catch(e)
{
console.log(e);
}
}
function cb_ios(p)
{
try
{
let received = JSON.parse(p);
if(received && received.needRefresh)
{
that.props.onNeedRefresh();
}
}catch(e)
{
console.log(e);
}
}
if(Platform.OS==='android')
{
this.sinListener = DeviceEventEmitter.addListener("event_custom_message_back",cb_android);
}else {
this.sinListener = DeviceEventEmitter.addListener("event_custom_message_back",cb_ios);
}
}
componentWillUnmount() {
if(this.sinListener!=null)
{
this.sinListener.remove();
this.sinListener = null;
}
}
render() {
return(<View/>);
}
}
module.exports = Me;