Skip to content

Commit 6a1ff11

Browse files
authored
Merge pull request dotnet-architecture#270 from dotnet-architecture/xamarin
Increased app startup time of Xamarin client.
2 parents 82cc1f0 + de8c903 commit 6a1ff11

23 files changed

Lines changed: 601 additions & 231 deletions

File tree

src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml

Lines changed: 125 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<Application xmlns="http://xamarin.com/schemas/2014/forms"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4-
xmlns:light="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Light"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
54
xmlns:converters="clr-namespace:eShopOnContainers.Core.Converters;assembly=eShopOnContainers.Core"
65
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
76
x:Class="eShopOnContainers.App">
87
<Application.Resources>
9-
<ResourceDictionary MergedWith="light:LightThemeResources">
8+
<ResourceDictionary>
109

1110
<!-- COLORS -->
1211
<Color x:Key="WhiteColor">#ffffff</Color>
@@ -18,6 +17,69 @@
1817
<Color x:Key="DarkGreenColor">#00857D</Color>
1918
<Color x:Key="GrayColor">#e2e2e2</Color>
2019
<Color x:Key="ErrorColor">#ff5252</Color>
20+
<Color x:Key="TextColor">#757575</Color>
21+
<Color x:Key="InverseTextColor">#FFFFFF</Color>
22+
<Color x:Key="LightTextColor">#979797</Color>
23+
<Color x:Key="iOSDefaultTintColor">#007aff</Color>
24+
<Color x:Key="SeparatorLineColor">#CCCCCC</Color>
25+
<Color x:Key="AndroidDefaultButtonClassBackgroundColor">#C9C9C9</Color>
26+
<Color x:Key="iOSDefaultButtonClassBackgroundColor">Transparent</Color>
27+
<Color x:Key="AndroidDefaultButtonClassBorderColor">Transparent</Color>
28+
<Color x:Key="iOSDefaultButtonClassBorderColor">#007aff</Color>
29+
<Color x:Key="AndroidDefaultButtonClassTextColor">#FFFFFF</Color>
30+
<Color x:Key="iOSDefaultButtonClassTextColor">#007aff</Color>
31+
<Color x:Key="AndroidEntryBackgroundColor">Transparent</Color>
32+
<Color x:Key="iOSEntryBackgroundColor">#FFFFFF</Color>
33+
<Color x:Key="AndroidDefaultAccentColorColor">#1FAECE</Color>
34+
<Color x:Key="AndroidListViewBackgroundColor">Transparent</Color>
35+
<Color x:Key="iOSListViewBackgroundColor">Transparent</Color>
36+
37+
<OnPlatform
38+
x:TypeArguments="Color"
39+
x:Key="ActivityIndicatorColor"
40+
iOS="{ StaticResource iOSDefaultTintColor }" />
41+
42+
<OnPlatform
43+
x:TypeArguments="Color"
44+
x:Key="DefaultButtonClassBackgroundColor"
45+
Android="{ StaticResource AndroidDefaultButtonClassBackgroundColor }"
46+
iOS="{ StaticResource iOSDefaultButtonClassBackgroundColor }" />
47+
48+
<OnPlatform
49+
x:TypeArguments="Color"
50+
x:Key="DefaultButtonClassBorderColor"
51+
Android="{ StaticResource AndroidDefaultButtonClassBorderColor }"
52+
iOS="{ StaticResource iOSDefaultButtonClassBorderColor }" />
53+
54+
<OnPlatform
55+
x:TypeArguments="Color"
56+
x:Key="DefaultButtonClassTextColor"
57+
Android="{ StaticResource AndroidDefaultButtonClassTextColor }"
58+
iOS="{ StaticResource iOSDefaultButtonClassTextColor }" />
59+
60+
<OnPlatform
61+
x:TypeArguments="Color"
62+
x:Key="EntryBackgroundColor"
63+
Android="{ StaticResource AndroidEntryBackgroundColor }"
64+
iOS="{ StaticResource iOSEntryBackgroundColor }" />
65+
66+
<OnPlatform
67+
x:TypeArguments="Color"
68+
x:Key="ThemeListViewBackgroundColor"
69+
Android="{ StaticResource AndroidListViewBackgroundColor }"
70+
iOS="{ StaticResource iOSListViewBackgroundColor }" />
71+
72+
<!-- SIZES -->
73+
<OnPlatform
74+
x:TypeArguments="x:Double"
75+
x:Key="BaseButtonBorderRadius"
76+
iOS="6" />
77+
78+
<OnPlatform
79+
x:TypeArguments="x:Double"
80+
x:Key="BaseButtonBorderWidth"
81+
Android="0"
82+
iOS="0" />
2183

