Skip to content

Commit a94433a

Browse files
committed
make lib trimmable
1 parent a859c01 commit a94433a

File tree

6 files changed

+13
-19
lines changed

6 files changed

+13
-19
lines changed

Vapolia.SegmentedViews/ISegmentedView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface ISegmentedView : IView, ITextStyle
1616
internal void SetSelectedIndex(int i);
1717
public bool IsSelectionRequired { get; }
1818

19-
internal string? TextPropertyName { get; }
19+
//internal string? TextPropertyName { get; }
2020
internal IValueConverter? TextConverter { get; }
2121
internal ObservableCollection<Segment> Children { get; }
2222
internal WidthDefinitionCollection? WidthDefinitions { get; }

Vapolia.SegmentedViews/MauiAppBuilderExtensions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Diagnostics.CodeAnalysis;
2-
using System.Runtime.CompilerServices;
32

43
[assembly: XmlnsDefinition("https://vapolia.eu/Vapolia.SegmentedViews", "Vapolia.SegmentedViews", AssemblyName = "Vapolia.SegmentedViews")]
54
[assembly: Microsoft.Maui.Controls.XmlnsPrefix("https://vapolia.eu/Vapolia.SegmentedViews", "segmented")]
@@ -10,15 +9,6 @@ namespace Vapolia.SegmentedViews;
109
[SuppressMessage("Usage", "CA2255: ’ModuleInitializer’ warning")]
1110
public static class MauiAppBuilderExtensions
1211
{
13-
//Force load the assembly for the XAML compiler, to fix:
14-
// Error XC0000 : Cannot resolve type "https://vapolia.eu/Vapolia.SegmentedViews:segmented:Segment".
15-
[ModuleInitializer]
16-
internal static void LoadAssembly()
17-
{
18-
_ = new Segment();
19-
}
20-
21-
2212
/// <summary>
2313
/// Add Maui handlers for this control
2414
/// </summary>

Vapolia.SegmentedViews/Segment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ private void OnItemChanged(object value, object newValue)
2424
{
2525
if (value is INotifyPropertyChanged notifyPropertyChanged1)
2626
notifyPropertyChanged1.PropertyChanged -= OnItemPropertyChanged;
27-
27+
2828
if (newValue is INotifyPropertyChanged notifyPropertyChanged2)
2929
notifyPropertyChanged2.PropertyChanged += OnItemPropertyChanged;
30-
30+
3131
//Simulate the change of the whole item when an item's property has changed
3232
void OnItemPropertyChanged(object? sender, PropertyChangedEventArgs e)
3333
{

Vapolia.SegmentedViews/SegmentExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Globalization;
23

34
namespace Vapolia.SegmentedViews;
@@ -9,14 +10,15 @@ public static string GetText(this Segment segment, ISegmentedView segmentedContr
910
if (segment.Item == null)
1011
return string.Empty;
1112

12-
var obj = segmentedControl.TextPropertyName != null ? segment.Item.GetType().GetProperty(segmentedControl.TextPropertyName)?.GetValue(segment.Item) : segment.Item;
13+
//var obj = segmentedControl.TextPropertyName != null ? segment.Item.GetType().GetProperty(segmentedControl.TextPropertyName)?.GetValue(segment.Item) : segment.Item;
14+
var obj = segment.Item;
1315

1416
if (segmentedControl.TextConverter != null)
1517
obj = segmentedControl.TextConverter.Convert(obj, typeof(string), null, CultureInfo.CurrentCulture);
1618

1719
return obj?.ToString() ?? string.Empty;
1820
}
19-
21+
2022
public static List<GridLength> GetWidths(this ISegmentedView segmentedView)
2123
{
2224
return segmentedView.Children.Select((segment,i) =>

Vapolia.SegmentedViews/SegmentedView.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class SegmentedView : View, ISegmentedView, IFontElement
1717
#region Bindable Definitions
1818

1919
public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IEnumerable), typeof(SegmentedView), propertyChanged: (bindable, value, newValue) => ((SegmentedView)bindable).OnItemsSourceChanged((IEnumerable?)value, (IEnumerable?)newValue));
20-
public static readonly BindableProperty TextPropertyNameProperty = BindableProperty.Create(nameof(TextPropertyName), typeof(string), typeof(SegmentedView));
20+
//public static readonly BindableProperty TextPropertyNameProperty = BindableProperty.Create(nameof(TextPropertyName), typeof(string), typeof(SegmentedView));
2121
public static readonly BindableProperty TextConverterProperty = BindableProperty.Create(nameof(TextConverter), typeof(IValueConverter), typeof(SegmentedView));
2222
public static readonly BindableProperty SelectedBackgroundColorProperty = BindableProperty.Create(nameof(SelectedBackgroundColor), typeof(Color), typeof(SegmentedView), Colors.Blue);
2323
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(SegmentedView), Colors.Black);
@@ -28,7 +28,7 @@ public class SegmentedView : View, ISegmentedView, IFontElement
2828

2929
#region Font
3030

31-
public static readonly BindableProperty FontFamilyProperty = BindableProperty.Create(nameof(FontFamily), typeof(string), typeof(IFontElement), default(string), propertyChanged: OnFontFamilyChanged);
31+
public static readonly BindableProperty FontFamilyProperty = BindableProperty.Create(nameof(FontFamily), typeof(string), typeof(IFontElement), propertyChanged: OnFontFamilyChanged);
3232
public static readonly BindableProperty FontSizeProperty = BindableProperty.Create(nameof(FontSize), typeof(double), typeof(IFontElement), 0d, propertyChanged: OnFontSizeChanged, defaultValueCreator: FontSizeDefaultValueCreator);
3333
public static readonly BindableProperty FontAttributesProperty = BindableProperty.Create(nameof(FontAttributes), typeof(FontAttributes), typeof(IFontElement), FontAttributes.None, propertyChanged: OnFontAttributesChanged);
3434
public static readonly BindableProperty FontAutoScalingEnabledProperty = BindableProperty.Create(nameof(FontAutoScalingEnabled), typeof(bool), typeof(IFontElement), true, propertyChanged: OnFontAutoScalingEnabledChanged);
@@ -61,7 +61,7 @@ public class SegmentedView : View, ISegmentedView, IFontElement
6161

6262
//if (DesignMode.IsDesignModeEnabled)
6363
[EditorBrowsable(EditorBrowsableState.Never)]
64-
public ObservableCollection<Segment> Children { get; } = new();
64+
public ObservableCollection<Segment> Children { get; } = [];
6565

6666
#region Bindables Properties
6767

@@ -72,7 +72,7 @@ public class SegmentedView : View, ISegmentedView, IFontElement
7272
/// </summary>
7373
public IEnumerable? ItemsSource { get => (IEnumerable?)GetValue(ItemsSourceProperty); set => SetValue(ItemsSourceProperty, value); }
7474

75-
public string? TextPropertyName { get => (string?)GetValue(TextPropertyNameProperty); set => SetValue(TextPropertyNameProperty, value); }
75+
//public string? TextPropertyName { get => (string?)GetValue(TextPropertyNameProperty); set => SetValue(TextPropertyNameProperty, value); }
7676
public IValueConverter? TextConverter { get => (IValueConverter?)GetValue(TextConverterProperty); set => SetValue(TextConverterProperty, value); }
7777

7878
/// <summary>

Vapolia.SegmentedViews/Vapolia.SegmentedViews.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<SingleProject>true</SingleProject>
99
<ImplicitUsings>enable</ImplicitUsings>
1010
<Nullable>enable</Nullable>
11+
<IsTrimmable>true</IsTrimmable>
1112

1213
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
1314
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
@@ -60,6 +61,7 @@
6061
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
6162
<PackageProjectUrl>https://github.com/vapolia/SegmentedViews</PackageProjectUrl>
6263
<PackageReleaseNotes>
64+
1.0.9: remove TextPropertyName as it uses reflection. Mark library as Trimmable.
6365
1.0.8: fix typo in Segment which prevented the Width property to work for Segments.
6466
1.0.7: net9.0 and Windows
6567
1.0.6: upgrade nugets.

0 commit comments

Comments
 (0)