Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavigationView Handler for Android #2336

Merged
merged 14 commits into from
Sep 1, 2021
Merged

NavigationView Handler for Android #2336

merged 14 commits into from
Sep 1, 2021

Conversation

PureWeen
Copy link
Member

@PureWeen PureWeen commented Aug 31, 2021

TODO

I need to add Unit tests but otherwise ready to review

Description of Change

  • Creates the APIs required inside Maui.Core to implementation navigation
  • Implements Navigation for Android. The Maui.Core implementation leans heavily on JetPack Navigation in order to avoid having to interact with fragment management ourselves.
  • Toolbar Management still only exists at the controls level. In a later PR we'll better organized the ToolBar management into Core

INavigationView

The idea with only using requests is that it forces immutable communication about navigation stack changes. Once the xplat layer requests a change that's the change that gets applied and the native layer only applies changes related to those args. Requests are also useful because you need to convey information about the navigation operation (i.e. animated) which can't be indicated through a property change.

The nice thing about doing everything through stack mutations is that it allows you to modify the stack atomically opposed to having to chain navigation operations together.

For example in XF if you want to swap out the Main Page users would typically do

NavigationPage.InsertPageBefore(mainpage, newpage);
NavigationPage.Pop();

Or if you want to pop down multiple pages but not to root

NavigationPage.Pop();
NavigationPage.Pop();
NavigationPage.Pop();

Where as now we can add APIs that just let users perform multiple operations in one go.

// This would get exposed as a simpler API to the user but it demonstrates the behavior
void SwapRoot(object sender, EventArgs e)
{
	if (_currentNavStack == null)
	{
               // save stack so you can swap back to it
		_currentNavStack = Navigation.NavigationStack.ToList();
		(Parent as INavigationView).RequestNavigation(
		new NavigationRequest(
			new List<NavigationGallery>
			{
				new NavigationGallery()
			}, false));
	}
	else
	{
		(Parent as INavigationView).RequestNavigation(
			new NavigationRequest(_currentNavStack, true));

		_currentNavStack = null;
	}
}
public interface INavigationView : IView
{
	void RequestNavigation(MauiNavigationRequestedEventArgs eventArgs);
	void NavigationFinished(IReadOnlyList<IView> newStack);
}

Alternative API (possibly for future PR)

public interface INavigationView : IView
{
	IReadOnlyList<NavigationItem> NavigationStack { get; }
	void NavigationFinished(IReadOnlyList<IView> newStack);
}
public class NavigationItem
{
	IView View;
	Animation PopEnter;
	Animation PopExit;
	Animation Enter;
	Animation Exit;
}

NavigationManager

If users want to customize any of the behavior of navigation they can provide a custom Navigation Manager

public class NavigationManager
{
        public virtual FragmentNavigator.Destination AddFragmentDestination();
        public virtual void Connect(IView navigationView, NavigationLayout nativeView);
        public virtual void RequestNavigation(MauiNavigationRequestedEventArgs e);
        protected virtual void OnBackButtonPressed();
        protected virtual void OnNavigationViewFragmentDestroyed(AndroidX.Fragment.App.FragmentManager fm, NavigationViewFragment navHostPageFragment);
        protected virtual void OnNavigationViewFragmentResumed(AndroidX.Fragment.App.FragmentManager fm, NavigationViewFragment navHostPageFragment);
        protected virtual void OnDestinationChanged(NavController navController, NavDestination navDestination, Bundle bundle);
}

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)
  • Targets a single property for a single control (or intertwined few properties)
  • Adds the property to the appropriate interface
  • Avoids any changes not essential to the handler property
  • Adds the mapping to the PropertyMapper in the handler
  • Adds the mapping method to the Android, iOS, and Standard aspects of the handler
  • Implements the actual property updates (usually in extension methods in the Platform section of Core)
  • Tags ported renderer methods with [PortHandler]
  • Adds an example of the property to the sample project (MainPage)
  • Adds the property to the stub class
  • Implements basic property tests in DeviceTests

