[Proposal] Android-Specific Navigation Bar Effect
See original GitHub issueNavigationBarEffect
- 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:
- Created 2 years ago
- Reactions:4
- Comments:6 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@maxkoshevoi we will vote to champion this after the Status bar implementation
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?