Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { Component } from 'react';
import {
ActivityIndicator,
FlatList,
PermissionsAndroid,
Platform,
StyleSheet,
View,
Text,
FlatList,
ActivityIndicator,
View,
} from 'react-native';
import CameraRoll from "@react-native-community/cameraroll";
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -70,7 +71,11 @@ class CameraRollPicker extends Component {
this.renderImage = this.renderImage.bind(this);
}

componentWillMount() {
async componentWillMount() {
if (Platform.OS === "android" && !(await this.hasAndroidPermission())) {
return;
}

this.fetch();
}

Expand All @@ -80,6 +85,22 @@ class CameraRollPicker extends Component {
});
}

// Ensure we have the correct permissions read external storage on Android (required for Android 10+).
// Pulled straight from cameraroll README.
// See https://github.com/react-native-cameraroll/react-native-cameraroll#permissions.
async hasAndroidPermission() {
console.log( "Hello there love!" );
const permission = PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE;

const hasPermission = await PermissionsAndroid.check(permission);
if (hasPermission) {
return true;
}

const status = await PermissionsAndroid.request(permission);
return status === 'granted';
}

onEndReached() {
if (!this.state.noMore) {
this.fetch();
Expand Down