add support for dynamic theme update
This commit is contained in:
1 parent
f62a405979
commit
ff8cb20cae
10 files changed
+125
-17
No files matched your search
@@ -28,6 +28,6 @@
|
|||||||
- (void)resizeBySizeFactor:(CGFloat)factor;
|
- (void)resizeBySizeFactor:(CGFloat)factor;
|
||||||
- (id) initWithHost:(TemporaryHost*)host;
|
- (id) initWithHost:(TemporaryHost*)host;
|
||||||
- (id) initWithHost:(TemporaryHost*)host andSizeFactor:(CGFloat)sizeFactor;
|
- (id) initWithHost:(TemporaryHost*)host andSizeFactor:(CGFloat)sizeFactor;
|
||||||
|
- (void)updateTheme;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -431,7 +431,7 @@ static const float REFRESH_CYCLE = 2.0f;
|
|||||||
|
|
||||||
_size = CGSizeMake(_widthConstraint.constant, _heightConstraint.constant);
|
_size = CGSizeMake(_widthConstraint.constant, _heightConstraint.constant);
|
||||||
|
|
||||||
[self updateTheme:ThemeManager.userInterfaceStyle];
|
[self updateTheme];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)createBackgroundLayer{
|
- (void)createBackgroundLayer{
|
||||||
@@ -469,7 +469,7 @@ static const float REFRESH_CYCLE = 2.0f;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)updateTheme:(UIUserInterfaceStyle)userIterfaceStyle{
|
- (void)updateTheme {
|
||||||
self.backgroundColor = [ThemeManager widgetBackgroundColor];
|
self.backgroundColor = [ThemeManager widgetBackgroundColor];
|
||||||
_hostNameLabel.textColor = [ThemeManager textColor];
|
_hostNameLabel.textColor = [ThemeManager textColor];
|
||||||
[_appButton setTitleColor:[ThemeManager appPrimaryColor] forState:UIControlStateNormal];
|
[_appButton setTitleColor:[ThemeManager appPrimaryColor] forState:UIControlStateNormal];
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
extern NSString * const ThemeDidChangeNotification;
|
||||||
|
|
||||||
@interface ThemeManager:NSObject
|
@interface ThemeManager:NSObject
|
||||||
|
|
||||||
@property (class, nonatomic, assign) UIUserInterfaceStyle userInterfaceStyle;
|
@property (class, nonatomic, assign) UIUserInterfaceStyle userInterfaceStyle;
|
||||||
@@ -23,4 +25,3 @@
|
|||||||
+ (UIColor *)textTintColorWithAlpha;
|
+ (UIColor *)textTintColorWithAlpha;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#import "ThemeManager.h"
|
#import "ThemeManager.h"
|
||||||
|
|
||||||
|
NSString * const ThemeDidChangeNotification = @"ThemeDidChangeNotification";
|
||||||
|
|
||||||
@implementation ThemeManager
|
@implementation ThemeManager
|
||||||
|
|
||||||
static UIUserInterfaceStyle _privateUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
|
static UIUserInterfaceStyle _privateUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
|
||||||
@@ -34,8 +36,12 @@ static UIUserInterfaceStyle _userInterfaceStyle;
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ (void)setUserInterfaceStyle:(UIUserInterfaceStyle)style {
|
+ (void)setUserInterfaceStyle:(UIUserInterfaceStyle)style {
|
||||||
|
if (_userInterfaceStyle == style) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_privateUserInterfaceStyle = style;
|
_privateUserInterfaceStyle = style;
|
||||||
[ThemeManager getUIStyle];
|
[ThemeManager getUIStyle];
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:ThemeDidChangeNotification object:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (UIColor *)appBackgroundColor {
|
+ (UIColor *)appBackgroundColor {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
/// 添加一个 item
|
/// 添加一个 item
|
||||||
- (void)addHost:(TemporaryHost *)host;
|
- (void)addHost:(TemporaryHost *)host;
|
||||||
- (void)removeHost:(TemporaryHost *)host;
|
- (void)removeHost:(TemporaryHost *)host;
|
||||||
|
- (void)updateTheme;
|
||||||
|
|
||||||
/// 移除最后一个 item(如果有)
|
/// 移除最后一个 item(如果有)
|
||||||
- (void)removeLastItem;
|
- (void)removeLastItem;
|
||||||
|
|||||||
@@ -100,13 +100,28 @@ static const CGFloat cellOffsetY = 20;
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)updateTheme {
|
||||||
|
self.collectionView.backgroundColor = [ThemeManager appBackgroundColor];
|
||||||
|
for (HostCell *cell in [self.collectionView visibleCells]) {
|
||||||
|
[cell.cardView updateTheme];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
[self.collectionView registerClass:[HostCell class] forCellWithReuseIdentifier:@"HostCell"];
|
[self.collectionView registerClass:[HostCell class] forCellWithReuseIdentifier:@"HostCell"];
|
||||||
self.collectionView.alwaysBounceVertical = NO;
|
self.collectionView.alwaysBounceVertical = NO;
|
||||||
self.collectionView.showsVerticalScrollIndicator = NO;
|
self.collectionView.showsVerticalScrollIndicator = NO;
|
||||||
self.collectionView.backgroundColor = [ThemeManager appBackgroundColor];
|
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(updateTheme)
|
||||||
|
name:ThemeDidChangeNotification
|
||||||
|
object:nil];
|
||||||
|
[self updateTheme];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1481,10 +1481,45 @@ static NSMutableSet* hostList;
|
|||||||
[_upButton setAction:@selector(switchToHostView)];
|
[_upButton setAction:@selector(switchToHostView)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidLoad{
|
- (void)updateTheme {
|
||||||
[ThemeManager setUserInterfaceStyle:UIScreen.mainScreen.traitCollection.userInterfaceStyle];
|
self.view.backgroundColor = [ThemeManager appBackgroundColor];
|
||||||
|
self.hostCollectionVC.view.backgroundColor = [ThemeManager appBackgroundColor];
|
||||||
|
self.collectionView.backgroundColor = [ThemeManager appBackgroundColor];
|
||||||
|
|
||||||
|
if (@available(iOS 13.0, *)) {
|
||||||
|
[navBarAppearanceStandard setValue:[ThemeManager appBackgroundColor] forKey:@"backgroundColor"];
|
||||||
|
NSDictionary* titleTextAttributes = @{
|
||||||
|
NSForegroundColorAttributeName: [ThemeManager textColor]
|
||||||
|
};
|
||||||
|
[navBarAppearanceStandard setValue:titleTextAttributes forKey:@"titleTextAttributes"];
|
||||||
|
}
|
||||||
|
|
||||||
|
_settingsButton.tintColor = [ThemeManager appPrimaryColor];
|
||||||
|
_upButton.tintColor = [ThemeManager appPrimaryColor];
|
||||||
|
((UIButton*)_addHostButton.customView).backgroundColor = [ThemeManager appPrimaryColor];
|
||||||
|
((UIButton*)_helpButton.customView).tintColor = [ThemeManager appPrimaryColor];
|
||||||
|
|
||||||
|
[self applyNavBarAppearance];
|
||||||
|
[self updateTitle];
|
||||||
|
if (hostViewTitleLabel) {
|
||||||
|
hostViewTitleLabel.textColor = [ThemeManager textColor];
|
||||||
|
}
|
||||||
|
[self.hostCollectionVC updateTheme];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the system's theme (light/dark mode) changes
|
||||||
|
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
|
||||||
|
[super traitCollectionDidChange:previousTraitCollection];
|
||||||
|
if (@available(iOS 13.0, *)) {
|
||||||
|
if ([self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
|
||||||
|
[ThemeManager setUserInterfaceStyle:self.traitCollection.userInterfaceStyle];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)viewDidLoad{
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
//[OrientationHelper updateOrientationToLandscape];
|
//[OrientationHelper updateOrientationToLandscape];
|
||||||
// self.navigationController.delegate = self;
|
// self.navigationController.delegate = self;
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
@@ -1800,6 +1835,11 @@ static NSMutableSet* hostList;
|
|||||||
{
|
{
|
||||||
[super viewWillAppear:NO];
|
[super viewWillAppear:NO];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(updateTheme)
|
||||||
|
name:ThemeDidChangeNotification
|
||||||
|
object:nil];
|
||||||
|
|
||||||
/* this makes background color works*/
|
/* this makes background color works*/
|
||||||
|
|
||||||
if(!_settingsViewExpanded){
|
if(!_settingsViewExpanded){
|
||||||
@@ -1819,13 +1859,12 @@ static NSMutableSet* hostList;
|
|||||||
// this view via an error dialog from the stream
|
// this view via an error dialog from the stream
|
||||||
// view, so we won't get a return to active notification
|
// view, so we won't get a return to active notification
|
||||||
// for that which would normally fire beginForegroundRefresh.
|
// for that which would normally fire beginForegroundRefresh.
|
||||||
self.view.backgroundColor = [ThemeManager appBackgroundColor];
|
|
||||||
self.hostCollectionVC.view.backgroundColor = [ThemeManager appBackgroundColor];
|
|
||||||
self.collectionView.backgroundColor = [ThemeManager appBackgroundColor];
|
|
||||||
|
|
||||||
[self.view addSubview:self.collectionView];
|
[self.view addSubview:self.collectionView];
|
||||||
[self initHostCollection];
|
[self initHostCollection];
|
||||||
if(!_enteredAppView) [self switchToHostView];
|
if(!_enteredAppView) [self switchToHostView];
|
||||||
|
|
||||||
|
[self updateTheme];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidDisappear:(BOOL)animated
|
- (void)viewDidDisappear:(BOOL)animated
|
||||||
|
|||||||
@@ -837,9 +837,36 @@ const int FrontViewPositionNone = 0xff;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)viewDidLoad{
|
- (void)dealloc {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)updateTheme {
|
||||||
|
_contentView.backgroundColor = [ThemeManager appBackgroundColor];
|
||||||
|
_contentView.rearNavView.backgroundColor = [ThemeManager appBackgroundColor];
|
||||||
|
_separatorLine.backgroundColor = [ThemeManager separatorColor];
|
||||||
|
|
||||||
|
if (@available(iOS 13.0, *)) {
|
||||||
|
UINavigationBarAppearance *navBarAppearanceStandard = _dockedNavBar.standardAppearance;
|
||||||
|
navBarAppearanceStandard.backgroundColor = [ThemeManager appBackgroundColor];
|
||||||
|
navBarAppearanceStandard.titleTextAttributes = @{
|
||||||
|
NSForegroundColorAttributeName: [ThemeManager textColor]
|
||||||
|
};
|
||||||
|
_dockedNavBar.standardAppearance = navBarAppearanceStandard;
|
||||||
|
_dockedNavBar.scrollEdgeAppearance = navBarAppearanceStandard;
|
||||||
|
} else {
|
||||||
|
_dockedNavBar.barTintColor = [ThemeManager appBackgroundColor];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)viewDidLoad{
|
||||||
self.isStreaming = false; //init this flag
|
self.isStreaming = false; //init this flag
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(updateTheme)
|
||||||
|
name:ThemeDidChangeNotification
|
||||||
|
object:nil];
|
||||||
|
[self updateTheme];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated
|
- (void)viewDidAppear:(BOOL)animated
|
||||||
@@ -2425,5 +2452,3 @@ NSString * const SWSegueRightIdentifier = @"sw_right";
|
|||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//@end
|
//@end
|
||||||
|
|
||||||
|
|
||||||
@@ -1232,8 +1232,16 @@ BOOL isCustomResolution(CGSize res) {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
//[self updateTheme];
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(updateTheme)
|
||||||
|
name:ThemeDidChangeNotification
|
||||||
|
object:nil];
|
||||||
|
|
||||||
settingStackWillBeRelocatedToLowestPosition = false;
|
settingStackWillBeRelocatedToLowestPosition = false;
|
||||||
hiddenStacks = [[NSMutableSet alloc] init];
|
hiddenStacks = [[NSMutableSet alloc] init];
|
||||||
|
|
||||||
|
|||||||
@@ -490,6 +490,16 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateTheme {
|
||||||
|
self.view.backgroundColor = [ThemeManager appBackgroundColor];
|
||||||
|
_stageLabel.textColor = [[ThemeManager textColor] colorWithAlphaComponent:0.9];
|
||||||
|
_spinner.color = [ThemeManager textColor];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)viewDidLoad
|
- (void)viewDidLoad
|
||||||
{
|
{
|
||||||
@@ -501,6 +511,11 @@
|
|||||||
|
|
||||||
[UIApplication sharedApplication].idleTimerDisabled = YES;
|
[UIApplication sharedApplication].idleTimerDisabled = YES;
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(updateTheme)
|
||||||
|
name:@"ThemeDidChangeNotification"
|
||||||
|
object:nil];
|
||||||
|
|
||||||
_settings = [[[DataManager alloc] init] getSettings]; //StreamFrameViewController retrieve the settings here.
|
_settings = [[[DataManager alloc] init] getSettings]; //StreamFrameViewController retrieve the settings here.
|
||||||
|
|
||||||
_stageLabel = [[UILabel alloc] init];
|
_stageLabel = [[UILabel alloc] init];
|
||||||
@@ -631,9 +646,7 @@
|
|||||||
_stageLabel.textColor = [UIColor systemGrayColor];
|
_stageLabel.textColor = [UIColor systemGrayColor];
|
||||||
_spinner.color = [UIColor systemGrayColor];
|
_spinner.color = [UIColor systemGrayColor];
|
||||||
|
|
||||||
self.view.backgroundColor = [ThemeManager appBackgroundColor];
|
[self updateTheme];
|
||||||
_stageLabel.textColor = [[ThemeManager textColor] colorWithAlphaComponent:0.9];
|
|
||||||
_spinner.color = [ThemeManager textColor];
|
|
||||||
|
|
||||||
[self.view addSubview:_stageLabel];
|
[self.view addSubview:_stageLabel];
|
||||||
[self.view addSubview:_spinner];
|
[self.view addSubview:_spinner];
|
||||||
|
|||||||
Reference in new issue
Block a user