-
-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Question / Discussion
I'm attempting to use Media.Plugin with Fabulous. Unfortunately, using the Xamarin.Essentials Media Picker would not be ideal as it doesn't yet support everything I need to do. Right now I'm just trying to figure out what compiles and works, I'm not at all sure this is the best way to do it, or if what I'm trying to do is actually possible. Currently I'm trying to get Media.Plugin to open up the photo gallery for picking photos on iOS, via the CrossMedia.Current.PickPhotosAsync
method. Current problem is the photo gallery never appears.
In my page, I have a button that dispatches a SelectFromGallery
message. This message is matched in update
:
let update msg model =
match msg with
| SelectFromGallery -> { model with IsBusy = true },
Cmd.ofMsg (processSelectFromGallery model |> Async.StartImmediateAsTask).Result, ExternalMsg.NoOp
processSelectFromGallery
is called and looks like this:
let processSelectFromGallery model =
async {
try
match CrossMedia.Current.IsPickPhotoSupported with
| false -> return SelectFromGalleryError
| true ->
let mediaOptions = new PickMediaOptions (RotateImage = true)
let multiPickerOptions = new MultiPickerOptions (MaximumImagesCount = model.MaximumImagesCount)
let! currentPhotos =
CrossMedia.Current.PickPhotosAsync (mediaOptions, multiPickerOptions) |> Async.AwaitTask
return SelectFromGallerySuccess currentPhotos
with
| _ -> return SelectFromGalleryError
}
I have left out Async.SwitchToThreadPool()
as it seems things should be happening on the UI thread otherwise an exception is thrown out from Media.Plugin code. I gathered from this issue that using Async.RunSynchronously
silently "refuses" to run the code on the UI thread, hence why I've gone with Async.StartImmediateAsTask
, as I was hoping to return the collection of photos with the SelectFromGallerySuccess
message. I don't actually get to returning SelectFromGallerySuccess
.
CrossMedia.Current.PickPhotosAsync
is called and following the code execution inside Media.Plugin I can see Media.Plugin is constructing a UIViewController that looks like it is meant to show the photo gallery picker. But this UIViewController never displays. My hunch is that this is all happening orthogonal to the update loop and so it's not registering. CrossMedia.Current.PickPhotosAsync
is meant to return a System.Collections.Generic.List<MediaFile>
so the UIViewController construction and display all happens inside Media.Plugin code.
So my questions would be: is my hunch correct? Or am I going about this entirely wrong? Is using MediaPlugin or the Xamarin Essentials MediaPicker (which I assume works in a similar way to James Montemagno's MedaPlugin in so far as constructing its own view controller) with Fabulous actually possible? And if not, what would be the recommended alternate way forward for dealing with picking media from the photo gallery?