2284
<!-- FONTS -->
2385
<OnPlatform
@@ -41,7 +103,18 @@
41103
Android="SourceSansPro-Regular.ttf#Source Sans Pro"
42104
WinPhone="Assets/Fonts/SourceSansPro-Regular.ttf#Source Sans Pro"/>
43105

44-
<!-- FONT SIZES -->
106+
<OnPlatform
107+
x:TypeArguments="x:Double"
108+
x:Key="BaseButtonFontSize"
109+
Android="16"
110+
iOS="18" />
111+
112+
<OnPlatform
113+
x:TypeArguments="x:Double"
114+
x:Key="BaseFontSize"
115+
Android="15"
116+
iOS="16" />
117+
45118
<OnPlatform
46119
x:Key="LittleSize"
47120
x:TypeArguments="x:Double"
@@ -97,6 +170,12 @@
97170
iOS="32"
98171
Android="48"
99172
WinPhone="48"/>
173+
174+
<OnPlatform
175+
x:TypeArguments="FontAttributes"
176+
x:Key="BaseButtonFontAttributes"
177+
Android="None"
178+
iOS="Bold" />
100179

101180
<!-- CONVERTERS -->
102181
<converters:CountToBoolConverter x:Key="CountToBoolConverter" />
@@ -108,7 +187,7 @@
108187
<converters:ItemsToHeightConverter x:Key="ItemsToHeightConverter" />
109188
<converters:ToUpperConverter x:Key="ToUpperConverter" />
110189

111-
<!-- STYLES -->
190+
<!-- EXPLICIT STYLES -->
112191
<Style x:Key="ValidationErrorLabelStyle"
113192
TargetType="{x:Type Label}">
114193
<Setter Property="TextColor"
@@ -180,6 +259,47 @@
180259
</Trigger>
181260
</Style.Triggers>
182261
</Style>
262+
263+
<!-- IMPLICIT STYLES -->
264+
<Style TargetType="Button" ApplyToDerivedTypes="True" CanCascade="True">
265+
<Setter Property="FontSize" Value="{ StaticResource BaseButtonFontSize }" />
266+
<Setter Property="FontAttributes" Value="{ StaticResource BaseButtonFontAttributes }" />
267+
<Setter Property="BorderRadius" Value="{ StaticResource BaseButtonBorderRadius }" />
268+
<Setter Property="BorderWidth" Value="{ StaticResource BaseButtonBorderWidth }" />
269+
<Setter Property="BackgroundColor" Value="{ StaticResource DefaultButtonClassBackgroundColor }" />
270+
<Setter Property="BorderColor" Value="{ StaticResource DefaultButtonClassBorderColor }" />
271+
<Setter Property="TextColor" Value="{ StaticResource DefaultButtonClassTextColor }" />
272+
</Style>
273+
274+
<Style TargetType="Label" ApplyToDerivedTypes="True" CanCascade="True">
275+
<Setter Property="FontSize" Value="{ StaticResource BaseFontSize }" />
276+
</Style>
277+
278+
<Style TargetType="Entry" ApplyToDerivedTypes="True" CanCascade="True">
279+
<Setter Property="TextColor" Value="{ StaticResource TextColor }" />
280+
<Setter Property="PlaceholderColor" Value="{ StaticResource LightTextColor }" />
281+
<Setter Property="BackgroundColor" Value="{ StaticResource EntryBackgroundColor }" />
282+
</Style>
283+
284+
<Style TargetType="ImageCell" ApplyToDerivedTypes="True" CanCascade="True">
285+
<Setter Property="TextColor" Value="{ StaticResource InverseTextColor }" />
286+
<Setter Property="DetailColor" Value="{ StaticResource AccentColor }" />
287+
</Style>
288+
289+
<Style TargetType="TextCell" ApplyToDerivedTypes="True" CanCascade="True">
290+
<Setter Property="TextColor" Value="{ StaticResource InverseTextColor }" />
291+
<Setter Property="DetailColor" Value="{ StaticResource AccentColor }" />
292+
</Style>
293+
294+
<Style TargetType="ListView" ApplyToDerivedTypes="True" CanCascade="True">
295+
<Setter Property="BackgroundColor" Value="{ StaticResource ThemeListViewBackgroundColor }" />
296+
<Setter Property="SeparatorColor" Value="{ StaticResource SeparatorLineColor }" />
297+
<Setter Property="SeparatorVisibility" Value="Default" />
298+
</Style>
299+
300+
<Style TargetType="ActivityIndicator" ApplyToDerivedTypes="True" CanCascade="True">
301+
<Setter Property="Color" Value="{ StaticResource ActivityIndicatorColor }" />
302+
</Style>
183303

