UNPKG

autobots-lib

Version:

汽车人基础库

1 lines 2.77 kB
'use strict'; import React,{Component} from 'react'; import ReactNative from 'react-native'; import Native from '../native'; import Toast from './toast'; import {Buffer} from 'buffer'; import PropTypes from 'prop-types'; const { StyleSheet, requireNativeComponent, NativeModules, DeviceEventEmitter, Platform, View, Text, } = ReactNative; let openNative = function(data,callback) { let url = 'autobots://rn/wxshare?'+data; Native.callNative(url,function(result,data){ if(callback) { callback(result,data); } }); } class Me extends Component { //wxtype 1->微信,2->朋友圈 shareText(content,wxtype,callback){ let type_64 = new Buffer("text"); let content_64 = new Buffer(content); let wxtype_64 = new Buffer(wxtype); let data = "type="+type_64+"&content="+content_64+"&wxtype="+wxtype_64; openNative(data,callback); } shareUrl(title,url,pic,content,wxtype,callback) { let type_64 = new Buffer("url"); let title_64 = title && title!=""?new Buffer(title):""; let url_64 = url&&url!=""?new Buffer(url):""; let pic_64 = pic&&pic!=""?new Buffer(pic):""; let content_64 = content&&content!=""?new Buffer(content):""; let wxtype_64 = new Buffer(wxtype); let data = "type="+type_64+"&title="+title_64+"&url="+url_64+"&pic="+pic_64+"&content="+content_64+"&wxtype="+wxtype_64; openNative(data,callback); } sharePic(pic,wxtype,callback) { let type_64 = new Buffer("pic"); let pic_64 = new Buffer(pic); let wxtype_64 = new Buffer(wxtype); let data = "type="+type_64+"&pic="+pic_64+"&wxtype="+wxtype_64; openNative(data,callback); } componentWillMount() { var that = this; function cb_android(e:Event) { if(that.props.onCallBack) { that.props.onCallBack(JSON.parse(e.result)); } } function cb_ios(p) { if(that.props.onCallBack) { that.props.onCallBack(p); } } if(Platform.OS==='android') { this.sinListener = DeviceEventEmitter.addListener("react_event_wx_result",cb_android); }else { this.sinListener = DeviceEventEmitter.addListener("react_event_wx_result",cb_ios); } } componentWillUnmount() { if(this.sinListener!=null) { this.sinListener.remove(); this.sinListener = null; } } render() { return(<View/>); } } Me.propTypes= { onCallBack: PropTypes.func.isRequired, } module.exports = Me;