autobots-lib
Version:
汽车人基础库
87 lines (68 loc) • 1.48 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(callback)
{
let url = 'autobots://testrn/CameraPicker';
Native.callNative(url,function(result,data){
if(callback)
{
callback(result,data);
}
});
}
class CameraPicker extends Component {
Pick(callback){
openNative(callback);
}
componentWillMount() {
var that = this;
function cb_android(e:Event)
{
if(that.props.onPicked)
{
that.props.onPicked(e.result);
}
}
function cb_ios(p)
{
if(that.props.onPicked)
{
that.props.onPicked(p);
}
}
if(Platform.OS==='android')
{
this.imglistener = DeviceEventEmitter.addListener('react_event_cameraPicker',cb_android);
}else {
this.imglistener = DeviceEventEmitter.addListener("react_event_cameraPicker",cb_ios);
}
}
componentWillUnmount() {
if(this.imglistener!=null)
{
this.imglistener.remove();
this.imglistener = null;
}
}
render() {
return(<View/>);
}
}
CameraPicker.propTypes= {
display: PropTypes.bool,
onPicked: PropTypes.func,
}
module.exports = CameraPicker;