ReviewOS

also looking at this

craft-native/craft

fix(android): resolve share() with whether the person picked an app

#210
Merged glennmichael123 wants to merge fix/android-share-outcome into main
12 files +399 -56
packages/typescript/src/api/mobile.tsmodified+20-7
Changes to packages/typescript/src/api/mobile.ts
@@ -1050,20 +1050,33 @@ export const share = {
10501050 /**
10511051 * Open native share dialog.
10521052 *
1053 * Resolves `true` when the person shared and `false` when they dismissed the
1054 * dialog, on the native bridges and in the browser alike.
1055 *
10531056 * @param options - Share options
10541057 */
1055 async share(options: ShareOptions): Promise<void> {
1058 async share(options: ShareOptions): Promise<boolean> {
10561059 const craft = getCraftMobile()
10571060 if (typeof window !== 'undefined' && craft?.share) {
10581061 return craft.share.share(options)
10591062 }
10601063 // Web Share API fallback
10611064 if (navigator.share) {
1062 await navigator.share({
1063 title: options.title,
1064 text: options.text,
1065 url: options.url
1066 })
1065 try {
1066 await navigator.share({
1067 title: options.title,
1068 text: options.text,
1069 url: options.url
1070 })
1071 return true
1072 }
1073 catch (error) {
1074 // A dismissed dialog rejects with AbortError here. The native bridges
1075 // answer false for the same thing, so this does too rather than
1076 // turning a person's choice into an exception.
1077 if (error instanceof DOMException && error.name === 'AbortError') return false
1078 throw error
1079 }
10671080 }
10681081else {
10691082 throw new Error('Share API not available')
@@ -1580,7 +1593,7 @@ interface CraftMobileBridge {
15801593 readRecording?(): Promise<Location[]>
15811594 }
15821595 share?: {
1583 share(options: ShareOptions): Promise<void>
1596 share(options: ShareOptions): Promise<boolean>
15841597 }
15851598 lifecycle?: {
15861599 getState(): AppState