Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Add StatusBarEffect and NavigationBarEffect classes to manage their color and style #812

Merged
merged 126 commits into from Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
dea0f1e
Sample Android implementation (doesn't work)
maxkoshevoi Jan 29, 2021
656f0d0
Update to Android 11
maxkoshevoi Jan 29, 2021
3c6689c
Add OnElementPropertyChanged
maxkoshevoi Jan 29, 2021
c26ee4b
Refactor GetWindow a bit
maxkoshevoi Jan 29, 2021
d53959c
Add dummy implementations for iOS and UWP
maxkoshevoi Jan 29, 2021
2b95d86
Update Xamarin.CommunityToolkit.csproj
maxkoshevoi Jan 29, 2021
95202c2
Update Xamarin.CommunityToolkit.csproj
maxkoshevoi Jan 29, 2021
b2289c0
Fixed get Activity property
pictos Jan 30, 2021
b95e455
Merge branch 'develop' into bar-color
maxkoshevoi Jan 30, 2021
8514b1c
Update PlatformBarStyle.android.cs
maxkoshevoi Feb 10, 2021
20c8119
Remove NavigationBar bits
maxkoshevoi Feb 10, 2021
9519155
Make SetStatusBarColor available on API 23+
maxkoshevoi Feb 10, 2021
8877174
Make StatusBar white for demo app
maxkoshevoi Feb 10, 2021
a502e3f
Rename BarStyle to Window
maxkoshevoi Feb 10, 2021
eda8cd5
Merge branch 'develop' into bar-color
maxkoshevoi Feb 10, 2021
a850ed0
Fix spaces
maxkoshevoi Feb 10, 2021
44a1332
Revert "Update to Android 11"
maxkoshevoi Feb 14, 2021
a374e70
Update Xamarin.CommunityToolkit.csproj
maxkoshevoi Feb 14, 2021
a5c7f71
Rename Window to WindowEffect
maxkoshevoi Feb 14, 2021
38e872a
Revert Android 11 API support
maxkoshevoi Feb 14, 2021
b2b3d77
Set status bar style in app.xaml
maxkoshevoi Feb 14, 2021
54c5e54
Replaced Window with WindowEffect is other places
maxkoshevoi Feb 14, 2021
397a558
Remove Detached implementation
maxkoshevoi Feb 14, 2021
37c9d3a
Add WindowEffectAndroid for navigation bar stuff
maxkoshevoi Feb 15, 2021
62ceba6
Refactor SetBarStyle methods
maxkoshevoi Feb 15, 2021
f671e8f
Add UWP implementation
maxkoshevoi Feb 15, 2021
704e887
Add iOS implemetation (not tested)
maxkoshevoi Feb 15, 2021
6624d1d
Use switch expression
maxkoshevoi Feb 16, 2021
be65982
Merge branch 'develop' into bar-color
maxkoshevoi Feb 22, 2021
cd1d326
Add `#region` to specify Linker Work-Around
maxkoshevoi Feb 22, 2021
7974f6b
Rename WindowEffect to StatusBarEffect
maxkoshevoi Feb 26, 2021
f83d69d
Rename WindowEffectAndroid to PlatformNavigationBarEffect
maxkoshevoi Feb 26, 2021
9d5646d
Merge branch 'develop' into pr/812
brminnick Mar 9, 2021
94d3428
Fix nullability errors
maxkoshevoi Mar 9, 2021
f207c74
Commit to rerun tests
maxkoshevoi Mar 9, 2021
32fa472
Revert "Commit to rerun tests"
maxkoshevoi Mar 10, 2021
77bdb83
Add sample page
maxkoshevoi Mar 11, 2021
9c11974
Fix default is not applied on Android
maxkoshevoi Mar 11, 2021
3127b90
Fix radiobutton name on sample page
maxkoshevoi Mar 11, 2021
857c09e
Merge branch 'develop' into bar-color
brminnick Mar 18, 2021
1396fef
Merge branch 'develop' into bar-color
brminnick Mar 18, 2021
009e921
Merge branch 'develop' into bar-color
jsuarezruiz Mar 19, 2021
7a34a78
Add android specific NavigationBar class
maxkoshevoi Mar 19, 2021
a63e626
Remove unneeded null checks
maxkoshevoi Mar 19, 2021
c3caa32
Coverted StatusBarEffect to static class
maxkoshevoi Mar 19, 2021
f490303
Improve description
maxkoshevoi Mar 19, 2021
986629d
Update EffectIds.shared.cs
maxkoshevoi Mar 20, 2021
9681fbd
Merge branch 'develop' into bar-color
maxkoshevoi Mar 20, 2021
3270825
Remove unneeded activity parameter
maxkoshevoi Mar 20, 2021
d296d38
Refactor StatusBar.uwp
maxkoshevoi Mar 21, 2021
e70a16d
Setting view model in XAML
maxkoshevoi Mar 22, 2021
a1ea3b0
Update NavigationBar.android.cs
maxkoshevoi Mar 22, 2021
05b4cb9
Make StatusBar style setters accessible from C#
maxkoshevoi Mar 22, 2021
42ef3d8
Merge branch 'develop' into bar-color
maxkoshevoi Mar 22, 2021
8eedf41
Merge branch 'develop' into bar-color
maxkoshevoi Mar 25, 2021
2d63455
Add XML documentation
maxkoshevoi Mar 26, 2021
82ac62b
Remove unrelated code
maxkoshevoi Apr 1, 2021
1c6d4ba
Move constant outside the loop
maxkoshevoi Apr 1, 2021
9c906c8
Add logs if bar style is not supported
maxkoshevoi Apr 1, 2021
9a0849c
Remove LightContent case
maxkoshevoi Apr 1, 2021
a49e18f
Commit to rerun build
maxkoshevoi Apr 1, 2021
c9b3d5b
Revert "Commit to rerun build"
maxkoshevoi Apr 1, 2021
7152b25
Revert "Revert "Commit to rerun build""
maxkoshevoi Apr 1, 2021
d440274
Revert "Revert "Revert "Commit to rerun build"""
maxkoshevoi Apr 2, 2021
9d2c58c
Merge branch 'develop' into bar-color
brminnick Apr 5, 2021
a1fa95f
Merge branch 'develop' into bar-color
brminnick Apr 6, 2021
17e2207
Merge branch 'develop' into bar-color
brminnick Apr 8, 2021
136a3d6
Merge branch 'develop' into bar-color
pictos Apr 10, 2021
02c3b67
Merge branch 'develop' into bar-color
maxkoshevoi Apr 11, 2021
789de33
Merge branch 'develop' into bar-color
maxkoshevoi Apr 13, 2021
bcc4e7d
Merge branch 'develop' into bar-color
pictos Apr 13, 2021
d81aaea
Merge branch 'develop' into bar-color
maxkoshevoi Apr 14, 2021
79ded40
Change Debug to Trace
maxkoshevoi Apr 14, 2021
0c946c7
Replace Trace with Log
maxkoshevoi Apr 14, 2021
6d37b50
Update src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfigur…
maxkoshevoi Apr 14, 2021
c56f02b
Update src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfigur…
maxkoshevoi Apr 14, 2021
0976993
Revert "Update src/CommunityToolkit/Xamarin.CommunityToolkit/Platform…
maxkoshevoi Apr 14, 2021
f815d77
Revert "Update src/CommunityToolkit/Xamarin.CommunityToolkit/Platform…
maxkoshevoi Apr 14, 2021
605fc5e
Move enums to sepparate files
maxkoshevoi Apr 14, 2021
9495e9e
Replace linq with methods
maxkoshevoi Apr 14, 2021
e2d7b2d
Merge branch 'develop' into bar-color
maxkoshevoi Apr 14, 2021
bc7c8ad
Update UpdateStatusBarAppearance to support iOS 13
maxkoshevoi Apr 15, 2021
65786f5
View controller-based status bar appearance: No
maxkoshevoi Apr 15, 2021
ca12ac5
Commit to rerun tests
maxkoshevoi Apr 15, 2021
a1e14a7
Merge branch 'develop' into bar-color
maxkoshevoi Apr 16, 2021
bcae91d
Merge branch 'develop' into bar-color
maxkoshevoi Apr 24, 2021
5626659
Merge branch 'develop' into bar-color
maxkoshevoi May 1, 2021
04e2e8b
Merge branch 'develop' into bar-color
maxkoshevoi May 7, 2021
6b05b27
Update EffectsGalleryViewModel.cs
maxkoshevoi May 9, 2021
682e82d
Move files to Effects folder
maxkoshevoi May 9, 2021
c422ac3
Converted BarStyle to effects
maxkoshevoi May 9, 2021
d28fa48
Update sample app
maxkoshevoi May 9, 2021
4b528c4
Drop Windows Mobile support
maxkoshevoi May 9, 2021
b79a1e6
Get activity from control
maxkoshevoi May 9, 2021
7ebd4bb
Update NavigationBarEffect.shared.cs
maxkoshevoi May 9, 2021
84147ea
Commit to rerun tests
maxkoshevoi May 10, 2021
3cf3fb6
Merge branch 'develop' into bar-color
maxkoshevoi May 10, 2021
86d757d
Merge branch 'develop' into bar-color
maxkoshevoi May 11, 2021
5a3c5fe
Merge branch 'develop' into bar-color
maxkoshevoi May 14, 2021
6ae63d9
Merge branch 'develop' into bar-color
maxkoshevoi May 15, 2021
4530973
refactoring ios
pictos May 15, 2021
9413ed7
removed UWP linker hack
pictos May 15, 2021
f086ce6
Removed not needed properties
maxkoshevoi May 16, 2021
94e2a4c
Remove not needed null checks
maxkoshevoi May 16, 2021
34f0450
Remove using
maxkoshevoi May 16, 2021
1787a1f
Merge branch 'develop' into bar-color
maxkoshevoi May 16, 2021
87ce63b
Merge branch 'develop' into bar-color
maxkoshevoi May 16, 2021
5def0a1
Merge branch 'develop' into bar-color
maxkoshevoi May 17, 2021
e729c3a
Merge branch 'develop' into bar-color
maxkoshevoi May 21, 2021
f1efb13
Merge branch 'develop' into bar-color
maxkoshevoi Jun 2, 2021
ae925e6
Merge branch 'develop' into bar-color
maxkoshevoi Jun 5, 2021
4f31745
Merge branch 'develop' into bar-color
maxkoshevoi Jun 7, 2021
abec398
Merge branch 'develop' into bar-color
pictos Jun 8, 2021
dbd9a48
Merge branch 'develop' into bar-color
maxkoshevoi Jun 14, 2021
53d28a2
Merge branch 'develop' into bar-color
maxkoshevoi Jun 18, 2021
c49a521
Merge branch 'develop' into bar-color
maxkoshevoi Jun 18, 2021
c089dd5
Merge branch 'develop' into bar-color
maxkoshevoi Jun 20, 2021
049bf63
Merge branch 'develop' into bar-color
maxkoshevoi Jun 21, 2021
3de2a3f
Merge branch 'develop' into bar-color
maxkoshevoi Jun 22, 2021
a389337
Merge branch 'develop' into bar-color
maxkoshevoi Jun 25, 2021
154241e
Commit to rerun tests
maxkoshevoi Jun 25, 2021
06c4492
Merge branch 'develop' into bar-color
maxkoshevoi Jun 28, 2021
5b76758
Moved NavigationBarEffect to use the platformspecific API
pictos Jun 30, 2021
80fbf29
Updated the sample
pictos Jun 30, 2021
ce2a355
Fix test
jfversluis Jun 30, 2021
bc1a467
Little better styling
jfversluis Jun 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions samples/XCT.Sample.iOS/Info.plist
Expand Up @@ -46,5 +46,7 @@
<array>
<string>audio</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Comment on lines +49 to +50
Copy link
Contributor

Choose a reason for hiding this comment

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

A friendly reminder to add this configuration on docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there are docs for this feature yet

Copy link
Contributor

Choose a reason for hiding this comment

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

I know, but just to remember us to add it there

</dict>
</plist>
21 changes: 16 additions & 5 deletions samples/XCT.Sample/App.xaml
Expand Up @@ -5,8 +5,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:custom="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:droid="clr-namespace:Xamarin.CommunityToolkit.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.CommunityToolkit"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
mc:Ignorable="d">
<Application.Resources>
<!-- Values -->
Expand All @@ -23,7 +25,8 @@
<Color x:Key="DarkLabelTextColor">#000000</Color>
<Color x:Key="DarkLabelPlaceholderColor">#333d47</Color>
<Color x:Key="SoftFrameBackgroundColor">#ecf0f9</Color>

<Color x:Key="StatusbarColor">#1976D2</Color>
<Color x:Key="NavBarColor">#1976D2</Color>
<!-- Fonts -->
<OnPlatform x:Key="font_bold" x:TypeArguments="x:String">
<On Platform="iOS" Value=".SFUIText-Bold" />
Expand Down Expand Up @@ -56,6 +59,10 @@
<Setter Property="BackgroundColor" Value="{StaticResource AppBackgroundColor}" />
<Setter Property="ios:Page.UseSafeArea" Value="False" />
<Setter Property="NavigationPage.BackButtonTitle" Value="" />
<Setter Property="xct:StatusBarEffect.Color" Value="{StaticResource StatusbarColor}" />
<Setter Property="xct:StatusBarEffect.Style" Value="DarkContent" />
<Setter Property="droid:NavigationBarEffect.Color" Value="{StaticResource NavBarColor}" />
<Setter Property="droid:NavigationBarEffect.Style" Value="LightContent" />
</Style>

<Style TargetType="Button">
Expand Down Expand Up @@ -96,7 +103,11 @@
<!-- Content templates -->
<ControlTemplate x:Key="GalleryPageTemplate">
<StackLayout Spacing="0">
<ListView ItemsSource="{TemplateBinding BindingContext.FilteredItems}" SelectionMode="None" HasUnevenRows="True" SeparatorVisibility="None">
<ListView
HasUnevenRows="True"
ItemsSource="{TemplateBinding BindingContext.FilteredItems}"
SelectionMode="None"
SeparatorVisibility="None">
<ListView.Header>
<ContentView Padding="20,12">
<Entry
Expand Down Expand Up @@ -127,9 +138,9 @@
</Grid.ColumnDefinitions>
<BoxView BackgroundColor="{Binding DetailColor, Source={x:RelativeSource AncestorType={x:Type ContentPage}}}" />
<StackLayout
Grid.Column="1"
Padding="0,24,24,24"
Spacing="8">
Grid.Column="1"
Padding="0,24,24,24"
Spacing="8">
<Label Style="{StaticResource label_section_header}" Text="{Binding Title}" />
<Label Text="{Binding Description}" />
</StackLayout>
Expand Down
61 changes: 61 additions & 0 deletions samples/XCT.Sample/Pages/Effects/StatusBarEffectPage.xaml
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" ?>
<pages:BasePage
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Effects.StatusBarEffectPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:droid="clr-namespace:Xamarin.CommunityToolkit.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.CommunityToolkit"
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
xmlns:vm="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.Effects"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
droid:NavigationBarEffect.Color="{Binding StatusBarColor}"
droid:NavigationBarEffect.Style="{Binding NavigationBarStyle}"
xct:StatusBarEffect.Color="{Binding StatusBarColor}"
xct:StatusBarEffect.Style="{Binding StatusBarStyle}">

<pages:BasePage.BindingContext>
<vm:StatusBarEffectViewModel />
</pages:BasePage.BindingContext>

<ScrollView Padding="{StaticResource ContentPadding}">
<StackLayout Padding="15,0" Spacing="30">

<Label Text="NavigationBar supported only on Android" />
<Label Text="Slide to change StatusBar and NavigationBar color" />

<Slider
Margin="20,10"
Maximum="255"
MaximumTrackColor="Red"
Minimum="0"
MinimumTrackColor="Red"
ThumbColor="Red"
Value="{Binding RedSliderValue}" />

<Slider
Margin="20,10"
Maximum="255"
MaximumTrackColor="Green"
Minimum="0"
MinimumTrackColor="Green"
ThumbColor="Green"
Value="{Binding GreenSliderValue}" />

<Slider
Margin="20,10"
Maximum="255"
MaximumTrackColor="Blue"
Minimum="0"
MinimumTrackColor="Blue"
ThumbColor="Blue"
Value="{Binding BlueSliderValue}" />

<StackLayout Spacing="15">
<Label Text="Select StatusBar and NavigationBar style" />
<RadioButton Content="Default" IsChecked="{Binding IsDefaultChecked}" />
<RadioButton Content="Light content" IsChecked="{Binding IsLightContentChecked}" />
<RadioButton Content="Dark content" IsChecked="{Binding IsDarkContentChecked}" />
</StackLayout>

</StackLayout>
</ScrollView>
</pages:BasePage>
7 changes: 7 additions & 0 deletions samples/XCT.Sample/Pages/Effects/StatusBarEffectPage.xaml.cs
@@ -0,0 +1,7 @@
namespace Xamarin.CommunityToolkit.Sample.Pages.Effects
{
public partial class StatusBarEffectPage
{
public StatusBarEffectPage() => InitializeComponent();
}
}
Expand Up @@ -47,7 +47,12 @@ public class EffectsGalleryViewModel : BaseGalleryViewModel
new SectionModel(
typeof(SemanticEffectPage),
nameof(SemanticEffect),
"The SemanticEffect allows you to set semantic properties for accessibility.")
"The SemanticEffect allows you to set semantic properties for accessibility."),