184304
<Style TargetType="NavigationPage">
185305
<Setter Property="BarBackgroundColor" Value="{StaticResource GreenColor}"/>

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Controls/AddBasketButton.xaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<ContentView
33
xmlns="http://xamarin.com/schemas/2014/forms"
44
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
xmlns:effects="clr-namespace:eShopOnContainers.Core.Effects"
56
x:Class="eShopOnContainers.Core.Controls.AddBasketButton">
67
<ContentView.Resources>
78
<ResourceDictionary>
89

10+
<Style TargetType="BoxView" Class="Circle">
11+
<Setter Property="BackgroundColor" Value="{ StaticResource AccentColor }" />
12+
<Setter Property="WidthRequest" Value="34" />
13+
<Setter Property="HeightRequest" Value="34" />
14+
<Setter Property="HorizontalOptions" Value="Start" />
15+
<Setter Property="effects:ThemeEffects.Circle" Value="True" />
16+
</Style>
17+
918
<Style x:Key="AddBackgroundImageStyle"
1019
TargetType="{x:Type Image}">
1120
<Setter Property="HorizontalOptions"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Xamarin.Forms;
4+
5+
namespace eShopOnContainers.Core.Effects
6+
{
7+
public static class ThemeEffects
8+
{
9+
public static readonly BindableProperty CircleProperty =
10+
BindableProperty.CreateAttached("Circle", typeof(bool), typeof(ThemeEffects), false, propertyChanged: OnChanged<CircleEffect, bool>);
11+
12+
public static bool GetCircle(BindableObject view)
13+
{
14+
return (bool)view.GetValue(CircleProperty);
15+
}
16+
17+
public static void SetCircle(BindableObject view, bool circle)
18+
{
19+
view.SetValue(CircleProperty, circle);
20+
}
21+
22+
23+
private static void OnChanged<TEffect, TProp>(BindableObject bindable, object oldValue, object newValue)
24+
where TEffect : Effect, new()
25+
{
26+
var view = bindable as View;
27+
if (view == null)
28+
{
29+
return;
30+
}
31+
32+
if (EqualityComparer<TProp>.Equals(newValue, default(TProp)))
33+
{
34+
var toRemove = view.Effects.FirstOrDefault(e => e is TEffect);
35+
if (toRemove != null)
36+
{
37+
view.Effects.Remove(toRemove);
38+
}
39+
}
40+
else
41+
{
42+
view.Effects.Add(new TEffect());
43+
}
44+
}
45+
46+
private class CircleEffect : RoutingEffect
47+
{
48+
public CircleEffect()
49+
: base("eShopOnContainers.CircleEffect")
50+
{
51+
}
52+
}
53+
}
54+
}

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/LoginView.xaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@
151151
<Label
152152
Text="REGISTER"
153153
TextColor="Gray"/>
154-
<Grid.GestureRecognizers>
155-
<TapGestureRecognizer
156-
Command="{Binding RegisterCommand}"
157-
NumberOfTapsRequired="1" />
158-
</Grid.GestureRecognizers>
159154
</Grid>
160155
<StackLayout
161156
Grid.Column="2"

