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

Commit

Permalink
Update merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarinho committed Oct 20, 2020
1 parent bf4dabb commit c55d2e0
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 66 deletions.
18 changes: 14 additions & 4 deletions src/Platform.Handlers/samples/Sample.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using Microsoft.Extensions.DependencyInjection;
using Sample.Services;
using Xamarin.Platform.Hosting;
using Xamarin.Platform.Handlers;
using System;
using System.Collections.Generic;

namespace Sample.Droid
{
Expand All @@ -35,14 +38,21 @@ protected override void OnCreate(Bundle savedInstanceState)

var app = CreateAppBuilder()
.ConfigureServices(ConfigureExtraServices)
//.RegisterHandler<IButton, CustomHandlers.CustomPinkTextButtonHandler>()
//.RegisterHandlers(new Dictionary<Type, Type>
//{
// { typeof(Xamarin.Platform.VerticalStackLayout),typeof(LayoutHandler) },
// { typeof(Xamarin.Platform.HorizontalStackLayout),typeof(LayoutHandler) },
// { typeof(Xamarin.Forms.FlexLayout),typeof(LayoutHandler) },
// { typeof(Xamarin.Forms.StackLayout),typeof(LayoutHandler) },
//})
.Init<MyApp>();

_appBuilder.Start();

var page = app.Services.GetRequiredService<IStartup>() as Xamarin.Forms.ContentPage;
Add(page.Content as IView);
var page = app.Services.GetRequiredService<IStartup>() as Pages.MainPage;
Add(page.GetContentView());
}

void ConfigureExtraServices(HostBuilderContext ctx, IServiceCollection services)
{
services.AddSingleton<ITextService, Services.DroidTextService>();
Expand Down
18 changes: 14 additions & 4 deletions src/Platform.Handlers/samples/Sample.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using Xamarin.Platform.Core;
using Xamarin.Platform.Hosting;
using Sample.Services;
using System.Collections.Generic;
using System;
using Xamarin.Platform.Handlers;

namespace Sample.iOS
{
Expand All @@ -32,16 +35,23 @@ public override bool FinishedLaunching(UIApplication application, NSDictionary l

var app = CreateAppBuilder()
.ConfigureServices(ConfigureExtraServices)
.RegisterHandler<IButton, CustomHandlers.CustomPinkTextButtonHandler>()
//.RegisterHandler<IButton, CustomHandlers.CustomPinkTextButtonHandler>()
//.RegisterHandlers(new Dictionary<Type, Type>
//{
// { typeof(Xamarin.Platform.VerticalStackLayout),typeof(LayoutHandler) },
// { typeof(Xamarin.Platform.HorizontalStackLayout),typeof(LayoutHandler) },
// { typeof(Xamarin.Forms.FlexLayout),typeof(LayoutHandler) },
// { typeof(Xamarin.Forms.StackLayout),typeof(LayoutHandler) },
//})
.Init<MyApp>();

_appBuilder.Start();

var page = app.Services.GetRequiredService<IStartup>() as Xamarin.Forms.ContentPage;

var page = app.Services.GetRequiredService<IStartup>() as Pages.MainPage;
_window.RootViewController = new UIViewController
{
View = page.Content.ToNative()
View = page.GetContentView().ToNative()
};

_window.MakeKeyAndVisible();
Expand Down
2 changes: 2 additions & 0 deletions src/Platform.Handlers/samples/Sample.iOS/Sample.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<MtouchArch>x86_64</MtouchArch>
<MtouchLink>None</MtouchLink>
<MtouchDebug>true</MtouchDebug>
<CodesignKey>Apple Development: Rui Marinho (G6DXESA369)</CodesignKey>
<CodesignProvision>VS: WildCard Development</CodesignProvision>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Sample.iOS.Services
{
class iOSTextService : ITextService
{
public string GetText() => "Hello From Android";
public string GetText() => "Hello From iOS";
}
}
26 changes: 3 additions & 23 deletions src/Platform.Handlers/samples/Sample/MyApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,11 @@ namespace Sample
{
public class MyApp : App
{

public void ConfigureServices(HostBuilderContext ctx, IServiceCollection services)
{
var verticalStack = new Xamarin.Platform.VerticalStackLayout() { Spacing = 5, BackgroundColor = Color.AntiqueWhite };
var horizontalStack = new Xamarin.Platform.HorizontalStackLayout() { Spacing = 2 };

var label = new Label { Text = "This top part is a Xamarin.Platform.VerticalStackLayout" };

verticalStack.Add(label);

var button = new Button() { Text = "A Button", Width = 200 };
var button2 = new Button()
{
Color = Color.Green,
Text = "Hello I'm a button",
BackgroundColor = Color.Purple
};

horizontalStack.Add(button);
horizontalStack.Add(button2);
horizontalStack.Add(new Label { Text = "And these buttons are in a HorizontalStackLayout" });

verticalStack.Add(horizontalStack);

return verticalStack;
services.AddSingleton<ITextService, TextService>();
services.AddTransient<MainPageViewModel>();
services.AddTransient<IStartup, MainPage>();
}
}
}
30 changes: 27 additions & 3 deletions src/Platform.Handlers/samples/Sample/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Sample.Services;
using Sample.ViewModel;
using Xamarin.Forms;
using Xamarin.Platform;
using Xamarin.Platform.Hosting;

namespace Sample.Pages
Expand All @@ -13,11 +14,34 @@ public class MainPage : ContentPage, IStartup
public MainPage(MainPageViewModel viewModel)
{
BindingContext = viewModel;
}

public IView GetContentView()
{
var verticalStack = new Xamarin.Platform.VerticalStackLayout() { Spacing = 5, BackgroundColor = Color.AntiqueWhite };
var horizontalStack = new HorizontalStackLayout() { Spacing = 2 };

var label = new Label { Text = "This top part is a Xamarin.Platform.VerticalStackLayout" };

verticalStack.Add(label);

var button = new Xamarin.Forms.Button();
button.BindingContext = BindingContext;
button.SetBinding(Xamarin.Forms.Button.TextProperty, "Text");
var button2 = new Button()
{
Color = Color.Green,
Text = "Hello I'm a button",
BackgroundColor = Color.Purple
};

horizontalStack.Add(button);
horizontalStack.Add(button2);
horizontalStack.Add(new Label { Text = "And these buttons are in a HorizontalStackLayout" });

var btn = new Xamarin.Forms.Button();
btn.SetBinding(Xamarin.Forms.Button.TextProperty, "Text");
verticalStack.Add(horizontalStack);

Content = btn;
return verticalStack;
}
}
}
30 changes: 0 additions & 30 deletions src/Platform.Handlers/samples/Sample/Startup.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ public AppBuilder UseXamarinHandlers()
{
RegisterHandlers(new Dictionary<Type, Type>
{
{ typeof(IButton), typeof(ButtonHandler) }
{ typeof(IButton), typeof(ButtonHandler) },
{ typeof(ILayout), typeof(LayoutHandler) },
{ typeof(ILabel), typeof(LabelHandler) },
{ typeof(ISlider), typeof(SliderHandler) }
});

return this;
}

Expand Down

0 comments on commit c55d2e0

Please sign in to comment.