new SectionModel(
typeof(StatusBarEffectPage),
nameof(StatusBarEffect),
"The StatusBar allows to change status bar color and style. This page also demonstrates Android only NavigationBar changes.")
};
}
}
83 changes: 83 additions & 0 deletions samples/XCT.Sample/ViewModels/Effects/StatusBarEffectViewModel.cs
@@ -0,0 +1,83 @@
using System;
using Xamarin.CommunityToolkit.Effects;
using Xamarin.CommunityToolkit.PlatformConfiguration.AndroidSpecific;
using Xamarin.Forms;

namespace Xamarin.CommunityToolkit.Sample.ViewModels.Effects
{
public class StatusBarEffectViewModel : BaseViewModel
{
int redSliderValue;
int greanSliderValue;
int blueSliderValue;
bool isDefaultChecked = true;
bool isLightContentChecked;
bool isDarkContentChecked;

public Color StatusBarColor => Color.FromRgb(RedSliderValue, GreenSliderValue, BlueSliderValue);

public StatusBarStyle StatusBarStyle
{
get
{
if (IsDefaultChecked)
{
return StatusBarStyle.Default;
}
if (IsLightContentChecked)
{
return StatusBarStyle.LightContent;
}
if (IsDarkContentChecked)
{
return StatusBarStyle.DarkContent;
}
throw new InvalidOperationException("Style is not selected");
}
}

public NavigationBarStyle NavigationBarStyle => (NavigationBarStyle)(int)StatusBarStyle;

public int RedSliderValue
{
get => redSliderValue;
set => SetProperty(ref redSliderValue, value, onChanged: () => OnPropertyChanged(nameof(StatusBarColor)));
}

public int GreenSliderValue
{
get => greanSliderValue;
set => SetProperty(ref greanSliderValue, value, onChanged: () => OnPropertyChanged(nameof(StatusBarColor)));
}

public int BlueSliderValue
{
get => blueSliderValue;
set => SetProperty(ref blueSliderValue, value, onChanged: () => OnPropertyChanged(nameof(StatusBarColor)));
}

public bool IsDefaultChecked
{
get => isDefaultChecked;
set => SetProperty(ref isDefaultChecked, value, onChanged: NotifyStyleChanged);
}

public bool IsLightContentChecked
{
get => isLightContentChecked;
set => SetProperty(ref isLightContentChecked, value, onChanged: NotifyStyleChanged);
}

public bool IsDarkContentChecked
{
get => isDarkContentChecked;
set => SetProperty(ref isDarkContentChecked, value, onChanged: NotifyStyleChanged);
}

void NotifyStyleChanged()
{
OnPropertyChanged(nameof(StatusBarStyle));
OnPropertyChanged(nameof(NavigationBarStyle));
}
}
}
Expand Up @@ -30,6 +30,9 @@ public void MakeSureEffectsAreInTheRightNamespace()
{
var allTheTypes = Assembly.GetAssembly(typeof(SafeAreaEffect))?.GetTypes() ?? throw new NullReferenceException();

// Filter out the platform-specific ones, i.e. AndroidSpecific or iOSSpecific
allTheTypes = allTheTypes.Except(allTheTypes.Where(t => t.Namespace.EndsWith("Specific"))).ToArray();

foreach (var type in allTheTypes.Where(t => t.Name.EndsWith("Effect") && t.IsClass && t.IsSealed && t.IsAbstract))
{
Assert.IsTrue(type?.Namespace?.Equals("Xamarin.CommunityToolkit.Effects"),
Expand Down
@@ -1,4 +1,5 @@
using Xamarin.Forms;
using Xamarin.CommunityToolkit.PlatformConfiguration.AndroidSpecific;
using Xamarin.Forms;

[assembly: ResolutionGroupName("Xamarin.CommunityToolkit.Effects")]

Expand Down Expand Up @@ -55,5 +56,14 @@ sealed class EffectIds
/// Effect Id for <see cref="SemanticEffect"/>
/// </summary>
public static string Semantic => $"{effectResolutionGroupName}.{nameof(SemanticEffectRouter)}";

/// Effect Id for <see cref="StatusBarEffect"/>
/// </summary>
public static string StatusBar => $"{effectResolutionGroupName}.{nameof(StatusBarEffect)}";

/// <summary>
/// Effect Id for <see cref="NavigationBarEffect"/>
/// </summary>
public static string NavigationBar => $"{effectResolutionGroupName}.{nameof(NavigationBarEffect)}";
}
}
@@ -0,0 +1,44 @@
using System;
using Android.App;
using Android.OS;
using Android.Views;
using Xamarin.Forms.Internals;

namespace Xamarin.CommunityToolkit.Effects
{
static class BarStyle
{
internal static bool IsSupported()
{
if (Build.VERSION.SdkInt < BuildVersionCodes.M)
{
Log.Warning(string.Empty, $"This functionality is not available. Minimum supported API is {BuildVersionCodes.M}");
return false;
}

return true;
}
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved

internal static void AddBarAppearanceFlag(Activity activity, StatusBarVisibility flag) =>
SetBarAppearance(activity, barAppearance => barAppearance |= flag);

internal static void RemoveBarAppearanceFlag(Activity activity, StatusBarVisibility flag) =>
SetBarAppearance(activity, barAppearance => barAppearance &= ~flag);

static void SetBarAppearance(Activity activity, Func<StatusBarVisibility, StatusBarVisibility> updateAppearance)
{
var window = GetCurrentWindow(activity);
var appearance = window.DecorView.SystemUiVisibility;
appearance = updateAppearance(appearance);
window.DecorView.SystemUiVisibility = appearance;
}

internal static Window GetCurrentWindow(Activity activity)
{
var window = activity.Window ?? throw new NullReferenceException();
window.ClearFlags(WindowManagerFlags.TranslucentStatus);
window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
return window;
}
}
}
@@ -0,0 +1,9 @@
namespace Xamarin.CommunityToolkit.Effects
{
public enum StatusBarStyle
{
Default = 0,
LightContent = 1,
DarkContent = 2
}
}
@@ -0,0 +1,72 @@
using System.ComponentModel;
using Android.Views;
using Xamarin.CommunityToolkit.Android.Effects;
using Xamarin.CommunityToolkit.Effects;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportEffect(typeof(PlatformStatusBarEffect), nameof(StatusBarEffect))]