src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
<Compile Include="Effects\EntryLineColorEffect.cs" />
193193
<Compile Include="Behaviors\LineColorBehavior.cs" />
194194
<Compile Include="Models\Token\UserToken.cs" />
195+
<Compile Include="Effects\ThemeEffects.cs" />
195196
</ItemGroup>
196197
<ItemGroup>
197198
<None Include="app.config" />

src/Mobile/eShopOnContainers/eShopOnContainers.Core/project.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
"Xam.Plugins.Settings": "2.6.0.12-beta",
1717
"Xamarin.FFImageLoading": "2.2.9",
1818
"Xamarin.FFImageLoading.Forms": "2.2.9",
19-
"Xamarin.Forms": "2.3.4.231",
20-
"Xamarin.Forms.Pages": "2.3.4.231",
21-
"Xamarin.Forms.Theme.Base": "1.0.0.43-pre1",
22-
"Xamarin.Forms.Theme.Light": "1.0.0.43-pre1"
19+
"Xamarin.Forms": "2.3.4.231"
2320
},
2421
"frameworks": {
2522
".NETPortable,Version=v4.5,Profile=Profile111": {}

src/Mobile/eShopOnContainers/eShopOnContainers.Droid/Activities/MainActivity.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace eShopOnContainers.Droid.Activities
1515
{
1616
[Activity(
17-
Label = "eShopOnContainers",
17+
Label = "eShopOnContainers",
1818
Icon = "@drawable/icon",
1919
Theme = "@style/MainTheme",
2020
MainLauncher = true,
@@ -38,9 +38,6 @@ protected override void OnCreate(Bundle bundle)
3838
CachedImageRenderer.Init();
3939
LoadApplication(new App());
4040

41-
var x = typeof(Xamarin.Forms.Themes.LightThemeResources);
42-
x = typeof(Xamarin.Forms.Themes.Android.UnderlineEffect);
43-
4441
Window window = this.Window;
4542
window.ClearFlags(WindowManagerFlags.TranslucentStatus);
4643
window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Xamarin.Forms.Platform.Android;
2+
3+
namespace eShopOnContainers.Droid.Effects
4+
{
5+
public abstract class BaseContainerEffect : PlatformEffect
6+
{
7+
private bool _unloaded;
8+
private bool _attached;
9+
10+
protected bool Attached
11+
{
12+
get { return _attached; }
13+
}
14+
15+
protected virtual bool CanBeApplied()
16+
{
17+
return true;
18+
}
19+
20+
protected virtual void OnAttachedInternal()
21+
{
22+
}
23+
24+
protected virtual void OnDetachedInternal()
25+
{
26+
}
27+
28+
protected sealed override void OnAttached()
29+
{
30+
if (CanBeApplied())
31+
{
32+
_attached = true;
33+
34+
Container.ViewDetachedFromWindow -= ContainerViewDetachedFromWindow;
35+
Container.ViewDetachedFromWindow += ContainerViewDetachedFromWindow;
36+
Container.ViewAttachedToWindow -= ContainerViewAttachedToWindow;
37+
Container.ViewAttachedToWindow += ContainerViewAttachedToWindow;
38+
39+
OnAttachedInternal();
40+
}
41+
}
42+
43+
protected sealed override void OnDetached()
44+
{
45+
if (_attached && !_unloaded)
46+
{
47+
_attached = false;
48+
49+
Container.ViewDetachedFromWindow -= ContainerViewDetachedFromWindow;
50+
Container.ViewAttachedToWindow -= ContainerViewAttachedToWindow;
51+
52+
OnDetachedInternal();
53+
}
54+
}
55+
56+
private void ContainerViewDetachedFromWindow(object sender, global::Android.Views.View.ViewDetachedFromWindowEventArgs e)
57+
{
58+
_unloaded = true;
59+
}
60+
61+
private void ContainerViewAttachedToWindow(object sender, global::Android.Views.View.ViewAttachedToWindowEventArgs e)
62+
{
63+
_unloaded = false;
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)