Skip to content

Commit

Permalink
feat(iOS): add fileopenpicker file limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam committed Jun 6, 2024
1 parent 59d9d05 commit ce2d123
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/Uno.UWP/Storage/Pickers/FileOpenPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class FileOpenPicker : IFilePicker
{
private string _settingsIdentifier = string.Empty;
private string _commitButtonText = string.Empty;
private int _multipleFileLimit;

/// <summary>
/// Gets the collection of file types that the folder picker displays.
Expand Down Expand Up @@ -98,6 +99,22 @@ private void ValidateConfiguration()
throw new InvalidOperationException("You must provide at least a general file type filter ('*')");
}
}

internal void SetMultipleFileLimit(int limit)
{
_multipleFileLimit = limit;
}
#endif
}

public static class FileOpenPickerExtensions
{
/// <summary>
/// Sets the file limit a user can select when picking multiple files.
/// </summary>
public static void SetLimit(this FileOpenPicker picker, int limit)
{
picker.SetMultipleFileLimit(limit);
}
}
}
10 changes: 5 additions & 5 deletions src/Uno.UWP/Storage/Pickers/FileOpenPicker.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private Task<IReadOnlyList<StorageFile>> PickMultipleFilesTaskAsync(Cancellation
return tcs.Task;
}

private UIViewController GetViewController(bool multiple, TaskCompletionSource<StorageFile?[]> completionSource)
private UIViewController GetViewController(bool multiple, int limit, TaskCompletionSource<StorageFile?[]> completionSource)
{
var iOS14AndAbove = UIDevice.CurrentDevice.CheckSystemVersion(14, 0);
switch (SuggestedStartLocation)
Expand All @@ -69,7 +69,7 @@ private UIViewController GetViewController(bool multiple, TaskCompletionSource<S
var imageConfiguration = new PHPickerConfiguration
{
Filter = PHPickerFilter.ImagesFilter,
SelectionLimit = 0
SelectionLimit = limit
};
return new PHPickerViewController(imageConfiguration)
{
Expand All @@ -79,7 +79,7 @@ private UIViewController GetViewController(bool multiple, TaskCompletionSource<S
var videoConfiguration = new PHPickerConfiguration
{
Filter = PHPickerFilter.VideosFilter,
SelectionLimit = 0
SelectionLimit = limit
};
return new PHPickerViewController(videoConfiguration)
{
Expand All @@ -90,7 +90,7 @@ private UIViewController GetViewController(bool multiple, TaskCompletionSource<S
var documentTypes = UTTypeMapper.GetDocumentTypes(FileTypeFilter);
return new UIDocumentPickerViewController(documentTypes, UIDocumentPickerMode.Open)
{
AllowsMultipleSelection = multiple,
AllowsMultipleSelection = multiple,
ShouldShowFileExtensions = true,
Delegate = new FileOpenPickerDelegate(completionSource)
};
Expand All @@ -107,7 +107,7 @@ private async Task<FilePickerSelectedFilesArray> PickFilesAsync(bool multiple, C

var completionSource = new TaskCompletionSource<StorageFile?[]>();

using var viewController = this.GetViewController(multiple, completionSource);
using var viewController = this.GetViewController(multiple, _multipleFileLimit, completionSource);

viewController.OverrideUserInterfaceStyle = CoreApplication.RequestedTheme == SystemTheme.Light ?
UIUserInterfaceStyle.Light : UIUserInterfaceStyle.Dark;
Expand Down

0 comments on commit ce2d123

Please sign in to comment.