autobots-lib
Version:
汽车人基础库
91 lines (67 loc) • 1.47 kB
JavaScript
;
import React,{Component} from 'react';
import ReactNative from 'react-native';
import Native from '../native';
import Toast from './toast';
import PropTypes from 'prop-types';
const {
StyleSheet,
requireNativeComponent,
NativeModules,
DeviceEventEmitter,
Platform,
View,
Text,
} = ReactNative;
let openNative = function(data,callback)
{
let url = 'autobots://rn/alipay?'+data;
Native.callNative(url,function(result,data){
if(callback)
{
callback(result,data);
}
});
}
class Me extends Component {
pay(data,callback){
openNative(data,callback);
}
componentWillMount() {
var that = this;
function cb_android(e:Event)
{
if(that.props.onPayBack)
{
that.props.onPayBack(JSON.parse(e.result));
}
}
function cb_ios(p)
{
if(that.props.onPayBack)
{
that.props.onPayBack(p);
}
}
if(Platform.OS==='android')
{
this.sinListener = DeviceEventEmitter.addListener("event_alipay_back",cb_android);
}else {
this.sinListener = DeviceEventEmitter.addListener("event_alipay_back",cb_ios);
}
}
componentWillUnmount() {
if(this.sinListener!=null)
{
this.sinListener.remove();
this.sinListener = null;
}
}
render() {
return(<View/>);
}
}
Me.propTypes= {
onPayBack: PropTypes.func.isRequired,
}
module.exports = Me;