summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xamarin.Forms.Controls/App.cs330
-rw-r--r--Xamarin.Forms.Controls/AppLifeCycle.cs16
-rw-r--r--Xamarin.Forms.Controls/MainPageLifeCycleTests.cs75
-rw-r--r--Xamarin.Forms.Controls/NavReproApp.cs66
-rw-r--r--Xamarin.Forms.Controls/SimpleApp.cs42
-rw-r--r--Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj4
6 files changed, 257 insertions, 276 deletions
diff --git a/Xamarin.Forms.Controls/App.cs b/Xamarin.Forms.Controls/App.cs
index 975faf8..2556bc8 100644
--- a/Xamarin.Forms.Controls/App.cs
+++ b/Xamarin.Forms.Controls/App.cs
@@ -1,85 +1,54 @@
using System;
-using System.Collections;
using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
namespace Xamarin.Forms.Controls
{
- public class AppLifeCycle : Application
+ public class App : Application
{
- protected override void OnStart ()
- {
- base.OnStart ();
- }
+ public const string AppName = "XamarinFormsControls";
+ static string s_insightsKey;
+
+ // ReSharper disable once InconsistentNaming
+ public static int IOSVersion = -1;
- protected override void OnSleep ()
- {
- base.OnSleep ();
- }
+ public static List<string> AppearingMessages = new List<string>();
- protected override void OnResume ()
- {
- base.OnResume ();
- }
+ static Dictionary<string, string> s_config;
+ readonly ITestCloudService _testCloudService;
- public AppLifeCycle ()
+ public App()
{
- MainPage = new ContentPage {
- Content = new Label {
- Text = "Testing Lifecycle events"
- }
+ _testCloudService = DependencyService.Get<ITestCloudService>();
+ InitInsights();
+ // MainPage = new MainPageLifeCycleTests ();
+ MainPage = new MasterDetailPage
+ {
+ Master = new ContentPage { Title = "Master", BackgroundColor = Color.Red },
+ Detail = CoreGallery.GetMainPage()
};
}
- }
-
- public class SimpleApp : Application
- {
- Label label;
- public SimpleApp ()
+ public static Dictionary<string, string> Config
{
- label = new Label { VerticalOptions = LayoutOptions.CenterAndExpand };
+ get
+ {
+ if (s_config == null)
+ LoadConfig();
- if (Current.Properties.ContainsKey ("LabelText")) {
- label.Text = (string) Current.Properties["LabelText"] + " Restored!";
- Debug.WriteLine ("Initialized");
- } else {
- Current.Properties["LabelText"] = "Wowza";
- label.Text = (string) Current.Properties["LabelText"] + " Set!";
- Debug.WriteLine ("Saved");
+ return s_config;
}
-
- MainPage = new ContentPage {
- Content = new StackLayout {
- Children = {
- label
- }
- }
- };
-
- SerializeProperties ();
- }
-
- async void SerializeProperties ()
- {
- await Current.SavePropertiesAsync ();
}
- }
- public class App : Application
- {
- static string s_insightsKey;
public static string InsightsApiKey
{
get
{
if (s_insightsKey == null)
{
- var key = Config["InsightsApiKey"];
+ string key = Config["InsightsApiKey"];
s_insightsKey = string.IsNullOrEmpty(key) ? Insights.DebugModeKey : key;
}
@@ -87,249 +56,58 @@ namespace Xamarin.Forms.Controls
}
}
- public const string AppName = "XamarinFormsControls";
- public const string AppVersion = "1.4.3";
- public static int IOSVersion = -1;
- readonly ITestCloudService _testCloudService;
- // make sure serialized data is available here
-
- //protected override void OnStart ()
- //{
- // // called right after property store is populated
- // MainPage.BackgroundColor = Color.Green;
- // Current.Properties["TimesStarted"] = ((int)Current.Properties["TimesStarted"]) + 1;
- // ((MainPageLifeCycleTests)MainPage).UpdateLabels ();
- //}
-
- //protected override void OnResume ()
- //{
- // MainPage.BackgroundColor = Color.White;
- // Current.Properties["TimesResumed"] = ((int)Current.Properties["TimesResumed"]) + 1;
- // ((MainPageLifeCycleTests)MainPage).UpdateLabels ();
- //}
-
- //protected override void OnSleep ()
- //{
- // MainPage.BackgroundColor = Color.Red;
- // Current.Properties["TimesSlept"] = ((int)Current.Properties["TimesSlept"]) + 1;
- // ((MainPageLifeCycleTests)MainPage).UpdateLabels ();
- //}
- public static List<string> AppearingMessages = new List<string>();
-
public static ContentPage MenuPage { get; set; }
-
-
- public App ()
+ public void SetMainPage(Page rootPage)
{
- _testCloudService = DependencyService.Get<ITestCloudService> ();
- InitInsights ();
- // MainPage = new MainPageLifeCycleTests ();
- MainPage = new MasterDetailPage () {
- Master = new ContentPage { Title = "Master", BackgroundColor = Color.Red },
- Detail = CoreGallery.GetMainPage ()
- };
+ MainPage = rootPage;
}
- public void SetMainPage (Page rootPage)
+ static Assembly GetAssembly(out string assemblystring)
{
- MainPage = rootPage;
+ assemblystring = typeof (App).AssemblyQualifiedName.Split(',')[1].Trim();
+ var assemblyname = new AssemblyName(assemblystring);
+ return Assembly.Load(assemblyname);
}
- void InitInsights ()
+ void InitInsights()
{
- if (Insights.IsInitialized) {
+ if (Insights.IsInitialized)
+ {
Insights.ForceDataTransmission = true;
- if (_testCloudService != null && _testCloudService.IsOnTestCloud ())
- Insights.Identify (_testCloudService.GetTestCloudDevice (), "Name", _testCloudService.GetTestCloudDeviceName ());
+ if (_testCloudService != null && _testCloudService.IsOnTestCloud())
+ Insights.Identify(_testCloudService.GetTestCloudDevice(), "Name", _testCloudService.GetTestCloudDeviceName());
else
- Insights.Identify ("DemoUser", "Name", "Demo User");
- }
- }
-
- public static Assembly GetAssembly (out string assemblystring)
- {
- assemblystring = typeof(App).AssemblyQualifiedName.Split (',')[1].Trim ();
- var assemblyname = new AssemblyName (assemblystring);
- return Assembly.Load (assemblyname);
- }
-
- public static async Task<string> LoadResource (string filename)
- {
- string assemblystring;
- Assembly assembly = GetAssembly (out assemblystring);
-
- Stream stream = assembly.GetManifestResourceStream ($"{assemblystring}.{filename}");
- string text;
- using (var reader = new StreamReader (stream)) {
- text = await reader.ReadToEndAsync ();
+ Insights.Identify("DemoUser", "Name", "Demo User");
}
- return text;
}
- public static void LoadConfig ()
+ static void LoadConfig()
{
- s_config = new Dictionary<string, string> ();
-
- string keyData = LoadResource ("controlgallery.config").Result;
- string[] entries = keyData.Split ("\n\r".ToCharArray (), StringSplitOptions.RemoveEmptyEntries);
- foreach (string entry in entries) {
- string[] parts = entry.Split (':');
- if (parts.Length < 2) {
- continue;
- }
+ s_config = new Dictionary<string, string>();
- s_config.Add (parts[0].Trim (), parts[1].Trim ());
- }
- }
-
- static Dictionary<string, string> s_config;
-
- public static Dictionary<string, string> Config
- {
- get
+ string keyData = LoadResource("controlgallery.config").Result;
+ string[] entries = keyData.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+ foreach (string entry in entries)
{
- if (s_config == null) {
- LoadConfig ();
- }
-
- return s_config;
- }
- }
- }
-
- // Not quite sure how to turn this into a test case, effectively replace the normal Application with this to repro issues reported.
- // Full repro requires assignment to MainPage, hence the issue
- public class NavReproApp : Application
- {
- NavigationPage navPage1 = new NavigationPage ();
-
- public NavReproApp ()
- {
-
- var btn = new Button () { Text = "Start" };
-
- btn.Clicked += Btn_Clicked;
-
- navPage1.PushAsync (new ContentPage () { Content = btn });
-
- MainPage = navPage1;
-
- }
-
- async void Btn_Clicked (object sender, EventArgs e)
- {
- await navPage1.PushAsync (new ContentPage () { Content = new Label () { Text = "Page 2" } });
- await navPage1.PushAsync (new ContentPage () { Content = new Label () { Text = "Page 3" } });
-
-
- var navPage2 = new NavigationPage ();
-
- var btn = new Button () { Text = "Start Next" };
- btn.Clicked += Btn_Clicked1;
-
- await navPage2.PushAsync (new ContentPage () { Content = btn });
-
- MainPage = navPage2;
-
-
- }
-
- async void Btn_Clicked1 (object sender, EventArgs e)
- {
- MainPage = navPage1;
- await navPage1.PopAsync ();
-
-
- await navPage1.PushAsync (new ContentPage () { Content = new Label () { Text = "Page 3a" } });
- }
-
- protected override void OnStart ()
- {
- // Handle when your app starts
- }
-
- protected override void OnSleep ()
- {
- // Handle when your app sleeps
- }
-
- protected override void OnResume ()
- {
- // Handle when your app resumes
- }
- }
-
- public class MainPageLifeCycleTests : ContentPage
- {
- int numTimesStarted;
- int numTimesSlept;
- int numTimesResumed;
-
- StackLayout numTimesStartedLayout;
- StackLayout numTimesSleptLayout;
- StackLayout numTimesResumedLayout;
-
- public MainPageLifeCycleTests ()
- {
- object timesStarted;
- if (!Application.Current.Properties.TryGetValue ("TimesStarted", out timesStarted)) {
- Application.Current.Properties["TimesStarted"] = 0;
- }
- var numTimesStarted = (int)Application.Current.Properties["TimesStarted"];
-
-
- object timesSlept;
- if (!Application.Current.Properties.TryGetValue ("TimesSlept", out timesSlept)) {
- Application.Current.Properties["TimesSlept"] = 0;
- }
- var numTimesSlept = (int)Application.Current.Properties["TimesSlept"];
-
+ string[] parts = entry.Split(':');
+ if (parts.Length < 2)
+ continue;
- object timesResumed;
- if (!Application.Current.Properties.TryGetValue ("TimesResumed", out timesResumed)) {
- Application.Current.Properties["TimesResumed"] = 0;
+ s_config.Add(parts[0].Trim(), parts[1].Trim());
}
- var numTimesResumed = (int)Application.Current.Properties["TimesResumed"];
-
- numTimesStartedLayout = BuildLabelLayout ("TimesStarted", numTimesStarted);
- numTimesSleptLayout = BuildLabelLayout ("TimesSlept", numTimesSlept);
- numTimesResumedLayout = BuildLabelLayout ("TimesResumed", numTimesResumed);
-
- var layout = new StackLayout {
- Children = {
- numTimesStartedLayout,
- numTimesSleptLayout,
- numTimesResumedLayout
- }
- };
-
- Content = layout;
}
- StackLayout BuildLabelLayout (string title, int property)
+ static async Task<string> LoadResource(string filename)
{
- var labelTitle = new Label {
- Text = title
- };
-
- var valueLabel = new Label {
- Text = property.ToString ()
- };
-
- return new StackLayout {
- Children = {
- labelTitle,
- valueLabel
- }
- };
- }
+ string assemblystring;
+ Assembly assembly = GetAssembly(out assemblystring);
- public void UpdateLabels ()
- {
- ((Label)numTimesStartedLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesStarted"]).ToString ();
- ((Label)numTimesSleptLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesSlept"]).ToString ();
- ((Label)numTimesResumedLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesResumed"]).ToString ();
+ Stream stream = assembly.GetManifestResourceStream($"{assemblystring}.{filename}");
+ string text;
+ using (var reader = new StreamReader(stream))
+ text = await reader.ReadToEndAsync();
+ return text;
}
}
-}
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls/AppLifeCycle.cs b/Xamarin.Forms.Controls/AppLifeCycle.cs
new file mode 100644
index 0000000..b32939e
--- /dev/null
+++ b/Xamarin.Forms.Controls/AppLifeCycle.cs
@@ -0,0 +1,16 @@
+namespace Xamarin.Forms.Controls
+{
+ public class AppLifeCycle : Application
+ {
+ public AppLifeCycle()
+ {
+ MainPage = new ContentPage
+ {
+ Content = new Label
+ {
+ Text = "Testing Lifecycle events"
+ }
+ };
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls/MainPageLifeCycleTests.cs b/Xamarin.Forms.Controls/MainPageLifeCycleTests.cs
new file mode 100644
index 0000000..5d14fca
--- /dev/null
+++ b/Xamarin.Forms.Controls/MainPageLifeCycleTests.cs
@@ -0,0 +1,75 @@
+namespace Xamarin.Forms.Controls
+{
+ public class MainPageLifeCycleTests : ContentPage
+ {
+ int _numTimesStarted;
+ int _numTimesSlept;
+ int _numTimesResumed;
+
+ readonly StackLayout _numTimesStartedLayout;
+ readonly StackLayout _numTimesSleptLayout;
+ readonly StackLayout _numTimesResumedLayout;
+
+ public MainPageLifeCycleTests ()
+ {
+ object timesStarted;
+ if (!Application.Current.Properties.TryGetValue ("TimesStarted", out timesStarted)) {
+ Application.Current.Properties["TimesStarted"] = 0;
+ }
+ var numTimesStarted = (int)Application.Current.Properties["TimesStarted"];
+
+
+ object timesSlept;
+ if (!Application.Current.Properties.TryGetValue ("TimesSlept", out timesSlept)) {
+ Application.Current.Properties["TimesSlept"] = 0;
+ }
+ var numTimesSlept = (int)Application.Current.Properties["TimesSlept"];
+
+
+ object timesResumed;
+ if (!Application.Current.Properties.TryGetValue ("TimesResumed", out timesResumed)) {
+ Application.Current.Properties["TimesResumed"] = 0;
+ }
+ var numTimesResumed = (int)Application.Current.Properties["TimesResumed"];
+
+ _numTimesStartedLayout = BuildLabelLayout ("TimesStarted", numTimesStarted);
+ _numTimesSleptLayout = BuildLabelLayout ("TimesSlept", numTimesSlept);
+ _numTimesResumedLayout = BuildLabelLayout ("TimesResumed", numTimesResumed);
+
+ var layout = new StackLayout {
+ Children = {
+ _numTimesStartedLayout,
+ _numTimesSleptLayout,
+ _numTimesResumedLayout
+ }
+ };
+
+ Content = layout;
+ }
+
+ StackLayout BuildLabelLayout (string title, int property)
+ {
+ var labelTitle = new Label {
+ Text = title
+ };
+
+ var valueLabel = new Label {
+ Text = property.ToString ()
+ };
+
+ return new StackLayout {
+ Children = {
+ labelTitle,
+ valueLabel
+ }
+ };
+ }
+
+ public void UpdateLabels ()
+ {
+ ((Label)_numTimesStartedLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesStarted"]).ToString ();
+ ((Label)_numTimesSleptLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesSlept"]).ToString ();
+ ((Label)_numTimesResumedLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesResumed"]).ToString ();
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls/NavReproApp.cs b/Xamarin.Forms.Controls/NavReproApp.cs
new file mode 100644
index 0000000..1c55d0b
--- /dev/null
+++ b/Xamarin.Forms.Controls/NavReproApp.cs
@@ -0,0 +1,66 @@
+using System;
+
+namespace Xamarin.Forms.Controls
+{
+ // Not quite sure how to turn this into a test case, effectively replace the normal Application with this to repro issues reported.
+ // Full repro requires assignment to MainPage, hence the issue
+ public class NavReproApp : Application
+ {
+ NavigationPage navPage1 = new NavigationPage ();
+
+ public NavReproApp ()
+ {
+
+ var btn = new Button () { Text = "Start" };
+
+ btn.Clicked += Btn_Clicked;
+
+ navPage1.PushAsync (new ContentPage () { Content = btn });
+
+ MainPage = navPage1;
+
+ }
+
+ async void Btn_Clicked (object sender, EventArgs e)
+ {
+ await navPage1.PushAsync (new ContentPage () { Content = new Label () { Text = "Page 2" } });
+ await navPage1.PushAsync (new ContentPage () { Content = new Label () { Text = "Page 3" } });
+
+
+ var navPage2 = new NavigationPage ();
+
+ var btn = new Button () { Text = "Start Next" };
+ btn.Clicked += Btn_Clicked1;
+
+ await navPage2.PushAsync (new ContentPage () { Content = btn });
+
+ MainPage = navPage2;
+
+
+ }
+
+ async void Btn_Clicked1 (object sender, EventArgs e)
+ {
+ MainPage = navPage1;
+ await navPage1.PopAsync ();
+
+
+ await navPage1.PushAsync (new ContentPage () { Content = new Label () { Text = "Page 3a" } });
+ }
+
+ protected override void OnStart ()
+ {
+ // Handle when your app starts
+ }
+
+ protected override void OnSleep ()
+ {
+ // Handle when your app sleeps
+ }
+
+ protected override void OnResume ()
+ {
+ // Handle when your app resumes
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls/SimpleApp.cs b/Xamarin.Forms.Controls/SimpleApp.cs
new file mode 100644
index 0000000..aab454f
--- /dev/null
+++ b/Xamarin.Forms.Controls/SimpleApp.cs
@@ -0,0 +1,42 @@
+using System.Diagnostics;
+
+namespace Xamarin.Forms.Controls
+{
+ public class SimpleApp : Application
+ {
+ public SimpleApp()
+ {
+ var label = new Label { VerticalOptions = LayoutOptions.CenterAndExpand };
+
+ if (Current.Properties.ContainsKey("LabelText"))
+ {
+ label.Text = (string)Current.Properties["LabelText"] + " Restored!";
+ Debug.WriteLine("Initialized");
+ }
+ else
+ {
+ Current.Properties["LabelText"] = "Wowza";
+ label.Text = (string)Current.Properties["LabelText"] + " Set!";
+ Debug.WriteLine("Saved");
+ }
+
+ MainPage = new ContentPage
+ {
+ Content = new StackLayout
+ {
+ Children =
+ {
+ label
+ }
+ }
+ };
+
+ SerializeProperties();
+ }
+
+ static async void SerializeProperties()
+ {
+ await Current.SavePropertiesAsync();
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj b/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj
index fbccef9..53565c9 100644
--- a/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj
+++ b/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj
@@ -73,6 +73,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="App.cs" />
+ <Compile Include="AppLifeCycle.cs" />
<Compile Include="ControlGalleryPages\CellForceUpdateSizeGalleryPage.cs" />
<Compile Include="ControlGalleryPages\LayoutAddPerformance.xaml.cs">
<DependentUpon>LayoutAddPerformance.xaml</DependentUpon>
@@ -94,6 +95,8 @@
<Compile Include="LegacyRepro\Page1.xaml.cs">
<DependentUpon>Page1.xaml</DependentUpon>
</Compile>
+ <Compile Include="MainPageLifeCycleTests.cs" />
+ <Compile Include="NavReproApp.cs" />
<Compile Include="RootPages\RootContentPage.cs" />
<Compile Include="RootPages\SwapHierachyStackLayout.cs" />
<Compile Include="GalleryPages\EditableList.cs" />
@@ -116,6 +119,7 @@
<Compile Include="LegacyRepro\SampleViewCell.xaml.cs">
<DependentUpon>SampleViewCell.xaml</DependentUpon>
</Compile>
+ <Compile Include="SimpleApp.cs" />
<Compile Include="ViewContainers\EventViewContainer.cs" />
<Compile Include="ViewContainers\LayeredViewContainer.cs" />
<Compile Include="ViewContainers\MultiBindingHack.cs" />