實現拍照和獲取本地圖片功能
阿新 • • 發佈:2017-08-12
console flow dex eat struct xtend owa extends return
/* @flow */ import React, { Component } from ‘react‘; import { View, Text, StyleSheet, Button, Image, TouchableOpacity, Dimensions, TextInput, ToastAndroid, } from ‘react-native‘; const ImageUrl=‘http://192.168.127.1:8080‘; import ActionSheet from ‘react-native-actionsheet‘; const options = [ ‘取消‘, ‘本地圖庫‘, ‘拍照‘]; const title = ‘請選擇‘; export default class SetView extends Component { constructor(props) { super(props) this.state = { selected: ‘‘, image:‘‘, } this.handlePress = this.handlePress.bind(this) this.showActionSheet = this.showActionSheet.bind(this) } showActionSheet() { this.ActionSheet.show() } handlePress(i) { if(i == 1){ console.log(‘本地圖冊‘); Expo.ImagePicker.launchImageLibraryAsync() .then((info)=>{ this.setState({image:info.uri}); this.settingUserImage(); }) }else if(i == 2){ console.log(‘拍照‘); Expo.ImagePicker.launchCameraAsync() .then((info)=>{ this.setState({image:info.uri}); }) } } render() { return ( <View style={styles.container}> <ActionSheet ref={o => this.ActionSheet = o} title={title} options={options} cancelButtonIndex={0} destructiveButtonIndex={3} onPress={this.handlePress} /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, }, });
import ActionSheet from‘react-native-actionsheet‘;
實現拍照和獲取本地圖片功能