Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ten-milly-android-save' into ten…
Browse files Browse the repository at this point in the history
…-milly

* origin/ten-milly-android-save:
  On android, change ten milly nux secondary action to save instead of share
  • Loading branch information
estrattonbailey committed Sep 13, 2024
2 parents 4637c66 + 7acf0e1 commit b47bac9
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/components/dialogs/nuxs/TenMillion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -585,16 +612,22 @@ export function TenMillionInner({userNumber}: {userNumber: number}) {
<Button
disabled={isLoadingImage}
label={
isNative
isNative && isIOS
? _(msg`Share image externally`)
: _(msg`Download image`)
}
size="large"
variant="solid"
color="secondary"
shape="square"
onPress={isNative ? onNativeShare : download}>
<ButtonIcon icon={isNative ? Share : Download} />
onPress={
isNative
? isIOS
? onNativeShare
: onNativeDownload
: onWebDownload
}>
<ButtonIcon icon={isNative && isIOS ? Share : Download} />
</Button>
<Button
disabled={isLoadingImage}
Expand Down

0 comments on commit b47bac9

Please sign in to comment.