Skip to content

Commit fb1c94a

Browse files
authored
General performance improvements (#13)
1 parent 79ff4b7 commit fb1c94a

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

Scr/Breadcrumb.xaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<ContentView x:Class="Breadcrumb.Breadcrumb"
33
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
44
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5-
Padding="4"
65
AutomationProperties.IsInAccessibleTree="False">
76
<ContentView.Content>
87
<ScrollView x:Name="BreadCrumbsScrollView"
@@ -12,9 +11,7 @@
1211
Orientation="Horizontal">
1312
<HorizontalStackLayout x:Name="BreadCrumbContainer"
1413
AutomationProperties.IsInAccessibleTree="False"
15-
HorizontalOptions="Fill"
16-
Loaded="BreadCrumbContainer_Loaded"
17-
VerticalOptions="Center" />
14+
Loaded="BreadCrumbContainer_Loaded" />
1815
</ScrollView>
1916
</ContentView.Content>
2017
</ContentView>

Scr/Breadcrumb.xaml.cs

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public partial class Breadcrumb : ContentView
99
#region Control properties
1010

1111
// Separator
12-
public static readonly BindableProperty SeparatorProperty = BindableProperty.Create(nameof(Separator), typeof(ImageSource), typeof(Breadcrumb), new FontImageSource { Glyph = " / ", Color = Colors.Black, Size = 15, });
12+
public static readonly BindableProperty SeparatorProperty = BindableProperty.Create(nameof(Separator), typeof(ImageSource), typeof(Breadcrumb), new FontImageSource { Glyph = " / ", Color = Colors.Black, Size = 15, }, BindingMode.OneTime);
1313

1414
public ImageSource Separator
1515
{
@@ -18,7 +18,7 @@ public ImageSource Separator
1818
}
1919

2020
// Separator height
21-
public static readonly BindableProperty SeparatorHeightProperty = BindableProperty.Create(nameof(SeparatorHeight), typeof(double), typeof(Breadcrumb), 15d);
21+
public static readonly BindableProperty SeparatorHeightProperty = BindableProperty.Create(nameof(SeparatorHeight), typeof(double), typeof(Breadcrumb), 15d, BindingMode.OneTime);
2222

2323
public double SeparatorHeight
2424
{
@@ -27,7 +27,7 @@ public double SeparatorHeight
2727
}
2828

2929
// FirstBreadCrumb
30-
public static readonly BindableProperty FirstBreadcrumbProperty = BindableProperty.Create(nameof(FirstBreadcrumb), typeof(ImageSource), typeof(Breadcrumb), null);
30+
public static readonly BindableProperty FirstBreadcrumbProperty = BindableProperty.Create(nameof(FirstBreadcrumb), typeof(ImageSource), typeof(Breadcrumb), null, BindingMode.OneTime);
3131

3232
public ImageSource FirstBreadcrumb
3333
{
@@ -36,7 +36,7 @@ public ImageSource FirstBreadcrumb
3636
}
3737

3838
// Scrollbar Visibility
39-
public static readonly BindableProperty ScrollBarVisibilityProperty = BindableProperty.Create(nameof(ScrollBarVisibility), typeof(ScrollBarVisibility), typeof(Breadcrumb), ScrollBarVisibility.Never);
39+
public static readonly BindableProperty ScrollBarVisibilityProperty = BindableProperty.Create(nameof(ScrollBarVisibility), typeof(ScrollBarVisibility), typeof(Breadcrumb), ScrollBarVisibility.Never, BindingMode.OneTime);
4040

4141
public ScrollBarVisibility ScrollBarVisibility
4242
{
@@ -45,7 +45,7 @@ public ScrollBarVisibility ScrollBarVisibility
4545
}
4646

4747
// FontSize
48-
public static readonly BindableProperty FontSizeProperty = BindableProperty.Create(nameof(FontSize), typeof(double), typeof(Breadcrumb), 15d);
48+
public static readonly BindableProperty FontSizeProperty = BindableProperty.Create(nameof(FontSize), typeof(double), typeof(Breadcrumb), 15d, BindingMode.OneTime);
4949

5050
[TypeConverter(typeof(FontSizeConverter))]
5151
public double FontSize
@@ -55,7 +55,7 @@ public double FontSize
5555
}
5656

5757
// Text Color
58-
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(Breadcrumb), Colors.Black);
58+
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(Breadcrumb), Colors.Black, BindingMode.OneTime);
5959

6060
public Color TextColor
6161
{
@@ -64,7 +64,7 @@ public Color TextColor
6464
}
6565

6666
// Corner radius
67-
public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(float), typeof(Breadcrumb), 10f);
67+
public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(float), typeof(Breadcrumb), 10f, BindingMode.OneTime);
6868

