also looking at this
fix(android): resolve share() with whether the person picked an app
#210
12 files
+399
-56
| @@ -1050,20 +1050,33 @@ export const share = { | ||
| 1050 | 1050 | /** |
| 1051 | 1051 | * Open native share dialog. |
| 1052 | 1052 | * |
| 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 | * | |
| 1053 | 1056 | * @param options - Share options |
| 1054 | 1057 | */ |
| 1055 | async share(options: ShareOptions): Promise<void> { | |
| 1058 | async share(options: ShareOptions): Promise<boolean> { | |
| 1056 | 1059 | const craft = getCraftMobile() |
| 1057 | 1060 | if (typeof window !== 'undefined' && craft?.share) { |
| 1058 | 1061 | return craft.share.share(options) |
| 1059 | 1062 | } |
| 1060 | 1063 | // Web Share API fallback |
| 1061 | 1064 | 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 | } | |
| 1067 | 1080 | } |
| 1068 | 1081 | else { |
| 1069 | 1082 | throw new Error('Share API not available') |
| @@ -1580,7 +1593,7 @@ interface CraftMobileBridge { | ||
| 1580 | 1593 | readRecording?(): Promise<Location[]> |
| 1581 | 1594 | } |
| 1582 | 1595 | share?: { |
| 1583 | share(options: ShareOptions): Promise<void> | |
| 1596 | share(options: ShareOptions): Promise<boolean> | |
| 1584 | 1597 | } |
| 1585 | 1598 | lifecycle?: { |
| 1586 | 1599 | getState(): AppState |