728x90
반응형
설치 필요
1) npm install @react-native-community/cameraroll --save
주소 : www.npmjs.com/package/@react-native-community/cameraroll
2) npm install react-native-unimodules
주소 : www.npmjs.com/package/react-native-unimodules
소스 :
import React, { Component } from 'react';
import {
Platform,
PermissionsAndroid,
View,
Image,
FlatList
} from 'react-native';
import CameraRoll from "@react-native-community/cameraroll";
class Image_Multi extends Component{
constructor(props) {
super(props);
this.state = {
data:''
};
}
async componentDidMount(){
if (Platform.OS === 'android') {
const result = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
{
title: 'Permission Explanation',
message: 'ReactNativeForYou would like to access your photos!',
},
);
if (result !== 'granted') {
console.log('Access to pictures was denied');
return;
}
}
CameraRoll.getPhotos({
first: 50,
assetType: 'Photos',
})
.then(res => {
this.setState({ data: res.edges });
})
.catch((error) => {
console.log(error);
});
}
render(){
return(
<View>
<FlatList
data={this.state.data}
numColumns={3}
renderItem={({ item }) => <Image
style={{
width: '33%',
height: 150,
}}
source={{ uri: item.node.image.uri }}
/>}
/>
</View>
)
}
}
export default Image_Multi;
728x90
반응형
'React Native' 카테고리의 다른 글
React native 애니메이션 ( 이동후 회전 + 뷰 등장 ) 연습 (0) | 2021.01.28 |
---|---|
Matter js 연습... (0) | 2021.01.27 |
팝업 다이얼로그 ver2 (0) | 2021.01.11 |
팝업 다이얼로그 ver1 (0) | 2021.01.11 |
화면 비율에 따른 폰트사이즈 구하기 (0) | 2021.01.08 |