6969
public float CornerRadius
7070
{
@@ -73,7 +73,7 @@ public float CornerRadius
7373
}
7474

7575
// Breadcrumb margin
76-
public static readonly BindableProperty BreadcrumbMarginProperty = BindableProperty.Create(nameof(BreadcrumbMargin), typeof(Thickness), typeof(Breadcrumb), new Thickness(0));
76+
public static readonly BindableProperty BreadcrumbMarginProperty = BindableProperty.Create(nameof(BreadcrumbMargin), typeof(Thickness), typeof(Breadcrumb), new Thickness(0), BindingMode.OneTime);
7777

7878
public Thickness BreadcrumbMargin
7979
{
@@ -82,7 +82,7 @@ public Thickness BreadcrumbMargin
8282
}
8383

8484
// BreadcrumbBackgroundColor
85-
public static readonly BindableProperty BreadcrumbBackgroundColorProperty = BindableProperty.Create(nameof(BreadcrumbBackgroundColor), typeof(Color), typeof(Breadcrumb), Colors.Transparent);
85+
public static readonly BindableProperty BreadcrumbBackgroundColorProperty = BindableProperty.Create(nameof(BreadcrumbBackgroundColor), typeof(Color), typeof(Breadcrumb), Colors.Transparent, BindingMode.OneTime);
8686

8787
public Color BreadcrumbBackgroundColor
8888
{
@@ -91,7 +91,7 @@ public Color BreadcrumbBackgroundColor
9191
}
9292

9393
// LastBreadcrumbTextColor
94-
public static readonly BindableProperty LastBreadcrumbTextColorProperty = BindableProperty.Create(nameof(LastBreadcrumbTextColor), typeof(Color), typeof(Breadcrumb), Colors.Black);
94+
public static readonly BindableProperty LastBreadcrumbTextColorProperty = BindableProperty.Create(nameof(LastBreadcrumbTextColor), typeof(Color), typeof(Breadcrumb), Colors.Black, BindingMode.OneTime);
9595

9696
public Color LastBreadcrumbTextColor
9797
{
@@ -100,7 +100,7 @@ public Color LastBreadcrumbTextColor
100100
}
101101

102102
// LastBreadcrumbCornerRadius
103-
public static readonly BindableProperty LastBreadcrumbCornerRadiusProperty = BindableProperty.Create(nameof(LastBreadcrumbCornerRadius), typeof(float), typeof(Breadcrumb), 10f);
103+
public static readonly BindableProperty LastBreadcrumbCornerRadiusProperty = BindableProperty.Create(nameof(LastBreadcrumbCornerRadius), typeof(float), typeof(Breadcrumb), 10f, BindingMode.OneTime);
104104

105105
public float LastBreadcrumbCornerRadius
106106
{
@@ -109,7 +109,7 @@ public float LastBreadcrumbCornerRadius
109109
}
110110

111111
// LastBreadcrumbBackgroundColor
112-
public static readonly BindableProperty LastBreadcrumbBackgroundColorProperty = BindableProperty.Create(nameof(LastBreadcrumbBackgroundColor), typeof(Color), typeof(Breadcrumb), Colors.Transparent);
112+
public static readonly BindableProperty LastBreadcrumbBackgroundColorProperty = BindableProperty.Create(nameof(LastBreadcrumbBackgroundColor), typeof(Color), typeof(Breadcrumb), Colors.Transparent, BindingMode.OneTime);
113113

114114
public Color LastBreadcrumbBackgroundColor
115115
{
@@ -118,7 +118,7 @@ public Color LastBreadcrumbBackgroundColor
118118
}
119119

120120
// AnimationSpeed
121-
public static readonly BindableProperty AnimationSpeedProperty = BindableProperty.Create(nameof(AnimationSpeed), typeof(uint), typeof(Breadcrumb), (uint)800);
121+
public static readonly BindableProperty AnimationSpeedProperty = BindableProperty.Create(nameof(AnimationSpeed), typeof(uint), typeof(Breadcrumb), (uint)800, BindingMode.OneTime);
122122

123123
public uint AnimationSpeed
124124
{
@@ -127,7 +127,7 @@ public uint AnimationSpeed
127127
}
128128

129129
// IsNavigationEnabled
130-
public static readonly BindableProperty IsNavigationEnabledProperty = BindableProperty.Create(nameof(IsNavigationEnabled), typeof(bool), typeof(Breadcrumb), true);
130+
public static readonly BindableProperty IsNavigationEnabledProperty = BindableProperty.Create(nameof(IsNavigationEnabled), typeof(bool), typeof(Breadcrumb), true, BindingMode.OneTime);
131131

132132
public bool IsNavigationEnabled
133133
{
@@ -142,7 +142,7 @@ public Breadcrumb()
142142
InitializeComponent();
143143
}
144144

145-
async void BreadCrumbContainer_Loaded(object sender, EventArgs e)
145+
async void BreadCrumbContainer_Loaded(object? sender, EventArgs e)
146146
{
147147
BreadCrumbContainer.Loaded -= BreadCrumbContainer_Loaded;
148148

@@ -208,9 +208,6 @@ async void BreadCrumbContainer_Loaded(object sender, EventArgs e)
208208
/// <summary>
209209
/// Creates a new Breadcrumb object
210210
/// </summary>
211-
/// <param name="page"></param>
212-
/// <param name="isLast"></param>
213-
/// <param name="isFirst"></param>
214211
Border BreadcrumbCreator(Page page, bool isLast, bool isFirst)
215212
{
216213
// Create border control for the breadcrumb
@@ -222,13 +219,12 @@ Border BreadcrumbCreator(Page page, bool isLast, bool isFirst)
222219
}
223220
: new Border();
224221

225-
container.BackgroundColor = Colors.Transparent;
226222
container.StrokeShape = new RoundRectangle
227223
{
228224
CornerRadius = isLast ? LastBreadcrumbCornerRadius : CornerRadius
229225
};
230226
container.Padding = 10;
231-
container.Stroke = Colors.Transparent;
227+
container.StrokeThickness = 0;
232228
container.Margin = BreadcrumbMargin;
233229
container.VerticalOptions = LayoutOptions.Center;
234230
container.SetBinding(BackgroundColorProperty, new Binding(isLast ? nameof(LastBreadcrumbBackgroundColor) : nameof(BreadcrumbBackgroundColor), source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(Breadcrumb))));
@@ -239,18 +235,15 @@ Border BreadcrumbCreator(Page page, bool isLast, bool isFirst)
239235
{
240236
container.Content = new Image
241237
{
242-
Source = FirstBreadcrumb,
243-
VerticalOptions = LayoutOptions.Center
238+
Source = FirstBreadcrumb
244239
};
245240
}
246241
else
247242
{
248243
Label breadcrumbText = new()
249244
{
250245
Text = page.Title,
251-
FontSize = FontSize,
252-
VerticalOptions = LayoutOptions.Center,
253-
VerticalTextAlignment = TextAlignment.Center
246+
FontSize = FontSize
254247
};
255248
breadcrumbText.SetBinding(Label.TextColorProperty, new Binding(isLast ? nameof(LastBreadcrumbTextColor) : nameof(TextColor), source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, typeof(Breadcrumb))));
256249
AutomationProperties.SetIsInAccessibleTree(breadcrumbText, false);
@@ -264,8 +257,6 @@ Border BreadcrumbCreator(Page page, bool isLast, bool isFirst)
264257
/// <summary>
265258
/// Animates item added to stack
266259
/// </summary>
267-
/// <param name="sender"></param>
268-
/// <param name="e"></param>
269260
async void AnimatedStack_ChildAdded(object? sender, ElementEventArgs e)
270261
{
271262
// iOS scroll to end fix
@@ -276,10 +267,10 @@ async void AnimatedStack_ChildAdded(object? sender, ElementEventArgs e)
276267

277268
Animation lastBreadcrumbAnimation = new()
278269
{
279-
{ 0, 1, new Animation(_ => ((View)BreadCrumbContainer.Children.Last()).TranslationX = _, Application.Current?.MainPage?.Width ?? 0, 0, Easing.Linear) }
270+
{ 0, 1, new Animation(_ => ((View)BreadCrumbContainer.Children[^1]).TranslationX = _, Application.Current?.MainPage?.Width ?? 0, 0, Easing.Linear) }
280271
};
281272

282-
Point point = BreadCrumbsScrollView.GetScrollPositionForElement((View)BreadCrumbContainer.Children.Last(), ScrollToPosition.End);
273+
Point point = BreadCrumbsScrollView.GetScrollPositionForElement((View)BreadCrumbContainer.Children[^1], ScrollToPosition.End);
283274
lastBreadcrumbAnimation.Add(0, 1, new Animation(_ => BreadCrumbsScrollView.ScrollToAsync((View?)BreadCrumbContainer.Children.LastOrDefault(), ScrollToPosition.MakeVisible, true), BreadCrumbsScrollView.X, point.X - 6));
284275

285276
lastBreadcrumbAnimation.Commit(this, nameof(lastBreadcrumbAnimation), 16, AnimationSpeed);
@@ -288,7 +279,6 @@ async void AnimatedStack_ChildAdded(object? sender, ElementEventArgs e)
288279
/// <summary>
289280
/// Navigates the user back to chosen selectedPage in the Navigation stack
290281
/// </summary>
291-
/// <param name="selectedPage"></param>
292282
async Task GoBack(Page selectedPage)
293283
{
294284
// Check if selectedPage is still in Navigation Stack

0 commit comments

Comments
 (0)