Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[WIP] Fluent API + Micosoft.Extensions.Hosting for initialization of Xamarin.Forms #8220

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ec52e0c
wip
KSemenenko Oct 18, 2019
e297704
Merge remote-tracking branch 'upstream/master' into issue-5037-fluentapi
KSemenenko Oct 23, 2019
27ba432
FormsInit
KSemenenko Oct 25, 2019
17e1d3d
structure
KSemenenko Oct 25, 2019
2b448bf
Extensions for iOS and Android
KSemenenko Oct 25, 2019
5efcd34
refactoring
KSemenenko Oct 25, 2019
9a2c931
more extensions
KSemenenko Oct 25, 2019
92ec1ff
tests
KSemenenko Oct 25, 2019
3873a18
tests
KSemenenko Oct 25, 2019
35cb710
revert changes
KSemenenko Oct 25, 2019
660e211
one more revert
KSemenenko Oct 25, 2019
91193bf
wpf remove extra init
KSemenenko Oct 25, 2019
5ddc805
Merge remote-tracking branch 'upstream/master' into issue-5037-fluentapi
KSemenenko Oct 31, 2019
149de2f
WithVisualMaterial
KSemenenko Oct 31, 2019
ab59360
Merge remote-tracking branch 'upstream/master' into issue-5037-fluentapi
KSemenenko Nov 11, 2019
865a03b
Microsoft.Extensions.Hosting
KSemenenko Nov 11, 2019
67ce449
wip - android
KSemenenko Nov 14, 2019
98beb3c
new Fluent style
KSemenenko Nov 14, 2019
31b91b2
AndroidFormsInit
KSemenenko Nov 14, 2019
f73f583
unused using
KSemenenko Nov 14, 2019
f2300dd
FormsInit -> FormsBuilder
KSemenenko Nov 14, 2019
9db1443
refactoring
KSemenenko Nov 15, 2019
9369ade
refactoring
KSemenenko Nov 15, 2019
b985b6e
refactoring
KSemenenko Nov 15, 2019
0412ee1
appsettings.json check
KSemenenko Nov 15, 2019
2eb4b5d
Merge branch 'master' into issue-5037-fluentapi
KSemenenko Nov 15, 2019
2e3b6e6
fixes
KSemenenko Nov 15, 2019
32e8214
nuget
KSemenenko Nov 18, 2019
dc203e2
nuget
KSemenenko Nov 18, 2019
497fa56
nuget for test projects
KSemenenko Nov 18, 2019
56d4b6a
System.Threading.Tasks.Extensions
KSemenenko Nov 18, 2019
d8d64e9
fixes
KSemenenko Nov 18, 2019
ab33c30
EmbeddingTestBeds
KSemenenko Nov 18, 2019
d2d8bfa
refactoring
KSemenenko Nov 19, 2019
4636fb1
EmbeddedResourceLoaderTests
KSemenenko Nov 19, 2019
aaa158e
Nuget: Microsoft.Bcl.AsyncInterfaces + System.Text.Json
KSemenenko Nov 19, 2019
80be970
remove nuget references
KSemenenko Nov 25, 2019
0ad0915
cproj
KSemenenko Nov 25, 2019
2ac04d2
cproj
KSemenenko Nov 25, 2019
9a5c7c4
cproj
KSemenenko Nov 25, 2019
5ecc63e
cproj
KSemenenko Nov 25, 2019
955b756
Merge remote-tracking branch 'upstream/master' into issue-5037-fluentapi
KSemenenko Nov 25, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ protected override void OnCreate(Bundle bundle)

base.OnCreate(bundle);

Forms.Create(this, bundle)

#if TEST_EXPERIMENTAL_RENDERERS
// Fake_Flag is here so we can test for flag initialization issues
Forms.SetFlags("Fake_Flag"/*, "CollectionView_Experimental", "Shell_Experimental"*/);
// Fake_Flag is here so we can test for flag initialization issues
.WithFlags("Fake_Flag"/*, "CollectionView_Experimental", "Shell_Experimental"*/)
#else
Forms.SetFlags("UseLegacyRenderers"/*, "CollectionView_Experimental", "Shell_Experimental" */);
.WithFlags("UseLegacyRenderers"/*, "CollectionView_Experimental", "Shell_Experimental" */)
#endif
Forms.Init(this, bundle);
.WithMaps(this, bundle)
.WithMaterial()
.WithAppLinks(this)
.Init();

