Skip to content

Commit 12f02fa

Browse files
committed
Merge branch 'main' into fix-21814
2 parents 1ec083a + 67d52da commit 12f02fa

File tree

7 files changed

+216
-0
lines changed

7 files changed

+216
-0
lines changed
22.9 KB
Loading
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
using System.Globalization;
2+
3+
namespace Controls.TestCases.HostApp.Issues;
4+
5+
[Issue(IssueTracker.Github, 30728, "Android image sources with the same source ref fail to load", PlatformAffected.Android)]
6+
public class Issue30728 : Shell
7+
{
8+
public Issue30728()
9+
{
10+
var tabs = new TabBar();
11+
{
12+
var content = new ShellContent
13+
{
14+
ContentTemplate = new DataTemplate(() => new Issue30728Page()),
15+
Title = "Tab 1",
16+
Route = "t1"
17+
};
18+
Issue30728TabBarExtras.SetTabIcon(content, "\xf133");
19+
tabs.Items.Add(content);
20+
}
21+
22+
{
23+
var content = new ShellContent
24+
{
25+
ContentTemplate = new DataTemplate(() => new Issue30728Page()),
26+
Title = "Tab 2",
27+
Route = "t2"
28+
};
29+
Issue30728TabBarExtras.SetTabIcon(content, "\xf111");
30+
tabs.Items.Add(content);
31+
}
32+
33+
{
34+
var content = new ShellContent
35+
{
36+
ContentTemplate = new DataTemplate(() => new Issue30728Page()),
37+
Title = "Tab 3",
38+
Route = "t3"
39+
};
40+
Issue30728TabBarExtras.SetTabIcon(content, "\xf192");
41+
tabs.Items.Add(content);
42+
}
43+
44+
{
45+
var content = new ShellContent
46+
{
47+
ContentTemplate = new DataTemplate(() => new Issue30728Page()),
48+
Title = "Tab 4",
49+
Route = "t4"
50+
};
51+
Issue30728TabBarExtras.SetTabIcon(content, "\xf025");
52+
tabs.Items.Add(content);
53+
}
54+
55+
56+
Items.Add(tabs);
57+
}
58+
}
59+
60+
class Issue30728Page : ContentPage
61+
{
62+
public Issue30728Page()
63+
{
64+
Shell.SetTabBarIsVisible(this, false);
65+
66+
var content = new Grid
67+
{
68+
new Issue30728FakeShellNavigationBar
69+
{
70+
VerticalOptions = LayoutOptions.End,
71+
}
72+
};
73+
74+
Content = content;
75+
}
76+
}
77+
78+
file static class Issue30728TabBarExtras
79+
{
80+
public static readonly BindableProperty TabIconProperty = BindableProperty.CreateAttached(
81+
"TabIcon",
82+
typeof(string),
83+
typeof(Issue30728TabBarExtras),
84+
null,
85+
propertyChanged: OnTabIconChanged
86+
);
87+
88+
public static string GetTabIcon(BindableObject bindable) => (string)bindable.GetValue(TabIconProperty);
89+
90+
public static void SetTabIcon(BindableObject bindable, string value) => bindable.SetValue(TabIconProperty, value);
91+
92+
private static void OnTabIconChanged(BindableObject bindable, object oldvalue, object newvalue)
93+
{
94+
var targetObject = (BaseShellItem)bindable;
95+
var icon = (string)newvalue;
96+
var inactiveIcon = new FontImageSource { Glyph = icon, FontFamily = "FA", Color = Colors.Coral };
97+
var activeIcon = new FontImageSource { Glyph = icon, FontFamily = "FA", Color = Colors.Red };
98+
99+
var binding = new Binding
100+
{
101+
Source = targetObject,
102+
Path = nameof(BaseShellItem.IsChecked),
103+
Converter = new Issue30728BoolToImageSourceConverter
104+
{
105+
TrueObject = activeIcon,
106+
FalseObject = inactiveIcon
107+
}
108+
};
109+
110+
targetObject.SetBinding(BaseShellItem.IconProperty, binding);
111+
}
112+
}
113+
114+
file class Issue30728FakeShellNavigationBar : Grid
115+
{
116+
public Issue30728FakeShellNavigationBar()
117+
{
118+
RowDefinitions = [new RowDefinition(GridLength.Auto)];
119+
BackgroundColor = Colors.WhiteSmoke;
120+
CreateMenu();
121+
}
122+
123+
private void CreateMenu()
124+
{
125+
var tabBar = Shell.Current.Items.First();
126+
var contents = tabBar.Items.SelectMany(section => section.Items).Distinct().ToList();
127+
var columns = new ColumnDefinitionCollection();
128+
var i = 0;
129+
130+
foreach (var content in contents)
131+
{
132+
columns.Add(new ColumnDefinition(GridLength.Star));
133+
var route = $"//{content.Route}";
134+
135+
var layout = new Grid
136+
{
137+
RowDefinitions =
138+
[
139+
new RowDefinition { Height = GridLength.Auto },
140+
new RowDefinition { Height = GridLength.Auto }
141+
],
142+
BindingContext = content
143+
};
144+
145+
var tapGestureRecognizer = new TapGestureRecognizer();
146+
tapGestureRecognizer.Tapped += (s, e) => Shell.Current.GoToAsync(route);
147+
layout.GestureRecognizers.Add(tapGestureRecognizer);
148+
layout.AutomationId = content.Route;
149+
150+
var icon = new Image();
151+
icon.SetBinding(Image.SourceProperty, nameof(ShellContent.Icon));
152+
icon.HorizontalOptions = LayoutOptions.Center;
153+
154+
icon.Margin = new Thickness(0, 2);
155+
icon.HeightRequest = 24;
156+
icon.WidthRequest = 24;
157+
158+
var label = new Label { HorizontalTextAlignment = TextAlignment.Center, TextColor = Colors.Black };
159+
label.SetBinding(Label.TextProperty, nameof(ShellContent.Title));
160+
161+
layout.Add(icon);
162+
layout.Add(label, 0, 1);
163+
164+
this.Add(layout, i++);
165+
}
166+
167+
ColumnDefinitions = columns;
168+
}
169+
}
170+
171+
file class Issue30728BoolToImageSourceConverter : IValueConverter
172+
{
173+
public ImageSource TrueObject { get; set; }
174+
175+
public ImageSource FalseObject { get; set; }
176+
177+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
178+
{
179+
if (value is bool isChecked)
180+
{
181+
return isChecked ? TrueObject : FalseObject;
182+
}
183+
return null;
184+
}
185+
186+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotSupportedException();
187+
}
11 KB
Loading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue30728 : _IssuesUITest
8+
{
9+
public override string Issue => "Android image sources with the same source ref fail to load";
10+
11+
public Issue30728(TestDevice device)
12+
: base(device)
13+
{ }
14+
15+
[Test]
16+
[Category(UITestCategories.Shell)]
17+
public void VerifyTabBarIconIsLoaded()
18+
{
19+
App.WaitForElement("Tab 1");
20+
App.Tap("Tab 1");
21+
App.Tap("Tab 2");
22+
App.Tap("Tab 3");
23+
App.Tap("Tab 1");
24+
25+
VerifyScreenshot();
26+
}
27+
}
9.09 KB
Loading
30.8 KB
Loading

src/Core/src/Platform/ImageSourcePartLoader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public async Task UpdateImageSourceAsync()
8080
#elif ANDROID || TIZEN
8181
var result = await imageSource.UpdateSourceAsync(platformView, _imageSourceServiceProvider, Setter.SetImageSource, token)
8282
.ConfigureAwait(false);
83+
84+
SourceManager.CompleteLoad(result);
8385
#else
8486
await Task.CompletedTask;
8587
#endif

0 commit comments

Comments
 (0)