Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement system-provided file selection display on iOS #6445

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

frenzibyte
Copy link
Member

I'll preface this with a warning that I'm not quite experienced in the world of UIKit, and the implementation in this PR came from a one/two-days of researching Apple's documentations. I'm still unsure about the way I'm disposing the view controller on Dispose but I don't sense any issues on real-world testing.

This is implemented in a manner where if a FileSelector is loaded, it checks whether the platform supports system-based file selection, and hides the contents of the FileSelector in favour of that.

This is accompanied with osu!-side diff for the final behaviour shown in the video below.

osu!-side diff
diff --git a/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs b/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs
index 81023417a5..924a2dabfe 100644
--- a/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs
+++ b/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs
@@ -255,6 +255,8 @@ private partial class FileChooserPopover : OsuPopover
             protected override string PopInSampleName => "UI/overlay-big-pop-in";
             protected override string PopOutSampleName => "UI/overlay-big-pop-out";
 
+            private readonly FileSelector fileSelector;
+
             public FileChooserPopover(string[] handledExtensions, Bindable<FileInfo?> currentFile, string? chooserPath)
                 : base(false)
             {
@@ -264,7 +266,7 @@ public FileChooserPopover(string[] handledExtensions, Bindable<FileInfo?> curren
                     // simplest solution to avoid underlying text to bleed through the bottom border
                     // https://github.com/ppy/osu/pull/30005#issuecomment-2378884430
                     Padding = new MarginPadding { Bottom = 1 },
-                    Child = new OsuFileSelector(chooserPath, handledExtensions)
+                    Child = fileSelector = new FileSelector(chooserPath, handledExtensions)
                     {
                         RelativeSizeAxes = Axes.Both,
                         CurrentFile = { BindTarget = currentFile }
@@ -273,24 +275,43 @@ public FileChooserPopover(string[] handledExtensions, Bindable<FileInfo?> curren
             }
 
             [BackgroundDependencyLoader]
-            private void load(OverlayColourProvider colourProvider)
+            private void load()
             {
-                Add(new Container
+                if (fileSelector.UsingSystemFileSelector)
                 {
-                    RelativeSizeAxes = Axes.Both,
-                    Masking = true,
-                    BorderThickness = 2,
-                    CornerRadius = 10,
-                    BorderColour = colourProvider.Highlight1,
-                    Children = new Drawable[]
+                    // keep present for FileSelector scheduling to still work.
+                    Body.AlwaysPresent = true;
+                    Body.Hide();
+                }
+            }
+
+            private partial class FileSelector : OsuFileSelector
+            {
+                public FileSelector(string? initialPath = null, string[]? validFileExtensions = null)
+                    : base(initialPath, validFileExtensions)
+                {
+                }
+
+                [BackgroundDependencyLoader]
+                private void load(OverlayColourProvider colourProvider)
+                {
+                    TopLevelContent.Add(new Container
                     {
-                        new Box
+                        RelativeSizeAxes = Axes.Both,
+                        Masking = true,
+                        BorderThickness = 2,
+                        CornerRadius = 10,
+                        BorderColour = colourProvider.Highlight1,
+                        Children = new Drawable[]
                         {
-                            Colour = Color4.Transparent,
-                            RelativeSizeAxes = Axes.Both,
-                        },
-                    }
-                });
+                            new Box
+                            {
+                                Colour = Color4.Transparent,
+                                RelativeSizeAxes = Axes.Both,
+                            },
+                        }
+                    });
+                }
             }
         }
     }
diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs b/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs
index addea5c4a9..8c6477090b 100644
--- a/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs
+++ b/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs
@@ -29,7 +29,7 @@ public OsuFileSelector(string? initialPath = null, string[]? validFileExtensions
         [BackgroundDependencyLoader]
         private void load(OverlayColourProvider colourProvider)
         {
-            AddInternal(new Box
+            TopLevelContent.Add(new Box
             {
                 RelativeSizeAxes = Axes.Both,
                 Colour = colourProvider.Background5,

Preview:

ScreenRecording_12-07-2024.04-17-13_1.mov

@peppy
Copy link
Member

peppy commented Dec 16, 2024

@frenzibyte conflicts 🙏

@frenzibyte
Copy link
Member Author

frenzibyte commented Dec 16, 2024

Conflicts should be resolved. Also added minor iOS window API to do away with some of the awkward hookings and the sprinkled null forgiving operators everywhere in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants