美文网首页
ReactNative 常用组件

ReactNative 常用组件

作者: Sollrei | 来源:发表于2016-08-26 10:38 被阅读0次

    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>
    

    相关文章

      网友评论

          本文标题:ReactNative 常用组件

          本文链接:https://www.haomeiwen.com/subject/uqzasttx.html