unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
9.04k stars 734 forks source link

[IOS] `CommandBar` title disappears when garbage collector is triggered #9262

Open Marc-Antoine-Soucy opened 2 years ago

Marc-Antoine-Soucy commented 2 years ago

Current behavior

When the commandbar has it's title linked to a templatebinding and you navigate to another page, trigger the garbage collector, and then go back, the title is gone.

gbcollector

Expected behavior

The title should not disappear.

How to reproduce it (as minimally and precisely as possible)

Open the app, navigate to the next page, click on the garbage collector button Navigate back Notice Title disappeared CommandBarOffset (1).zip

Workaround

Works on UWP/WinUI

Yes (the bug is not present in UWP)

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia, Uno.UI.RemoteControl / Uno.WinUI.RemoteControl

NuGet package version(s)

image

Affected platforms

IOS

IDE

Visual Studio 2022

IDE version

Version 17.2.5

Relevant plugins

none

Anything else we need to know?

I made this sample from another sample that only had android/ios/uwp. I will try to put all the platforms in my samples in the future.

kazo0 commented 2 years ago

I have a feeling that this may be happening because of the Content being set to a FrameworkElement instead of just a string. If you were to TemplateBind the CommandBarTitle directly to the CommandBar.Content property does the issue still occur?

We have to basically force the custom view for the title to have its parent be the CommandBar instead of the native view. I'm thinking that we're not maintaining that relationship somewhere so the binding breaks

https://github.com/unoplatform/uno/blob/d4689ec1356d2cab7cb770fb1cb3d5e789fe9d16/src/Uno.UI/Controls/CommandBar/CommandBarNavigationItemRenderer.iOS.cs#L131-L135

Marc-Antoine-Soucy commented 2 years ago

@kazo0 So, I tried it and the title does indeed stop disappearing. Only thing I'm not 100% about is how to change the style of the title. Is there some style I can override to change it?

kazo0 commented 2 years ago

@Marc-Antoine-Soucy no :) you're pretty much stuck with the native iOS look of the title.

"When Content is a string, it's displayed using the platform's default font family, font size, font style and text alignment. Only the foreground color can be changed, using Foreground" https://platform.uno/docs/articles/controls/CommandBar.html#content

I am looking into the issue, hopefully we can get the custom Content working properly again soon

CommandBar
Marc-Antoine-Soucy commented 2 years ago

Alright, thanks

kazo0 commented 2 years ago

I have a bad feeling it has to do with the fix from here: https://github.com/unoplatform/uno/issues/7012

kazo0 commented 2 years ago

Maybe not, it seems that the view is still actually present in the CommandBar, it's just empty since the TemplateBinding looks to be broken. If we use just a regular Binding to some string in the PageLayout's DataContext, it will still be there after GC.

I'll have to keep digging to see why the TemplateBinding isn't working

jeromelaban commented 2 years ago

We may need to force an strong reference to some views and not rely on the CommandBar proxy's storage.

kazo0 commented 1 year ago

@Marc-Antoine-Soucy

I am no longer able to reproduce this in your sample app, nor in the one I created here: GcCommandBar.zip

Maybe this doesn't occur in later version of iOS? Can you confirm on your end that this is no longer an issue?

Marc-Antoine-Soucy commented 1 year ago

@kazo0 I tried it on 16.x versions of IOS and it was fixed, so It does seem to be fixed on later versions of IOS. But, it still happens on IOS 14.3 simulator.

kazo0 commented 1 year ago

@Marc-Antoine-Soucy

Ah interesting, is this still a high priority or is your client not going to be targeting the affected versions of iOS?

jeromelaban commented 1 year ago

@takla21 mentioned that this issue is of high priority for an upcoming scenario.

kazo0 commented 1 year ago

@takla21 This is still happening on latest iOS versions or is it a blocker for iOS 14 and below?

takla21 commented 1 year ago

@kazo0 So I went ahead and updated the sample to latest and test whether it was still happening and it seems to happen on ios 14 & 15. However, on IOS 16 it seems fixed (iPhone SE iOS 16.5)

ios15ios14

Here's the updated sample CommandBarSample.zip

kazo0 commented 1 year ago

Curious if the same occurs with NavigationBar from Toolkit, I would imagine so