Does this PR touch anything that might affect accessibility?

  • Does this PR introduce a new control? (If yes, add an example using SemanticProperties to the SemanticsPage)
  • APIs that modify focusability?
  • APIs that modify any text property on a control?
  • Does this PR modify view nesting or view arrangement in anyway?
  • Is there the smallest possibility that your PR will change accessibility?
  • I'm not sure, please help me

If any of the above checkboxes apply to your PR, then the PR will need to provide testing to demonstrate that accessibility still works.

internal void InitialNativeNavigationStackLoaded()
{
SendNavigated(null);
}

internal async Task<Page> PopAsyncInner(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved all of this to NavigationPage.Legacy.cs

@@ -6,33 +6,28 @@

namespace Microsoft.Maui.Handlers
{
internal partial class NavigationPageHandler :
internal partial class NavigationViewHandler :
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handler currently doesn't work so you can ignore changes here.

@@ -10,12 +10,16 @@

namespace Microsoft.Maui.Handlers
{
internal partial class NavigationPageHandler :
internal partial class NavigationViewHandler :
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handler currently doesn't work so you can ignore changes here.

@@ -3,5 +3,6 @@
<color name="colorPrimary">#2c3e50</color>
<color name="colorPrimaryDark">#1B3147</color>
<color name="colorAccent">#3498db</color>
<color name="colorActionMenuTextColor">#FFFFFF</color>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently in non Forms Shell apps this value is only settable through style attributes. The default in Forms is white so we are using white here

@PureWeen PureWeen marked this pull request as ready for review August 31, 2021 22:07
@Redth Redth merged commit 25c7c2c into main Sep 1, 2021
@Redth Redth deleted the navigation_controls_handler branch September 1, 2021 14:54
Csaba8472 added a commit to Csaba8472/maui that referenced this pull request Sep 6, 2021
* upstream/main: (326 commits)
  Re-enable interpreter on blazor by default
  Determine size of auto cells in GridLayout correctly when views occupy same cell (dotnet#2391)
  [main] Update dependencies from xamarin/xamarin-macios (dotnet#2326)
  [Android] Fix Horizontal Scrollbar Visibility (dotnet#2374)
  Try start vs4mac with local dotnet (dotnet#2386)
  [workoad] include missing dependencies in the workload (dotnet#2281)
  Update project templates to work with safe characters (dotnet#2368)
  [release/6.0.1xx-rc1] Update dependencies from xamarin/xamarin-android (dotnet#2369)
  Update dependencies from https://github.com/xamarin/xamarin-macios build 20210903.3 (dotnet#2384)
  Bump manifest to use api 31 (dotnet#2366)
  BoxView Handlers (dotnet#2250)
  Implement IsTextPredictionEnabled in WinUI Editor (dotnet#1478)
  Implement PlaceholderColor property in EntryHandlers (dotnet#1513)
  Automated dotnet-format update (dotnet#2355)
  Show entire search bar by default and make it not collapse (dotnet#2351)
  Remove test cloud if def for now (dotnet#2350)
  Add support for JS root components in BlazorWebView (dotnet#2293)
  Set base viewmapper to work against IViewHandler (dotnet#2339)
  NavigationView Handler for Android (dotnet#2336)
  Update OutputType to WinExe on -windows (dotnet#2340)
  ...
@samhouts samhouts added area-core-hosting Extensions / Hosting / AppBuilder / Startup area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter area-controls-modal area-navigation NavigationPage area-controls-shell Shell Navigation, Routes, Tabs, Flyout area/toolbar area-controls-pages Page types labels Jul 11, 2023
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jul 11, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2023
@Eilon Eilon removed area/toolbar legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-controls-pages Page types labels May 10, 2024
@samhouts samhouts added the fixed-in-6.0.101-preview.10 Look for this fix in 6.0.101-preview.10! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-modal area-controls-shell Shell Navigation, Routes, Tabs, Flyout area-controls-toolbar ToolBar area-core-hosting Extensions / Hosting / AppBuilder / Startup area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter area-navigation NavigationPage fixed-in-6.0.101-preview.10 Look for this fix in 6.0.101-preview.10! platform/android 🤖 platform/iOS 🍎 platform/windows 🪟
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants