Add better sizing for pictures

This commit is contained in:
John Lyon-Smith
2018-04-21 20:27:16 -07:00
parent f9cee95614
commit 3c3ec55660
10 changed files with 172 additions and 115 deletions

View File

@@ -20,54 +20,40 @@ console.ignoredYellowBox = [
"<ViroSurface>",
]
export const ensurePermission = (
permission,
neverAskKeyName,
export const ensurePermissions = (
permissions,
rationale,
onSuccess,
onError
) => {
if (Platform.OS === "ios") {
if (onSuccess) {
onSuccess()
onSuccess(
permissions.reduce(
(dict, permission) =>
(dict[permission] = PermissionsAndroid.RESULTS.GRANTED),
{}
)
)
}
return
}
PermissionsAndroid.check(permission)
.then((flag) => {
if (flag) {
if (onSuccess) {
onSuccess()
}
return
}
return AsyncStorage.getItem(neverAskKeyName)
})
.then((value) => {
if (value === "YES") {
return
} else {
return PermissionsAndroid.request(permission, rationale)
}
})
.then((result) => {
if (result === PermissionsAndroid.RESULTS.GRANTED) {
if (onSuccess) {
onSuccess()
}
return
PermissionsAndroid.requestMultiple(permissions, rationale)
.then((results) => {
if (
!Object.values(results).every(
(grant) => grant === PermissionsAndroid.RESULTS.GRANTED
)
) {
return Promise.reject()
}
if (result === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN) {
AsyncStorage.setItem(neverAskKeyName, "YES")
}
if (onError) {
onError()
if (onSuccess) {
onSuccess(results)
}
})
.catch((err) => {
.catch((error) => {
if (onError) {
onError()
}