-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Conversation
…es a Command property
…ranslate to a Page This vastly simplifies things. Note: this includes an iOS renderer, but there seems to be a bug with it that will need to be addressed.
This added extra complexity, but its usefulness wasn't very obvious. If a good argument were made for having this property, we can revert this.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll pull this branch, rebase and review further soon
{ | ||
// implementing classes must be castable to Element | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public interface ICommandableElement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep it internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, the BP can be extracted in a static helper class (see ITextElement, TextElement)
PopToRoot = Pop | MainPage, | ||
} | ||
|
||
public class NavigationActionConverter : TypeConverter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attribute with the return type
namespace Xamarin.Forms | ||
{ | ||
[TypeConverter(typeof(NavigationActionConverter))] | ||
public enum NavigationAction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the PopX
are OR
ed together, shouldn't they all be powers of two (and be [Flags]
)? Although as it turns out everything will be fine in this case with them having values of 5, 6, 7 respectively.
Since the PopX
values are special, and NavigationAction
s can't arbitrarily be OR
ed anyway, it seems better to specifically assign values to them.
This is going to get integrated into Shell and at that point we can move it over into core as one block |
Description of Change
Segues are objects that represent navigational actions. These objects can be created and wired up entirely in XAML without any codebehind (or with code, if you prefer).
This PR is an evolution of https://github.com/chkn/Xamarin.Forms.Segues integrated into Core. This integration has some benefits:
NavigationAction
enum maps toINavigation
methodsValueSegue
: a lightweight struct that holds either a simpleNavigationAction
or a fullSegue
instanceNavigationAction
when a fullSegue
instance is not needed{Segue}
markup extension does not actually instantiateSegue
(returns a lightweightICommand
that triggers the same behavior)Segue
instance can be provided by user if they want to enable/disable it, subclass it, bind properties, or to perform actions when the segue is executed.I've included the platform implementation for iOS only for now. If we decide we want to proceed with this approach, I could implement Android and UWP as well.
NavigationAction
This introduces the
NavigationAction
enum, whose values mostly represent method calls onINavigation
. However, there are a couple differences:Show
This PR introduces
INavigation.ShowAsync
andNavigationAction.Show
. This action is designed to do the right thing in most common cases, and as such, is the defaultNavigationAction
for segues. If the user does not want this default behavior, they can specify one of the other navigation actions explicitly.Behavior depends on the context. Here are the rules:
NavigationPage
, callsINavigation.PushAsync
.INavigation.PushModalAsync
.I also had a couple other interesting ideas for this action in the context of a
MultiPage
orMasterDetailPage
, but I did not implement them for this PR.Caveat: Throws an
InvalidOperationException
if this action is used when navigation is not rooted (i.e.NavigationProxy.Inner == null
). It might be possible to remove this limitation, but there are some issues that would need to be resolved.Pop
This PR also introduces
NavigationAction.Pop
. Note that this is NOT the equivalent of callingINavigation.PopAsync
, which is an existing API that corresponds to the newNavigationAction.PopPushed
.Like the above,
NavigationAction.Pop
tries to do the right thing depending on the context:INavigation.PopModalAsync
.INavigation.PopAsync
.MainPage
Sometimes you either don't want stack-based navigation, or you want to reset the root of your app easily. As such,
NavigationAction.MainPage
is included that trivially setsApplication.Current.MainPage
to the target page.Native Segues
Segues may be used to navigate to native screens. This functionality is analogous to the native view support (https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/native-views/).
Examples
Attach a segue to a button from XAML
Note that
Segue.Target
can also be aDataTemplate
.Attach a segue to a button from code
Imperatively perform a segue from code
Bugs Fixed
None
API Changes
Added:
Changed:
Behavioral Changes
None intended.
PR Checklist