FormsMaps.Init(this, bundle);
FormsMaterial.Init(this, bundle);
AndroidAppLinks.Init(this);
Forms.ViewInitialized += (sender, e) => {
// if (!string.IsNullOrWhiteSpace(e.View.StyleId)) {
// e.NativeView.ContentDescription = e.View.StyleId;
Expand Down
93 changes: 47 additions & 46 deletions Xamarin.Forms.ControlGallery.GTK/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,57 @@
[assembly: ExportRenderer(typeof(DisposeLabel), typeof(DisposeLabelRenderer))]
namespace Xamarin.Forms.ControlGallery.GTK
{
class Program
{
[STAThread]
static void Main(string[] args)
{
ExceptionManager.UnhandledException += OnUnhandledException;
class Program
{
[STAThread]
static void Main(string[] args)
{
ExceptionManager.UnhandledException += OnUnhandledException;

GtkOpenGL.Init();
GtkThemes.Init();
Gtk.Application.Init();
FormsMaps.Init(string.Empty);
Forms.Init();
var app = new App();
var window = new FormsWindow();
window.LoadApplication(app);
window.SetApplicationTitle("Xamarin.Forms GTK# Backend");
window.SetApplicationIcon("xamarinlogo.png");
window.Show();
Gtk.Application.Run();
}
GtkOpenGL.Init();
GtkThemes.Init();
Gtk.Application.Init();
Forms.Create()
.WithMaps(string.Empty)
.Init();
var app = new App();
var window = new FormsWindow();
window.LoadApplication(app);
window.SetApplicationTitle("Xamarin.Forms GTK# Backend");
window.SetApplicationIcon("xamarinlogo.png");
window.Show();
Gtk.Application.Run();
}

private static void OnUnhandledException(UnhandledExceptionArgs args)
{
System.Diagnostics.Debug.WriteLine($"Unhandled GTK# exception: {args.ExceptionObject}");
}
}
private static void OnUnhandledException(UnhandledExceptionArgs args)
{
System.Diagnostics.Debug.WriteLine($"Unhandled GTK# exception: {args.ExceptionObject}");
}
}

public class DisposePageRenderer : PageRenderer
{
protected override void Dispose(bool disposing)
{
if (disposing)
{
((DisposePage)Element).SendRendererDisposed();
}
public class DisposePageRenderer : PageRenderer
{
protected override void Dispose(bool disposing)
{
if (disposing)
{
((DisposePage)Element).SendRendererDisposed();
}

base.Dispose(disposing);
}
}
base.Dispose(disposing);
}
}

public class DisposeLabelRenderer : LabelRenderer
{
protected override void Dispose(bool disposing)
{
if (disposing)
{
((DisposeLabel)Element).SendRendererDisposed();
}
public class DisposeLabelRenderer : LabelRenderer
{
protected override void Dispose(bool disposing)
{
if (disposing)
{
((DisposeLabel)Element).SendRendererDisposed();
}

base.Dispose(disposing);
}
}
base.Dispose(disposing);
}
}
}
5 changes: 3 additions & 2 deletions Xamarin.Forms.ControlGallery.MacOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public override NSWindow MainWindow

public override void DidFinishLaunching(NSNotification notification)
{
Forms.Init();
FormsMaps.Init();
Forms.Create()
.WithMaps()
.Init();

var app = new App();
SetupMenu(app);
Expand Down
11 changes: 7 additions & 4 deletions Xamarin.Forms.ControlGallery.Tizen/ControlGallery.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ protected override void OnCreate()
static void Main(string[] args)
{
var app = new MainApplication();
FormsMaps.Init("HERE", "write-your-API-key-here");
Forms.SetFlags("CollectionView_Experimental", "Shell_Experimental");
Forms.Init(app);
FormsMaterial.Init();

Forms.Create(app)
.WithFlags("CollectionView_Experimental", "Shell_Experimental")
.WithMaps("HERE", "write-your-API-key-here")
.WithMaterial()
.Init();

app.Run(args);
}
}
Expand Down
15 changes: 8 additions & 7 deletions Xamarin.Forms.ControlGallery.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

namespace Xamarin.Forms.ControlGallery.WPF
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : FormsApplicationPage
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : FormsApplicationPage
{
public MainWindow()
{
InitializeComponent();
Xamarin.Forms.Forms.Init();
FormsMaps.Init("");
Xamarin.Forms.Forms.Create()
.WithMaps("")
.Init();
LoadApplication(new Controls.App());
}
}
}
}
129 changes: 65 additions & 64 deletions Xamarin.Forms.ControlGallery.WindowsUniversal/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@

