xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.88k forks source link

[Spec] Shell Scenarios #8528

Closed PureWeen closed 2 years ago

PureWeen commented 4 years ago

Shell Scenarios

Currently the shell Xaml structure isn't as declarative as it could be when putting together your structures. It would be ideal to enable the ability to create scenarios that allow developers to describe workflows.

https://github.com/xamarin/Xamarin.Forms/issues/6950 https://github.com/xamarin/Xamarin.Forms/issues/6139 https://github.com/xamarin/Xamarin.Forms/issues/5272

Currently if users want to represent a Login scenario (very typical) they do so like this

<!-- When the user is on this Login Page they won't see a flyout menu-->
<TabBar Route="LoginPage">
    <local:LoginPage/>
</TabBar>

<!-- When the user is here they won't be able to get back to the Login Page-->
<FlyoutItem Route="LoggedIn">
     <UserPages/>
</FlyoutItem>
<FlyoutItem>
     <UserPages/>
</FlyoutItem>

It's very confusing that the top part and the bottom part are mutually exclusive. Out of the box we could provide a default layout scenario that just indicates what layouts you want active

<LayoutScenario Route="Anonymous">
     <!-- When the user is on this Login Page they won't see a flyout menu-->
     <TabBar Route="LoginPage">
         <local:LoginPage/>
     </TabBar>
</LayoutScenario>

<LayoutScenario Route="Employee">
     <!-- When the user is here they won't be able to get back to the Login Page-->
     <FlyoutItem Route="LoggedIn">
          <UserPages/>
     </FlyoutItem>
     <FlyoutItem>
          <UserPages/>
     </FlyoutItem>
</LayoutScenario>

<LayoutScenario Route="Admin">
     <!-- When the user is here they won't be able to get back to the Login Page-->
     <FlyoutItem Route="LoggedIn">
          <UserPages/>
     </FlyoutItem>
     <FlyoutItem>
          <UserPages/>
     </FlyoutItem>
     <FlyoutItem>
          <AdminPages />
     </FlyoutItem>
</LayoutScenario>

Then we would enable these scenarios along the same line as the MVVM hooks we are building here https://github.com/xamarin/Xamarin.Forms/issues/5166

So users could register a service for a Scenario and then that service could handle everything outlined in #5166 before it passes things up to the NavigationService

Scenarios

Authentication Scenario (this would not be part of core it's just demonstrating capabilities)

<AuthenticationScenario Route="Anonymous">
     <!-- When the user is on this Login Page they won't see a flyout menu-->
     <TabBar Route="LoginPage">
         <local:LoginPage/>
     </TabBar>
</AuthenticationScenario>

<LayoutScenario Route="Employee">
     <!-- When the user is here they won't be able to get back to the Login Page-->
     <FlyoutItem Route="LoggedIn">
          <UserPages/>
     </FlyoutItem>
     <FlyoutItem>
          <UserPages/>
     </FlyoutItem>
</LayoutScenario>

See https://github.com/xamarin/Xamarin.Forms/issues/5166 for description of these interfaces

public class ShellScenario : IShellNavigationRequest, IShellContentCreator, IShellApplyParameters, IShellPartAppearing, IShellPartAppeared, IShellPartDisappeared
{

}

///third part scenario
public class AuthenticationScenario  : ShellScenario
{

}

Custom Scenarios with custom Xaml types

<Shell>
  <StackScenario>
    <ShellContent Route="Login" ContentTemplate="{DataTemplate LoginPage}"/>
    <ShellContent Route="Registration" ContentTemplate="{DataTemplate RegistrationPage}"/>
    <ShellContent Route="ForgotPassword" ContentTemplate="{DataTemplate ForgotPasswordPage}"/>
  </StackScenario>
</Shell>

In this scenario we would provide a custom XAML type and then developers could just control all the interactions themselves inside DrillDownNavigationScenario

<DrillDownNavigationScenario>
    <DrillDownContent ContentTemplate="{ShellItem1}">
        <DrillDownContent ContentTemplate="{ShellItem2}">
            <DrillDownContent ContentTemplate="{ShellItem3}">
                <DrillDownContent ContentTemplate="{ShellContent4}"/>
            </DrillDownContent >
        </DrillDownContent >
    </DrillDownContent >
</DrillDownNavigationScenario>

Difficulty : medium

mjfreelancing commented 4 years ago

Definitely liking the sound of this proposal.

mrbrl commented 4 years ago

+999999999 for drilldown and scenarios

jfversluis commented 2 years ago

Thanks for this suggestion! As Xamarin.Forms is now in maintenance mode, this will not happen anymore for Xamarin.Forms. We're only adding bugfixes and stability fixes.

If this is still important to you, make sure to check the .NET MAUI repo and see if it's already on the roadmap. If not, feel free to open a discussion to discuss a change first or open an issue with a detailed feature request. Thanks!