Different Forms Layout Between Platforms

juggernaut3000sdjuggernaut3000sd USMember ✭✭
edited June 2018 in Xamarin.Forms

Good morning,

What is the correct procedure for having different layouts on different platforms? For example:

On IOS: I want my widget page to have layout a which contains IOS related features
On Android: I want my widget page to have layout b which contains Android related features (floating action buttons, toasts, etc)

do I:

Do I create two separate pages and, based on the platform, redirect to the appropriate page?
Do I just create one page and do : If platform is IOS, render a page like this, If platform is Android, render page like this?
Do I use DI to override page?

Thanks

Tagged:

Answers

  • WasserEsserWasserEsser Member ✭✭

    I suggest using Prism and its navigation system.
    You register your pages for navigation in your App.xaml.cs and you can easily navigate to them.
    You can also register specific pages for specific platforms like this:

    containerRegistry.RegisterForNavigationOnPlatform<LoginPage, LoginPageViewModel>("Login", new Platform<LoginPage_Android>(RuntimePlatform.Android), new Platform<LoginPage_iOS>(RuntimePlatform.iOS));

    You can now navigate to your login page from anywhere via await navigationService.NavigateAsync("Login"); and it will show the different pages depending on the platform.

  • ColeXColeX Member, Xamarin Team Xamurai

    You can embedding native controls into Xamarin.Forms , so that you can render different controls on each platform.

    Refer to https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/native-views/code.

    But it is only support in Shared Project.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I'd bet most of the page is platform-agnostic with just a few items that are platform-specific.
    Is there any reason you couldn't use OnPlatform for the few specific items?
    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/essential-xaml-syntax

Sign In or Register to comment.