示例
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) => {
});
};
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>
);
}
}