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

refactor(responsive): remove ResponsiveHelper initialization #992

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions doc/controls/ResponsiveView.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@ The `ResponsiveView` provides the ability to display different content based on

The `ResponsiveView` control adapts to different screen sizes by dynamically choosing the right template. It looks at the current screen width and the defined templates. Since not all templates need a value, the control ensures a smooth user experience by picking the smallest defined template that satisfies the width requirements. If no match is found, it defaults to the largest defined template.

**Initialization**: The `ResponsiveHelper` needs to be hooked up to the window's `SizeChanged` event in order for this control to receive updates when the window size changes.
This is typically done in the `OnLaunched` method in the `App` class, where you can get the current `Window` instance for `ResponsiveHelper.HookupEvent`:

```cs
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
#if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO
MainWindow = new Window();
#else
MainWindow = Microsoft.UI.Xaml.Window.Current;
#endif

// ...
var helper = Uno.Toolkit.UI.ResponsiveHelper.GetForCurrentView();
helper.HookupEvent(MainWindow);
}
```

## Properties

| Property | Type | Description |
Expand Down Expand Up @@ -147,9 +129,9 @@ xmlns:utu="using:Uno.Toolkit.UI"
```

> [!NOTE]
> This `ResponsiveLayout` can also be provided from different locations. In order of precedences, they are:
> The `ResponsiveLayout` can also be provided from different locations. In order of precedences, they are:
>
> - from the `.ResponsiveLayout` property
> - in `ResponsiveView`'s parent `.Resources` with `x:Key="DefaultResponsiveLayout"`, or its ancestor's...
> - in `Application.Resources` with `x:Key="DefaultResponsiveLayout"`
> - from the hardcoded `ResponsiveHelper.Layout`
> - from the hardcoded `ResponsiveHelper.DefaultLayout` which is defined as [150/300/600/800/1080]
28 changes: 4 additions & 24 deletions doc/helpers/responsive-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,9 @@ uid: Toolkit.Helpers.ResponsiveExtension
The `ResponsiveExtension` class is a markup extension that enables the customization of `UIElement` properties based on screen size.
This functionality provides a dynamic and responsive user interface experience.

## Remarks

**Initialization**: The `ResponsiveHelper` needs to be hooked up to the window's `SizeChanged` event in order for this markup to receive updates when the window size changes.
This is typically done in the `OnLaunched` method in the `App` class, where you can get the current `Window` instance for `ResponsiveHelper.HookupEvent`:

```cs
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
#if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO
MainWindow = new Window();
#else
MainWindow = Microsoft.UI.Xaml.Window.Current;
#endif

// ...
var helper = Uno.Toolkit.UI.ResponsiveHelper.GetForCurrentView();
helper.HookupEvent(MainWindow);
}
```

## Platform limitation (UWP-desktop)

`ResponsiveExtension` relies on `MarkupExtension.ProvideValue(IXamlServiceProvider)` to find the target control and property for continuous value updates, and to obtain the property type to apply automatic type conversion, as its value properties are parsed as string by the XAML engine. Since this overload is a recent addition exclusive to WinUI, UWP projects targeting Windows won't have access to these features. Uno UWP projects targeting non-Windows platforms do not face this limitation. However, the Windows app may crash or present unexpected behavior if you attempt to use this markup on a non-string property.
`ResponsiveExtension` relies on `MarkupExtension.ProvideValue(IXamlServiceProvider)` to find the target control and property for continuous value updates, and to obtain the property type to apply automatic type conversion, as its value properties are parsed as `string` by the XAML engine. Since this overload is a recent addition exclusive to WinUI, UWP projects targeting Windows won't have access to these features. Uno UWP projects targeting non-Windows platforms do not face this limitation. However, the Windows app may crash or present unexpected behavior if you attempt to use this markup on a non-`string` property.

```xml
<Border Background="{utu:Responsive Narrow=Red, Wide=Blue}"
Expand Down Expand Up @@ -137,7 +117,7 @@ xmlns:utu="using:Uno.Toolkit.UI"
...

<Page.Resources>
<utu:ResponsiveLayout x:Key="CustomLayout"
<utu:ResponsiveLayout x:Key="CustomLayout"
Narrow="400"
Wide="800" />
</Page.Resources>
Expand All @@ -147,9 +127,9 @@ xmlns:utu="using:Uno.Toolkit.UI"
```

> [!NOTE]
> This `ResponsiveLayout` can also be provided from different locations. In the order of precedences, they are:
> The `ResponsiveLayout` can also be provided from different locations. In the order of precedences, they are:
>
> - from the `Layout` property
> - in the property owner's parent `.Resources` with `x:Key="DefaultResponsiveLayout"`, or the property owner's parent's parent's...
> - in `Application.Resources` with `x:Key="DefaultResponsiveLayout"`
> - from the hardcoded `ResponsiveHelper.Layout`
> - from the hardcoded `ResponsiveHelper.DefaultLayout` which is defined as [150/300/600/800/1080]
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ protected override async void OnLaunched(XamlLaunchActivatedEventArgs e)
#else
_window = XamlWindow.Current;
#endif
var helper = ResponsiveHelper.GetForCurrentView();
helper.HookupEvent(_window);

if (_window.Content is null)
{
Expand Down
Loading
Loading