Skip to content

Commit 6570085

Browse files
committed
maui: compiled bindings
* Try to resolve all warnings * Required for AOT
1 parent 29108fa commit 6570085

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+501
-575
lines changed

Diff for: Directory.Build.props

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<LangVersion>latest</LangVersion>
55
<Version>5.11.0</Version>
6+
<Nullable>warnings</Nullable>
67
<!-- Version Code Format (.NET Version, App Version, Build Number) -->
78
<!-- Note: Update here as well as Maui.AppWidget xproj -->
89
<VersionCode Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'windows'">95110000</VersionCode>
@@ -39,6 +40,11 @@
3940
<!-- Maui -->
4041
<PropertyGroup>
4142
<MauiVersion>9.0.40</MauiVersion>
43+
<_MauiBindingInterceptorsSupport>true</_MauiBindingInterceptorsSupport>
44+
<MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>
45+
<MauiStrictXamlCompilation>true</MauiStrictXamlCompilation>
46+
<NoWarn Condition="'$(_TargetPlatformIsWindows)' != 'True'">$(NoWarn);MT7091</NoWarn>
47+
<WarningsAsErrors Condition="'$(_TargetPlatformIsWindows)' != 'True'">$(WarningsAsErrors);XC0022;XC0023;IL2026</WarningsAsErrors>
4248
</PropertyGroup>
4349

4450
<PropertyGroup>

Diff for: Maui/SimpleWeather.Maui/Controls/AppBar/AppBarItem.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void UpdateLayout()
196196
_appbarItemText.Text = _originalText;
197197
else
198198
{
199-
if (Device.RuntimePlatform == Device.Android && !string.IsNullOrEmpty(_originalText))
199+
if (DeviceInfo.Platform == DevicePlatform.Android && !string.IsNullOrEmpty(_originalText))
200200
_appbarItemText.Text = _originalText.ToUpper();
201201
}
202202
}

Diff for: Maui/SimpleWeather.Maui/Controls/HourlyForecastItem.xaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
xmlns:mrkup="clr-namespace:SimpleWeather.Maui.MarkupExtensions"
1010
WidthRequest="{OnIdiom Default=150, Phone={mrkup:OnDeviceWidth MinWidth=828, Default=90, GreaterThanEq=100}, Tablet=110}"
1111
HeightRequest="{OnIdiom Default=250, Phone={mrkup:OnDeviceWidth MinWidth=828, Default=200, GreaterThanEq=175}, Tablet=192}"
12-
BindingContextChanged="HourlyForecastItem_BindingContextChanged">
12+
BindingContextChanged="HourlyForecastItem_BindingContextChanged"
13+
x:Name="Control">
1314
<VerticalStackLayout VerticalOptions="Center">
1415
<HorizontalStackLayout
1516
MinimumHeightRequest="20"
@@ -46,7 +47,7 @@
4647
IconWidth="{OnIdiom Phone=36, Tablet=42, Default=50}"
4748
Margin="5"
4849
HorizontalOptions="Center"
49-
IconProvider="{Binding Source={RelativeSource AncestorType={x:Type controls:HourlyForecastItem}}, Path=IconProvider}"
50+
IconProvider="{Binding Source={x:Reference Control}, Path=IconProvider, x:DataType={x:Type controls:HourlyForecastItem}}"
5051
WeatherIcon="{Binding Icon}" />
5152
<Label
5253
Padding="{OnIdiom Default='10,0', Phone='4'}"

Diff for: Maui/SimpleWeather.Maui/Controls/HourlyForecastItemPanel.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</CollectionView.ItemsLayout>
3333
<CollectionView.ItemTemplate>
3434
<DataTemplate>
35-
<controls:HourlyForecastItem IconProvider="{Binding Source={RelativeSource AncestorType={x:Type controls:HourlyForecastItemPanel}}, Path=IconProvider, Mode=OneWay}">
35+
<controls:HourlyForecastItem IconProvider="{Binding Source={RelativeSource AncestorType={x:Type controls:HourlyForecastItemPanel}}, Path=IconProvider, Mode=OneWay, x:DataType={x:Type controls:HourlyForecastItemPanel}}">
3636
<controls:HourlyForecastItem.GestureRecognizers>
3737
<TapGestureRecognizer Tapped="HourlyItem_Tapped" />
3838
</controls:HourlyForecastItem.GestureRecognizers>

Diff for: Maui/SimpleWeather.Maui/Controls/IconControl.cs

+13-42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CommunityToolkit.Mvvm.DependencyInjection;
1+
using CommunityToolkit.Maui.Markup;
2+
using CommunityToolkit.Mvvm.DependencyInjection;
23
using SimpleWeather.Icons;
34
using SimpleWeather.Preferences;
45
using SimpleWeather.SkiaSharp;
@@ -83,7 +84,7 @@ public double IconHeight
8384
}
8485

