Open
Description
Description
In the .NET Podcasts app, it has the following XAML:
<OnPlatform x:TypeArguments="View">
<On Platform="UWP, macOS">
<Grid RowDefinitions="*, auto">
<SearchBar x:Name="searchBar"
HorizontalOptions="Start"
WidthRequest="460"
Text="{Binding TextToSearch, Source={x:Reference selfMediaElementView}}"
SearchCommand="{Binding SearchCommand, Source={x:Reference selfMediaElementView}}" />
<Label Text="See All Categories"
Style="{StaticResource BodyLLabelStyle}"
TextColor="{StaticResource Primary}"
Grid.Row="1"
HorizontalOptions="End"
Margin="0,0,30,0"
IsVisible="{Binding ShowSearchCategories, Source={x:Reference selfMediaElementView}}"
FontSize="16">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
</Grid>
</On>
<On Platform="Android,iOS">
<Grid ColumnDefinitions="*,*"
Margin="16,12">
<Image Source="{AppThemeBinding Light=logo_header_horizontal.png,Dark=logo_color_horizontal_darkmode.png}"
HeightRequest="34"
WidthRequest="125"
VerticalOptions="Center"
HorizontalOptions="Start" />
<Image Source="search.png"
Grid.Column="1"
VerticalOptions="Center"
HorizontalOptions="End"
HeightRequest="20"
WidthRequest="20">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Image.GestureRecognizers>
</Image>
</Grid>
</On>
</OnPlatform>
When building the app for Android
, I'm still seeing the controls inside the <On Platform="UWP, macOS">
clause get created and properties set on them. For example, the SearchBar
is only used in UWP, macOS
, but in my compiled Android app I see:
private void InitializeComponent()
{
ReferenceExtension referenceExtension = new ReferenceExtension();
BindingExtension bindingExtension = new BindingExtension();
ReferenceExtension referenceExtension2 = new ReferenceExtension();
BindingExtension bindingExtension2 = new BindingExtension();
SearchBar searchBar = new SearchBar();
This pattern is used in 3 places in the .NET Podcasts app:
- The above
- The
Player
control - The
ShowDetailPage
.
We should optimize this pattern so when building for Android, the other platforms' controls are not created.
cc @StephaneDelcroix @jonathanpeppers
Steps to Reproduce
git clone https://github.com/microsoft/dotnet-podcasts.git
- cd dotnet-podcasts/src/Mobile
dotnet build Microsoft.NetConf2021.Maui.csproj -t:Run -c Release -f net6.0-android -r android-arm64
- Inspect the IL of
HeaderControl.InitializeComponent()
Version with bug
Preview 14 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
All
Did you find any workaround?
No response
Relevant log output
No response