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

fix(iOS): styles resolution #19841

Merged
merged 5 commits into from
Apr 7, 2025
Merged

Conversation

ajpinedam
Copy link
Contributor

GitHub Issue (If applicable): closes #19825

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

Style resolution only works from immediate parents. Any style at the Page level or above the direct parent is not being recognized.

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@ajpinedam ajpinedam requested a review from MartinZikmund April 4, 2025 13:47
@ajpinedam ajpinedam self-assigned this Apr 4, 2025
@unodevops
Copy link
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-19841/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-19841/index.html

@jeromelaban jeromelaban requested a review from Copilot April 4, 2025 16:01
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

@ajpinedam
Copy link
Contributor Author

First of all, the issue reported is happening when within a ScrollViewer

Reason:

When, doing the resource resolution, we had this code:

while (candidate is not null)
{
    if (candidate is FrameworkElement fe)
    {
        if (fe.TryGetResources() is { IsEmpty: false }) // It's legal (if pointless) on UWP to set Resources to null from user code, so check
        {
            yield return fe.Resources;
        }
        candidate = fe.Parent as FrameworkElement; // [Marked Line] Issue is here
    }
    else
    {
        candidate = VisualTreeHelper.GetParent(candidate) as DependencyObject;
    }
}

On the marked line, we expect the Parent to be a FrameworkElement. When this is not the case, the candidate becomes null, forcing the code to exit the while loop, and preventing us from going higher up in the visual tree.

In our case specifically, for the ScrollViewer, this has a NativeScrollContentPresenter as one of its Children. The NativeScrollContentPresenter is a DependencyObject but not a FrameworkElement.

So for the following XAML tree:

  <Page.Resources>
    <Style TargetType="Button">
      <Setter Property="Background" Value="Red"/>
    </Style>
  </Page.Resources>

  <ScrollViewer>
    <ScrollViewer.Resources>
      <Style TargetType="Button">
        <Setter Property="Background" Value="Red"/>
      </Style>
    </ScrollViewer.Resources>
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" utu:SafeArea.Insets="VisibleBounds">
      <Button Content="Test Content"/>
    </StackPanel>
  </ScrollViewer>
</Page>

When we reached the point of navigating from the StackPanel up to the ScrollViewer, we stopped the style resolution at the NativeScrollContentPresenter and never reached the ScrollViewer or the Page.

The solution proposed is to remove the casting to FrameworkElement

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-19841/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-19841/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-19841/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-19841/index.html

@unodevops
Copy link
Contributor

⚠️⚠️ The build 159879 has failed on Uno.UI - CI.

@ajpinedam ajpinedam force-pushed the dev/anpi/fix.style.resolution branch from b9d3d5a to bb5e410 Compare April 4, 2025 23:05
@unodevops
Copy link
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-19841/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-19841/index.html

@unodevops
Copy link
Contributor

⚠️⚠️ The build 159904 has failed on Uno.UI - CI.

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-19841/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-19841/index.html

@jeromelaban jeromelaban merged commit d960546 into master Apr 7, 2025
67 of 71 checks passed
@jeromelaban jeromelaban deleted the dev/anpi/fix.style.resolution branch April 7, 2025 12:04
@jeromelaban
Copy link
Member

@Mergifyio backport release/stable/5.6

Copy link
Contributor

mergify bot commented Apr 7, 2025

backport release/stable/5.6

✅ Backports have been created

jeromelaban added a commit that referenced this pull request Apr 7, 2025
…5.6/pr-19841

fix(iOS): styles resolution (backport #19841)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS 5.6 regression] Parent control resources completely ignored beyond direct parent
5 participants