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
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 656f0d0
Update to Android 11
maxkoshevoi 3c6689c
Add OnElementPropertyChanged
maxkoshevoi c26ee4b
Refactor GetWindow a bit
maxkoshevoi d53959c
Add dummy implementations for iOS and UWP
maxkoshevoi 2b95d86
Update Xamarin.CommunityToolkit.csproj
maxkoshevoi 95202c2
Update Xamarin.CommunityToolkit.csproj
maxkoshevoi b2289c0
Fixed get Activity property
pictos b95e455
Merge branch 'develop' into bar-color
maxkoshevoi 8514b1c
Update PlatformBarStyle.android.cs
maxkoshevoi 20c8119
Remove NavigationBar bits
maxkoshevoi 9519155
Make SetStatusBarColor available on API 23+
maxkoshevoi 8877174
Make StatusBar white for demo app
maxkoshevoi a502e3f
Rename BarStyle to Window
maxkoshevoi eda8cd5
Merge branch 'develop' into bar-color
maxkoshevoi a850ed0
Fix spaces
maxkoshevoi 44a1332
Revert "Update to Android 11"
maxkoshevoi a374e70
Update Xamarin.CommunityToolkit.csproj
maxkoshevoi a5c7f71
Rename Window to WindowEffect
maxkoshevoi 38e872a
Revert Android 11 API support
maxkoshevoi b2b3d77
Set status bar style in app.xaml
maxkoshevoi 54c5e54
Replaced Window with WindowEffect is other places
maxkoshevoi 397a558
Remove Detached implementation
maxkoshevoi 37c9d3a
Add WindowEffectAndroid for navigation bar stuff
maxkoshevoi 62ceba6
Refactor SetBarStyle methods
maxkoshevoi f671e8f
Add UWP implementation
maxkoshevoi 704e887
Add iOS implemetation (not tested)
maxkoshevoi 6624d1d
Use switch expression
maxkoshevoi be65982
Merge branch 'develop' into bar-color
maxkoshevoi cd1d326
Add `#region` to specify Linker Work-Around
maxkoshevoi 7974f6b
Rename WindowEffect to StatusBarEffect
maxkoshevoi f83d69d
Rename WindowEffectAndroid to PlatformNavigationBarEffect
maxkoshevoi 9d5646d
Merge branch 'develop' into pr/812
brminnick 94d3428
Fix nullability errors
maxkoshevoi f207c74
Commit to rerun tests
maxkoshevoi 32fa472
Revert "Commit to rerun tests"
maxkoshevoi 77bdb83
Add sample page
maxkoshevoi 9c11974
Fix default is not applied on Android
maxkoshevoi 3127b90
Fix radiobutton name on sample page
maxkoshevoi 857c09e
Merge branch 'develop' into bar-color
brminnick 1396fef
Merge branch 'develop' into bar-color
brminnick 009e921
Merge branch 'develop' into bar-color
jsuarezruiz 7a34a78
Add android specific NavigationBar class
maxkoshevoi a63e626
Remove unneeded null checks
maxkoshevoi c3caa32
Coverted StatusBarEffect to static class
maxkoshevoi f490303
Improve description
maxkoshevoi 986629d
Update EffectIds.shared.cs
maxkoshevoi 9681fbd
Merge branch 'develop' into bar-color
maxkoshevoi 3270825
Remove unneeded activity parameter
maxkoshevoi d296d38
Refactor StatusBar.uwp
maxkoshevoi e70a16d
Setting view model in XAML
maxkoshevoi a1ea3b0
Update NavigationBar.android.cs
maxkoshevoi 05b4cb9
Make StatusBar style setters accessible from C#
maxkoshevoi 42ef3d8
Merge branch 'develop' into bar-color
maxkoshevoi 8eedf41
Merge branch 'develop' into bar-color
maxkoshevoi 2d63455
Add XML documentation
maxkoshevoi 82ac62b
Remove unrelated code
maxkoshevoi 1c6d4ba
Move constant outside the loop
maxkoshevoi 9c906c8
Add logs if bar style is not supported
maxkoshevoi 9a0849c
Remove LightContent case
maxkoshevoi a49e18f
Commit to rerun build
maxkoshevoi c9b3d5b
Revert "Commit to rerun build"
maxkoshevoi 7152b25
Revert "Revert "Commit to rerun build""
maxkoshevoi d440274
Revert "Revert "Revert "Commit to rerun build"""
maxkoshevoi 9d2c58c
Merge branch 'develop' into bar-color
brminnick a1fa95f
Merge branch 'develop' into bar-color
brminnick 17e2207
Merge branch 'develop' into bar-color
brminnick 136a3d6
Merge branch 'develop' into bar-color
pictos 02c3b67
Merge branch 'develop' into bar-color
maxkoshevoi 789de33
Merge branch 'develop' into bar-color
maxkoshevoi bcc4e7d
Merge branch 'develop' into bar-color
pictos d81aaea
Merge branch 'develop' into bar-color
maxkoshevoi 79ded40
Change Debug to Trace
maxkoshevoi 0c946c7
Replace Trace with Log
maxkoshevoi 6d37b50
Update src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfigur…
maxkoshevoi c56f02b
Update src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfigur…
maxkoshevoi 0976993
Revert "Update src/CommunityToolkit/Xamarin.CommunityToolkit/Platform…
maxkoshevoi f815d77
Revert "Update src/CommunityToolkit/Xamarin.CommunityToolkit/Platform…
maxkoshevoi 605fc5e
Move enums to sepparate files
maxkoshevoi 9495e9e
Replace linq with methods
maxkoshevoi e2d7b2d
Merge branch 'develop' into bar-color
maxkoshevoi bc7c8ad
Update UpdateStatusBarAppearance to support iOS 13
maxkoshevoi 65786f5
View controller-based status bar appearance: No
maxkoshevoi ca12ac5
Commit to rerun tests
maxkoshevoi a1e14a7
Merge branch 'develop' into bar-color
maxkoshevoi bcae91d
Merge branch 'develop' into bar-color
maxkoshevoi 5626659
Merge branch 'develop' into bar-color
maxkoshevoi 04e2e8b
Merge branch 'develop' into bar-color
maxkoshevoi 6b05b27
Update EffectsGalleryViewModel.cs
maxkoshevoi 682e82d
Move files to Effects folder
maxkoshevoi c422ac3
Converted BarStyle to effects
maxkoshevoi d28fa48
Update sample app
maxkoshevoi 4b528c4
Drop Windows Mobile support
maxkoshevoi b79a1e6
Get activity from control
maxkoshevoi 7ebd4bb
Update NavigationBarEffect.shared.cs
maxkoshevoi 84147ea
Commit to rerun tests
maxkoshevoi 3cf3fb6
Merge branch 'develop' into bar-color
maxkoshevoi 86d757d
Merge branch 'develop' into bar-color
maxkoshevoi 5a3c5fe
Merge branch 'develop' into bar-color
maxkoshevoi 6ae63d9
Merge branch 'develop' into bar-color
maxkoshevoi 4530973
refactoring ios
pictos 9413ed7
removed UWP linker hack
pictos f086ce6
Removed not needed properties
maxkoshevoi 94e2a4c
Remove not needed null checks
maxkoshevoi 34f0450
Remove using
maxkoshevoi 1787a1f
Merge branch 'develop' into bar-color
maxkoshevoi 87ce63b
Merge branch 'develop' into bar-color
maxkoshevoi 5def0a1
Merge branch 'develop' into bar-color
maxkoshevoi e729c3a
Merge branch 'develop' into bar-color
maxkoshevoi f1efb13
Merge branch 'develop' into bar-color
maxkoshevoi ae925e6
Merge branch 'develop' into bar-color
maxkoshevoi 4f31745
Merge branch 'develop' into bar-color
maxkoshevoi abec398
Merge branch 'develop' into bar-color
pictos dbd9a48
Merge branch 'develop' into bar-color
maxkoshevoi 53d28a2
Merge branch 'develop' into bar-color
maxkoshevoi c49a521
Merge branch 'develop' into bar-color
maxkoshevoi c089dd5
Merge branch 'develop' into bar-color
maxkoshevoi 049bf63
Merge branch 'develop' into bar-color
maxkoshevoi 3de2a3f
Merge branch 'develop' into bar-color
maxkoshevoi a389337
Merge branch 'develop' into bar-color
maxkoshevoi 154241e
Commit to rerun tests
maxkoshevoi 06c4492
Merge branch 'develop' into bar-color
maxkoshevoi 5b76758
Moved NavigationBarEffect to use the platformspecific API
pictos 80fbf29
Updated the sample
pictos ce2a355
Fix test
jfversluis bc1a467
Little better styling
jfversluis File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Xamarin.CommunityToolkit.Sample.Pages.Effects | ||
{ | ||
public partial class StatusBarEffectPage | ||
{ | ||
public StatusBarEffectPage() => InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
samples/XCT.Sample/ViewModels/Effects/StatusBarEffectViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/StatusBar/BarStyle.android.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...mmunityToolkit/Xamarin.CommunityToolkit/Effects/StatusBar/Models/StatusBarStyle.shared.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Xamarin.CommunityToolkit.Effects | ||
{ | ||
public enum StatusBarStyle | ||
{ | ||
Default = 0, | ||
LightContent = 1, | ||
DarkContent = 2 | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...nityToolkit/Xamarin.CommunityToolkit/Effects/StatusBar/PlatformStatusBarEffect.android.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A friendly reminder to add this configuration on docs.
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 don't think there are docs for this feature yet
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 know, but just to remember us to add it there