Example

示例

import React from 'react';
import {Button, ScrollView,Image,View} from 'react-native';

import CameraRoll from '@react-native-community/cameraroll'


export default class App extends React.Component {
    constructor(){
        super();
        this.state= {
            photos: []
        }

    }
    _handleButtonPress = () => {
        CameraRoll.getPhotos({
            first: 20,
            assetType: 'Photos',
        })
            .then(r => {
                this.setState({photos: r.edges});
            })
            .catch((err) => {
                //Error Loading Images
            });
    };

    render() {
        return (
            <View style={{marginTop:100}}>
                <Button title="Load Images" onPress={this._handleButtonPress}/>
                <ScrollView>
                    {this.state.photos.map((p, i) => {
                        return (
                            <Image
                                key={i}
                                style={{
                                    width: 300,
                                    height: 100,
                                }}
                                source={{uri: p.node.image.uri}}
                            />
                        );
                    })}
                </ScrollView>
            </View>
        );
    }
}
该文件修订时间: 2021-01-14 15:02:10

results matching ""

    No results matching ""