ReactNative 常用组件

2016-08-26  本文已影响0人  Sollrei

react-native-swiper

github

Paste_Image.png

安装:

npm install react-native-image-picker@latest --save

ios注意:

添加 不要选错项目!

使用:

import {Platform} from 'react-native';
import ImagePicker from 'react-native-image-picker';

selectImage () {
    // 官网例子
    let options = {
        title: 'Select Avatar', 
        customButtons: {
             'Choose Photo from Facebook': 'fb',
        },
        storageOptions: {
            skipBackup: true,
            path: 'images'
        }
    };
    ImagePicker.showImagePicker(options, (response) => {
        console.log('Response = ', response);
        if (response.didCancel) {
            console.log('User cancelled image picker');
        }
        else if (response.error) {
            console.log('ImagePicker Error: ', response.error);
        } 
       else if (response.customButton) { 
           console.log('User tapped custom button: ',  response.customButton);
        }
        else {
            // You can display the image using either data...
            const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true}; 
           // or a reference to the platform specific asset location
            if (Platform.OS === 'ios') { 
               const source = {uri: response.uri.replace('file://', ''), isStatic: true};
            } else { 
               const source = {uri: response.uri, isStatic: true};
            }
            this.setState({
                avatarSource: source
            });
        } 
   });}


<TouchableOpacity
    onPress={this.selectImage.bind(this)}
>
    <Image
        style={styles.mAvatarImg}
        source={this.state.avatarSource}
    />
</TouchableOpacity>
上一篇下一篇

猜你喜欢

热点阅读