question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] Android-Specific Navigation Bar Effect

See original GitHub issue

NavigationBarEffect

  • Proposed
  • Prototype: Not Started
  • Implementation: Not Started
    • iOS Support
    • Android Support
    • macOS Support
    • Windows Support
  • Unit Tests: Not Started
  • Sample: Not Started
  • Documentation: Not Started

Summary

Android-specific implementation allowing the user to customize the Navigation Bar

Detailed Design

NavigationBarEffect.cs

namespace Xamarin.CommunityToolkit.PlatformConfiguration.AndroidSpecific
{
	[Preserve(Conditional = true)]
	public static class NavigationBarEffect
	{
		static NavigationBarEffect()
		{
			#region Required work-around to prevent linker from removing the platform-specific implementation
#if __ANDROID__
			if (System.DateTime.Now.Ticks < 0)
				_ = new PlatformNavigationBarEffect();
#endif
			#endregion
		}

		public static readonly BindableProperty ColorProperty = BindableProperty.CreateAttached(
			"Color", typeof(Color), typeof(NavigationBarEffect), Color.Default, propertyChanged: TryGenerateEffect);

		public static readonly BindableProperty StyleProperty = BindableProperty.CreateAttached(
			"Style", typeof(NavigationBarStyle), typeof(NavigationBarEffect), NavigationBarStyle.Default, propertyChanged: TryGenerateEffect);

		public static Color GetColor(BindableObject bindable) =>
			(Color)bindable.GetValue(ColorProperty);

		public static void SetColor(BindableObject bindable, Color value) =>
			bindable.SetValue(ColorProperty, value);

		public static NavigationBarStyle GetStyle(BindableObject bindable) =>
			(NavigationBarStyle)bindable.GetValue(StyleProperty);

		public static void SetStyle(BindableObject bindable, NavigationBarStyle value) =>
			bindable.SetValue(StyleProperty, value);

		public static IPlatformElementConfiguration<XFP.Android, FormsElement> SetNavigationBarColor(this IPlatformElementConfiguration<XFP.Android, FormsElement> config, Color color)
		{
			SetColor(config.Element, color);
			return config;
		}

		public static Color GetNavigationBarColor(this IPlatformElementConfiguration<XFP.Android, FormsElement> config) =>
			GetColor(config.Element);

		public static IPlatformElementConfiguration<XFP.Android, FormsElement> SetNavigationBarStyle(this IPlatformElementConfiguration<XFP.Android, FormsElement> config, NavigationBarStyle style)
		{
			SetStyle(config.Element, style);
			return config;
		}

		public static NavigationBarStyle GetNavigationBarStyle(this IPlatformElementConfiguration<XFP.Android, FormsElement> config) =>
			GetStyle(config.Element);

		static void TryGenerateEffect(BindableObject bindable, object oldValue, object newValue)
		{
			if (bindable is not FormsElement page)
				return;

			DetachEffect(page);

			AttachEffect(page);
		}

		static void AttachEffect(FormsElement element)
		{
			IElementController controller = element;
			if (controller is null || controller.EffectIsAttached(EffectIds.NavigationBar))
				return;

			element.Effects.Add(Effect.Resolve(EffectIds.NavigationBar));
		}

		static void DetachEffect(FormsElement element)
		{
			IElementController controller = element;
			if (controller is null || !controller.EffectIsAttached(EffectIds.NavigationBar))
				return;

			var toRemove = element.Effects.FirstOrDefault(e => e.ResolveId == Effect.Resolve(EffectIds.NavigationBar).ResolveId);
			if (toRemove != null)
				element.Effects.Remove(toRemove);
		}
	}
}

Usage Syntax

XAML Usage

<Setter Property="droid:NavigationBarEffect.Color" Value="{StaticResource NavBarColor}" />

C# Usage

var navigationPage = new NavigationPage();
NavigationBarEffect.SetColor(navigationPage, Colors.Blue);

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
pictoscommented, Sep 7, 2022

@maxkoshevoi we will vote to champion this after the Status bar implementation

0reactions
maxkoshevoicommented, Sep 7, 2022

Since it seems like https://github.com/CommunityToolkit/Maui/issues/85#issuecomment-1239441230 is getting some traction, could this one be moved forward as well?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Proposal] Change system navigation bar to match UI #10695
I expected the system navigation bar (on the bottom of the screen) to adapt to the color of the UI, particularly the bottom...
Read more >
Hide the navigation bar
This lesson describes how to hide the navigation bar, which was introduced in Android 4.0 (API level 14). Even though this lesson focuses...
Read more >
Bottom navigation bar - ripple effect over system navigation
I tried to make system navigation bar transparent but ripple effect was still cropped. Any hint what should I set or where is...
Read more >
Top Navigation Bar | Search & Grow
Dubsado proposals have a huge advantage over other CRM platforms — the ... Generator for a custom Top Navigation Bar for your Dubsado...
Read more >
Proposal: Navigation menu block design - Make WordPress
It relies on a pre-existing understanding of the model WordPress uses to organise menus and doesn't map to users' understanding of how ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found