mirror of
https://github.com/bitwarden/mobile
synced 2025-12-16 00:03:22 +00:00
Dynamic theme switching and visual tweaks (#1556)
* Dynamic theme switching and visual tweaks * update action runner to use macos-11 for iOS 15 support * additional tweaks * refinements * refinements * formatting and tweaks
This commit is contained in:
@@ -1,17 +1,68 @@
|
||||
using Bit.iOS.Core.Renderers;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.iOS.Core.Renderers;
|
||||
using Bit.iOS.Core.Utilities;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
|
||||
[assembly: ExportRenderer(typeof(TabbedPage), typeof(CustomTabbedRenderer))]
|
||||
|
||||
namespace Bit.iOS.Core.Renderers
|
||||
{
|
||||
public class CustomTabbedRenderer : TabbedRenderer
|
||||
{
|
||||
private IBroadcasterService _broadcasterService;
|
||||
|
||||
public CustomTabbedRenderer()
|
||||
{
|
||||
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
||||
_broadcasterService.Subscribe(nameof(CustomTabbedRenderer), async (message) =>
|
||||
{
|
||||
if (message.Command == "updatedTheme")
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
iOSCoreHelpers.AppearanceAdjustments();
|
||||
UpdateTabBarAppearance();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnElementChanged(VisualElementChangedEventArgs e)
|
||||
{
|
||||
base.OnElementChanged(e);
|
||||
TabBar.Translucent = false;
|
||||
TabBar.Opaque = true;
|
||||
UpdateTabBarAppearance();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_broadcasterService.Unsubscribe(nameof(CustomTabbedRenderer));
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void UpdateTabBarAppearance()
|
||||
{
|
||||
// https://developer.apple.com/forums/thread/682420
|
||||
var deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||
if (deviceActionService.SystemMajorVersion() >= 15)
|
||||
{
|
||||
var appearance = new UITabBarAppearance();
|
||||
appearance.ConfigureWithOpaqueBackground();
|
||||
appearance.BackgroundColor = ThemeHelpers.TabBarBackgroundColor;
|
||||
appearance.StackedLayoutAppearance.Normal.IconColor = ThemeHelpers.TabBarItemColor;
|
||||
appearance.StackedLayoutAppearance.Normal.TitleTextAttributes =
|
||||
new UIStringAttributes { ForegroundColor = ThemeHelpers.TabBarItemColor };
|
||||
TabBar.StandardAppearance = appearance;
|
||||
TabBar.ScrollEdgeAppearance = TabBar.StandardAppearance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user