namespace Xamarin.Forms.ControlGallery.WindowsUniversal
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
InitializeComponent();
Suspending += OnSuspending;
}
{
InitializeComponent();
Suspending += OnSuspending;
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
/* uncomment if you want to run tests without preloading
* issues list or change other behavior based on if tests
* are running in UI Harness
Expand All @@ -52,39 +52,40 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
Controls.App.PreloadTestCasesIssuesList = false;*/
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
// DebugSettings.EnableFrameRateCounter = true;
}
{
// DebugSettings.EnableFrameRateCounter = true;
}
#endif

var rootFrame = Window.Current.Content as Windows.UI.Xaml.Controls.Frame;
var rootFrame = Window.Current.Content as Windows.UI.Xaml.Controls.Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Windows.UI.Xaml.Controls.Frame();
// Set the default language
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Windows.UI.Xaml.Controls.Frame();
// Set the default language
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

rootFrame.NavigationFailed += OnNavigationFailed;
rootFrame.NavigationFailed += OnNavigationFailed;

Forms.SetFlags("Shell_UWP_Experimental");
Forms.Init (e);
//FormsMaps.Init (Controls.App.Config["UWPMapsAuthKey"]);
Forms.Create(e)
.WithFlags("Shell_UWP_Experimental")
//.WithMaps(Controls.App.Config["UWPMapsAuthKey"])
.Init();

// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
}

if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}

//// Uncomment to test overriding the status bar color
//if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
Expand All @@ -100,30 +101,30 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)

// Ensure the current window is active
Window.Current.Activate();
}
}

/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}
10 changes: 6 additions & 4 deletions Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary
App.IOSVersion = int.Parse(versionPart[0]);

Xamarin.Calabash.Start();
// Forms.SetFlags("CollectionView_Experimental", "Shell_Experimental");
Forms.Init();
FormsMaps.Init();
FormsMaterial.Init();

Forms.Create()
//.WithFlags("CollectionView_Experimental", "Shell_Experimental")
.WithMaps()
.WithMaterial()
.Init();

Forms.ViewInitialized += (object sender, ViewInitializedEventArgs e) =>
{
Expand Down
28 changes: 28 additions & 0 deletions Xamarin.Forms.Core.UnitTests/FormsInitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using NUnit.Framework;

namespace Xamarin.Forms.Core.UnitTests
{
[TestFixture]
public class FormsInitTests : BaseTestFixture
{
[Test]
public void InitTest()
{
var list = new List<string>();

var formsInit = new FormsInit(() => list.Add("init"));
formsInit.PostInit(() => list.Add("post1"));
formsInit.PreInit(() => list.Add("pre1"));
formsInit.PreInit(() => list.Add("pre2"));
formsInit.PostInit(() => list.Add("post2"));
formsInit.Init();

Assert.IsTrue(list[0] == "pre1");
Assert.IsTrue(list[1] == "pre2");
Assert.IsTrue(list[2] == "init");
Assert.IsTrue(list[3] == "post1");
Assert.IsTrue(list[4] == "post2");
}
}
}
Loading