xamarin / Xamarin.Forms

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

[Spec] Modal Improvements #7147

Closed PureWeen closed 2 years ago

PureWeen commented 5 years ago

Modal Spec

Allow users to further customize modal behavior and simplify down the interaction with modal pages. The majority of the time pages that are treated as Modal are only used modally so it makes more sense to just describe the modal behavior as a permanent attribute of the page itself.

This is different than PopOvers (https://github.com/xamarin/Xamarin.Forms/issues/1778). You can have only one pop over and pop overs map more to alerts/dialogs associated to visible content. The difference can also be seen at the platform level with how iOS has a specific UIPopOverController vs setting the Modal Behavior on a UIViewController itself. You can push as many Modal Pages as you want onto a stack but there can be only one PopOver.

API

Supporting APIs

ModalBehavior

Users will set this on a Page to define how this page will be displayed modally. With Shell this will allow users to pass in parameters on the query string to influence the modal behavior on a page. They could even bind to the IsEnabled property on ModalBehavior which will cause it to not be pushed modally

public class ModalBehavior
{
  bool IsEnabled //v1
  bool Animate //v1
  DismissOptions Dismiss //v2
  DisplayOptions Display //v2

}

Properties

API Description
IsEnabled If this is set to false than the page will just push onto the current stack intead of being pushed modally. Changing this value while the page is already displayed will have no real time effect
Dismiss Indicate what ways you can dismiss the modal. Default will use a combination of platform defaults and display to determine default
Display Default: Use platform default. FullScreen: Cover the entire screen. FitToDevice: Size the content based on the size of the device. Phones will be FullScreen whereas larger tablets will show content in a window
Animate Default: true. Whether to animate or not
public enum DisplayOptions
  Default,
  FitToDevice,
}
[Flags]
public enum DismissOptions
{
  Default = 0,
  Swipe  = 1 << 0
}

When Display and Dismiss are set to default how they act will be determined by the platform and device types.

Examples


<ContentPage x:Class="Xamarin.Forms.Sandbox.MainPage">
  <Page.ModalBehavior>
     <ModalBehavior IsEnabled={Binding IsModal} />
  </Page.ModalBehavior>
</ContentPage>
// This will push the page modally 
Navigation.PushAsync(new MainPage())
// This will push the page non modally
Shell.Current.GotoAsync("MainPage?IsModal=false")

// This will push the page modally
Shell.Current.GotoAsync("MainPage?IsModal=true")

Implementation Details

Android

jfversluis commented 2 years ago

Some this we did, some of this we won't do no more. Closing.