Skip to content

Commit

Permalink
Merge pull request #18460 from unoplatform/dev/mazi/winui-frame-mode-…
Browse files Browse the repository at this point in the history
…mobile
  • Loading branch information
MartinZikmund authored Nov 27, 2024
2 parents d7ff587 + 156c9e8 commit facfb7f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion doc/articles/controls/Frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@ uid: Uno.Controls.Frame

## Using Frame with Uno

To improve performance during navigation, `Frame` on Android, iOS, and WebAssembly targets operates in different way than in WinUI. Whereas WinUI follows `NavigationCacheMode` property on individual `Page` instances, on iOS and Android we keep the individual page instances in the back stack in memory by default. This way the can be quickly surfaced back to the user during back navigation. This behavior can be controlled using the `FeatureConfiguration.Frame.UseWinUIBehavior` property. This defaults to `true` on Skia targets and to `false` on Android, iOS and WebAssembly.
To improve performance during navigation, `Frame` on Android, iOS, and WebAssembly targets operates in different way than in WinUI. Whereas WinUI follows `NavigationCacheMode` property on individual `Page` instances, on iOS and Android we keep the individual page instances in the back stack in memory by default. This way they can be quickly surfaced back to the user during back navigation. This behavior can be controlled using the `FeatureConfiguration.Frame.UseWinUIBehavior` property. This defaults to `true` on Skia targets and to `false` on Android, iOS and WebAssembly.

If you set `UseWinUIBehavior` to `true` on Android and iOS, you also need to override the default style for the control. You can do this by explicitly setting the `Style` to `XamlDefaultFrame`:

```xml
<Frame Style="{StaticResource XamlDefaultFrame}" />
```

Or by creating an implicit style based on `XamlDefaultFrame`:

```xml
<Style TargetType="Frame" BasedOn="XamlDefaultFrame" />
```
1 change: 0 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/Frame/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.UI.Xaml.Navigation;
using Uno.Disposables;
using Uno.UI;
using Uno.UI.Helpers;
using Uno.UI.Xaml.Core;
Expand Down
13 changes: 13 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Frame/Frame.partial.mux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.UI.Xaml.Navigation;
using Uno.Disposables;
using Uno.Foundation.Logging;
using Uno.UI.Xaml.Core;

namespace Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -49,6 +50,18 @@ protected override void OnApplyTemplate()

base.OnApplyTemplate();

#if HAS_UNO && (__ANDROID__ || __IOS__)
// It is not possible to use the WinUI behavior with a NativeFramePresenter.
// We have two such presenters - on internal in Uno, another in Uno.Toolkit.
if (_useWinUIBehavior && this.TemplatedRoot?.GetType().Name?.Contains("NativeFramePresenter", StringComparison.Ordinal) == true)
{
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError("WinUI Frame behavior is not compatible with NativeFramePresenter. Set the Frame.Style to '{StaticResource XamlDefaultFrame}' instead.");
}
}
#endif

if (m_tpNext is not null)
{
m_nextClick.Disposable = null;
Expand Down

0 comments on commit facfb7f

Please sign in to comment.