dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

[Enhancement] Hot Reload: make Styles with Class hot reload friendly #620

Open etvorun opened 3 years ago

etvorun commented 3 years ago

Consider following XAML

<ResourceDictionary>
    <!-- Hot Reload unfriendly styles -->
    <Style TargetType="Label" Class="First">...</Style>
    <Style TargetType="Label" Class="Second">...</Style>
    <Style TargetType="Label" Class="First">...</Style>

    <!-- Hot Reload friendly styles ->
    <Style x:Key="MyStyle" TargetType="Label"/>
    <Style TargetType="Label"/>
<ResourceDictionary>

Last two styles are Hot Reload friendly wrt finding them in running app based on data from XAML. Just by looking at a <Style ...> and its owner <ResourceDictionary ...> we know how to find it in a running app, i.e. we know what key to use to look it up in RD. First three styles however are not hot reload friendly because of the way ResourceDictionary processes styles with Class. First, it uses non-public suffix for generated resource key. Second it combines multiple styles with same class in a single list; this means that not only we need to look at style but also we need to look at other styles with same class to calculate index. That makes Hot Reload much more difficult because to calculate correct index we need to look at both before-change and after-change XAML. For example, if user selects all 3 "unfriendly" styles and pastes

    <Style TargetType="Label" Class="Second">...</Style>
    <Style TargetType="Label" Class="First">...</Style>
    <Style TargetType="Label" Class="Second">...</Style>

then figuring out which items to remove will require non-trivial processing.

DISCUSSION IS NEEDED on how to address this.

spadapet commented 1 year ago

@etvorun, @StephaneDelcroix, what are good next steps for this request?