8586
public static readonly BindableProperty IconHeightProperty =
86-
BindableProperty.Create(nameof(IconHeight), typeof(double), typeof(IconControl), double.NaN, propertyChanged: (obj, _, _) => (obj as IconControl)?.UpdateWeatherIcon());
87+
BindableProperty.Create(nameof(IconHeight), typeof(double), typeof(IconControl), -1d, propertyChanged: (obj, _, _) => (obj as IconControl)?.UpdateWeatherIcon());
8788

8889
public double IconWidth
8990
{
@@ -92,9 +93,9 @@ public double IconWidth
9293
}
9394

9495
public static readonly BindableProperty IconWidthProperty =
95-
BindableProperty.Create(nameof(IconWidth), typeof(double), typeof(IconControl), double.NaN, propertyChanged: (obj, _, _) => (obj as IconControl)?.UpdateWeatherIcon());
96+
BindableProperty.Create(nameof(IconWidth), typeof(double), typeof(IconControl), -1d, propertyChanged: (obj, _, _) => (obj as IconControl)?.UpdateWeatherIcon());
9697

97-
private readonly SettingsManager SettingsManager = Ioc.Default.GetService<SettingsManager>();
98+
private readonly SettingsManager _settingsManager = Ioc.Default.GetService<SettingsManager>();
9899

99100
public IconControl()
100101
{
@@ -124,7 +125,7 @@ public async void UpdateWeatherIcon()
124125
// Remove any animatable drawables
125126
RemoveAnimatedDrawables();
126127

127-
var wip = SharedModule.Instance.WeatherIconsManager.GetIconProvider(IconProvider ?? SettingsManager.IconProvider);
128+
var wip = SharedModule.Instance.WeatherIconsManager.GetIconProvider(IconProvider ?? _settingsManager.IconProvider);
128129

129130
if (ForceBitmapIcon)
130131
{
@@ -188,18 +189,8 @@ public async void UpdateWeatherIcon()
188189

189190
e.Surface.Flush(true);
190191
};
191-
canvas.SetBinding(HeightRequestProperty, new Binding()
192-
{
193-
Source = this,
194-
Path = nameof(IconHeight),
195-
Mode = BindingMode.OneWay,
196-
});
197-
canvas.SetBinding(WidthRequestProperty, new Binding()
198-
{
199-
Source = this,
200-
Path = nameof(IconWidth),
201-
Mode = BindingMode.OneWay,
202-
});
192+
canvas.Bind(HeightRequestProperty, static src => src.IconHeight, mode: BindingMode.OneWay, source: this);
193+
canvas.Bind(WidthRequestProperty, static src => src.IconWidth, mode: BindingMode.OneWay, source: this);
203194
iconElement = canvas;
204195

205196
if (drawable is SKLottieDrawable lottieDrawable)
@@ -244,18 +235,8 @@ public async void UpdateWeatherIcon()
244235

245236
e.Surface.Flush(true);
246237
};
247-
canvas.SetBinding(HeightRequestProperty, new Binding()
248-
{
249-
Source = this,
250-
Path = nameof(IconHeight),
251-
Mode = BindingMode.OneWay,
252-
});
253-
canvas.SetBinding(WidthRequestProperty, new Binding()
254-
{
255-
Source = this,
256-
Path = nameof(IconWidth),
257-
Mode = BindingMode.OneWay,
258-
});
238+
canvas.Bind(HeightRequestProperty, static src => src.IconHeight, mode: BindingMode.OneWay, source: this);
239+
canvas.Bind(WidthRequestProperty, static src => src.IconWidth, mode: BindingMode.OneWay, source: this);
259240
iconElement = canvas;
260241
}
261242
catch (Exception e)
@@ -276,7 +257,7 @@ public async void UpdateWeatherIcon()
276257

277258
private bool ShouldUseBitmap()
278259
{
279-
return ShowAsMonochrome && IconColor != Colors.Transparent && !IsBlackOrWhiteColor(IconColor);
260+
return ShowAsMonochrome && !Equals(IconColor, Colors.Transparent) && !IsBlackOrWhiteColor(IconColor);
280261
}
281262

282263
private bool IsBlackOrWhiteColor(Color c)
@@ -315,18 +296,8 @@ private async Task<IView> CreateBitmapIcon(IWeatherIconsProvider provider)
315296

316297
e.Surface.Flush(true);
317298
};
318-
canvas.SetBinding(HeightRequestProperty, new Binding()
319-
{
320-
Source = this,
321-
Path = nameof(IconHeight),
322-
Mode = BindingMode.OneWay,
323-
});
324-
canvas.SetBinding(WidthRequestProperty, new Binding()
325-
{
326-
Source = this,
327-
Path = nameof(IconWidth),
328-
Mode = BindingMode.OneWay,
329-
});
299+
canvas.Bind(HeightRequestProperty, static src => src.IconHeight, mode: BindingMode.OneWay, source: this);
300+
canvas.Bind(WidthRequestProperty, static src => src.IconWidth, mode: BindingMode.OneWay, source: this);
330301

331302
return canvas;
332303
}

0 commit comments

Comments
 (0)