On android, change ten milly nux secondary action to save instead of share

zio/dev^2
Paul Frazee 2024-09-12 12:57:08 -07:00
parent cc8e7b5ae5
commit 7acf0e1284
1 changed files with 38 additions and 5 deletions

View File

@ -3,6 +3,8 @@ import {View} from 'react-native'
import Animated, {FadeIn} from 'react-native-reanimated' import Animated, {FadeIn} from 'react-native-reanimated'
import ViewShot from 'react-native-view-shot' import ViewShot from 'react-native-view-shot'
import {Image} from 'expo-image' import {Image} from 'expo-image'
import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker'
import * as MediaLibrary from 'expo-media-library'
import {moderateProfile} from '@atproto/api' import {moderateProfile} from '@atproto/api'
import {msg, Trans} from '@lingui/macro' import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
@ -12,13 +14,14 @@ import {getCanvas} from '#/lib/canvas'
import {shareUrl} from '#/lib/sharing' import {shareUrl} from '#/lib/sharing'
import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeDisplayName} from '#/lib/strings/display-names'
import {sanitizeHandle} from '#/lib/strings/handles' 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 {useModerationOpts} from '#/state/preferences/moderation-opts'
import {useProfileQuery} from '#/state/queries/profile' import {useProfileQuery} from '#/state/queries/profile'
import {useAgent, useSession} from '#/state/session' import {useAgent, useSession} from '#/state/session'
import {useComposerControls} from 'state/shell' import {useComposerControls} from 'state/shell'
import {formatCount} from '#/view/com/util/numeric/format' import {formatCount} from '#/view/com/util/numeric/format'
import {Logomark} from '#/view/icons/Logomark' import {Logomark} from '#/view/icons/Logomark'
import * as Toast from 'view/com/util/Toast'
import { import {
atoms as a, atoms as a,
ThemeProvider, ThemeProvider,
@ -221,7 +224,31 @@ export function TenMillionInner({userNumber}: {userNumber: number}) {
}) })
} }
}, [uri, control]) }, [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) { if (uri) {
const canvas = await getCanvas(uri) const canvas = await getCanvas(uri)
const imgHref = canvas const imgHref = canvas
@ -586,7 +613,7 @@ export function TenMillionInner({userNumber}: {userNumber: number}) {
<Button <Button
disabled={isLoadingImage} disabled={isLoadingImage}
label={ label={
isNative isNative && isIOS
? _(msg`Share image externally`) ? _(msg`Share image externally`)
: _(msg`Download image`) : _(msg`Download image`)
} }
@ -594,8 +621,14 @@ export function TenMillionInner({userNumber}: {userNumber: number}) {
variant="solid" variant="solid"
color="secondary" color="secondary"
shape="square" shape="square"
onPress={isNative ? onNativeShare : download}> onPress={
<ButtonIcon icon={isNative ? Share : Download} /> isNative
? isIOS
? onNativeShare
: onNativeDownload
: onWebDownload
}>
<ButtonIcon icon={isNative && isIOS ? Share : Download} />
</Button> </Button>
<Button <Button
disabled={isLoadingImage} disabled={isLoadingImage}