You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(dialog) - Support picker mode for open dialog (#3030)
For iOS and Android, there are 2 distinct file picker dialogs, one for
picking media and one for picking documents.
Previously, the filters provided by the user would determing which
picker would be displayed.
However, this has led to undefined behavior when no filter was provided.
To resolve this, we now provide a PickerMode (meant for iOS and
eventually Android) to explicitly define which picker we want to
display.
Eventually, we may need to provide more explicit ways of filtering by
MIME type or having specific modes for ImagePicker or VideoPicker for
ease of use on mobile platforms.
But for now, this is an initial implementation that allows specifying
which UI would be preferable for a file picker on mobile platforms.
Copy file name to clipboardExpand all lines: plugins/dialog/guest-js/index.ts
+29-1Lines changed: 29 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,14 @@ interface DialogFilter {
30
30
interfaceOpenDialogOptions{
31
31
/** The title of the dialog window (desktop only). */
32
32
title?: string
33
-
/** The filters of the dialog. */
33
+
/**
34
+
* The filters of the dialog.
35
+
* The behavior of filters on mobile platforms (iOS and Android) is different from desktop.
36
+
* On Android, we are not able to filter by extension, only by MIME type.
37
+
* On iOS, we are able to filter by extension in the document picker, but not in the media picker.
38
+
* In practice, if an extension for a video or image is included in the filters (such as `png` or `mp4`),
39
+
* the media picker will be displayed instead of the document picker (regardless of the {@linkcode pickerMode} value).
40
+
*/
34
41
filters?: DialogFilter[]
35
42
/**
36
43
* Initial directory or file path.
@@ -52,6 +59,25 @@ interface OpenDialogOptions {
52
59
recursive?: boolean
53
60
/** Whether to allow creating directories in the dialog. Enabled by default. **macOS Only** */
54
61
canCreateDirectories?: boolean
62
+
/**
63
+
* The preferred mode of the dialog.
64
+
* This is meant for mobile platforms (iOS and Android) which have distinct file and media pickers.
65
+
* On desktop, this option is ignored.
66
+
* If not provided, the dialog will automatically choose the best mode based on the MIME types of the filters.
67
+
*
68
+
* As a note, this is only fully implemented on iOS for the time being.
69
+
* Android does have a specific media picker, but it requires one of two of the below:
70
+
* 1) Defining exactly one mime type of media (for example, `image/*` or `video/*`) for use by the ACTION_GET_CONTENT intent.
71
+
* If both of these MIME types are provided to the filter, the Document picker will be displayed.
72
+
* 2) Using the registerForActivityResult API to register a result callback for the media picker as opposed to the ACTION_GET_CONTENT intent.
73
+
* This is the recommended way to implement the media picker on Android, as the ACTION_GET_CONTENT intent is currently marked as deprecated.
74
+
* However, using registerForActivityResult requires being called from within the actual Activity object (it is a protected method), for which Tauri currently
75
+
* does not have a hook.
76
+
* As a result, we currently only support the document picker on Android until either:
77
+
* 1) We allow for explicitly defining a VideoPicker or a ImagePicker on Android.
78
+
* 2) A hook is provided to allow for calling registerForActivityResult from within the Android Activity object.
0 commit comments