From 7acf0e1284be7ca5a5e7a55e1823ec0be1255308 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 12 Sep 2024 12:57:08 -0700 Subject: [PATCH] On android, change ten milly nux secondary action to save instead of share --- .../dialogs/nuxs/TenMillion/index.tsx | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/components/dialogs/nuxs/TenMillion/index.tsx b/src/components/dialogs/nuxs/TenMillion/index.tsx index 6d80dd12..29256502 100644 --- a/src/components/dialogs/nuxs/TenMillion/index.tsx +++ b/src/components/dialogs/nuxs/TenMillion/index.tsx @@ -3,6 +3,8 @@ import {View} from 'react-native' import Animated, {FadeIn} from 'react-native-reanimated' import ViewShot from 'react-native-view-shot' import {Image} from 'expo-image' +import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker' +import * as MediaLibrary from 'expo-media-library' import {moderateProfile} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -12,13 +14,14 @@ import {getCanvas} from '#/lib/canvas' import {shareUrl} from '#/lib/sharing' import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeHandle} from '#/lib/strings/handles' -import {isNative} from '#/platform/detection' +import {isIOS, isNative} from '#/platform/detection' import {useModerationOpts} from '#/state/preferences/moderation-opts' import {useProfileQuery} from '#/state/queries/profile' import {useAgent, useSession} from '#/state/session' import {useComposerControls} from 'state/shell' import {formatCount} from '#/view/com/util/numeric/format' import {Logomark} from '#/view/icons/Logomark' +import * as Toast from 'view/com/util/Toast' import { atoms as a, ThemeProvider, @@ -221,7 +224,31 @@ export function TenMillionInner({userNumber}: {userNumber: number}) { }) } }, [uri, control]) - const download = React.useCallback(async () => { + const onNativeDownload = React.useCallback(async () => { + if (uri) { + const res = await requestMediaLibraryPermissionsAsync() + + if (!res) { + Toast.show( + _( + msg`You must grant access to your photo library to save the image.`, + ), + 'xmark', + ) + return + } + + try { + await MediaLibrary.createAssetAsync(uri) + Toast.show(_(msg`Image saved to your camera roll!`)) + } catch (e: unknown) { + console.log(e) + Toast.show(_(msg`An error occurred while saving the image!`), 'xmark') + return + } + } + }, [_, uri]) + const onWebDownload = React.useCallback(async () => { if (uri) { const canvas = await getCanvas(uri) const imgHref = canvas @@ -586,7 +613,7 @@ export function TenMillionInner({userNumber}: {userNumber: number}) {