namespace Xamarin.CommunityToolkit.Android.Effects
{
public class PlatformStatusBarEffect : PlatformEffect
{
protected override void OnAttached()
{
SetColor(StatusBarEffect.GetColor(Element));
SetStyle(StatusBarEffect.GetStyle(Element));
}

protected override void OnDetached()
{
}

protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
{
base.OnElementPropertyChanged(args);
if (args.PropertyName == StatusBarEffect.ColorProperty.PropertyName)
{
SetColor(StatusBarEffect.GetColor(Element));
}
else if (args.PropertyName == StatusBarEffect.StyleProperty.PropertyName)
{
SetStyle(StatusBarEffect.GetStyle(Element));
}
}

void SetColor(Color color)
{
if (!BarStyle.IsSupported())
return;

Activity.SetStatusBarColor(color.ToAndroid());
}

void SetStyle(StatusBarStyle style)
{
if (!BarStyle.IsSupported())
return;

switch (style)
{
case StatusBarStyle.DarkContent:
BarStyle.AddBarAppearanceFlag(Activity, (StatusBarVisibility)SystemUiFlags.LightStatusBar);
break;
default:
BarStyle.RemoveBarAppearanceFlag(Activity, (StatusBarVisibility)SystemUiFlags.LightStatusBar);
break;
}
}

FormsAppCompatActivity Activity
{
get
{
if (Control != null)
return (FormsAppCompatActivity)Control.Context!;
else
return (FormsAppCompatActivity)Container.Context!;
}
}
}
}