123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /**
- * Sample React Native App
- * https://github.com/facebook/react-native
- *
- * @format
- * @flow
- */
- import React, {Component} from 'react';
- import {Platform, StyleSheet, Text, View ,Image} from 'react-native';
- import ImagePicker from 'react-native-image-crop-picker';
- const instructions = Platform.select({
- ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
- android:
- 'Double tap R on your keyboard to reload,\n' +
- 'Shake or press menu Text for dev menu',
- });
- export default class App extends Component{
- constructor(props){
- super(props)
- this.state={
- list:[{}]
- }
- }
- componentWillMount(){
-
- }
- render() {
- const {list} = this.state
- return (
- <View style={styles.container}>
- <Text
- style={styles.margin}
- onPress={()=>{
- ImagePicker.openPicker({
- width: 300,
- height: 400,
- cropping: true,
- cropperChooseText:'确认',
- cropperCancelText:"取消",
- loadingLabelText:'请等待...'
- }).then(image => {
- list.push(image)
- this.setState({
- list
- })
- console.log(image);
- });
-
- }}>
- 点击
- </Text>
- <Text
- style={styles.margin}
- onPress={()=>{
- ImagePicker.openPicker({
- multiple: true,
- cropping:true,
- cropperChooseText:'确认',
- cropperCancelText:"取消",
- loadingLabelText:'请等待...'
- }).then(images => {
- list.push(images)
- this.setState({
- list
- })
- console.log(images);
- });
- }}>
- 点击
- </Text>
-
- <Text
- style={styles.margin}
- onPress={()=>{
- ImagePicker.openCamera({
- width: 300,
- height: 400,
- cropping: true,
- cropperChooseText:'确认',
- cropperCancelText:"取消",
- loadingLabelText:'请等待...'
- }).then(image => {
- list.push(image)
- this.setState({
- list
- })
- console.log(image);
- });
- }}>
- 点击
- </Text>
- <View style={{backgroundColor:'#333',width:375,height:400}}>
- {
- list.map((item,index)=>{
- console.log(item.path)
- let source = { uri: item.path };
- return (
- <Image
- style={{width:100,height:100}}
- key={index} source={source}></Image>
- )
- })
- }
- </View>
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- margin:{
- marginBottom:20
- },
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: '#F5FCFF',
- },
- welcome: {
- fontSize: 20,
- textAlign: 'center',
- margin: 10,
- },
- instructions: {
- textAlign: 'center',
- color: '#333333',
- marginBottom: 5,
- },
- });
|