Skip to content

Commit

Permalink
Merge pull request #403 from tchapgouv/phlpro/theme
Browse files Browse the repository at this point in the history
Replace Style by Theme
  • Loading branch information
Phl-Pro authored Oct 5, 2021
2 parents 64030a3 + aa148bc commit 2f06c14
Show file tree
Hide file tree
Showing 72 changed files with 640 additions and 1,112 deletions.
1 change: 1 addition & 0 deletions Btchap/Generated/InfoPlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal enum InfoPlist {
internal static let uiStatusBarTintParameters: [String: Any] = _document["UIStatusBarTintParameters"]
internal static let uiSupportedInterfaceOrientations: [String] = _document["UISupportedInterfaceOrientations"]
internal static let uiSupportedInterfaceOrientationsIpad: [String] = _document["UISupportedInterfaceOrientations~ipad"]
internal static let uiUserInterfaceStyle: String = _document["UIUserInterfaceStyle"]
internal static let uiViewControllerBasedStatusBarAppearance: Bool = _document["UIViewControllerBasedStatusBarAppearance"]
internal static let userDefaults: String = _document["UserDefaults"]
internal static let applicationGroupIdentifier: String = _document["applicationGroupIdentifier"]
Expand Down
2 changes: 2 additions & 0 deletions Btchap/SupportingFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
<true/>
<key>UserDefaults</key>
<string>${PRODUCT_NAME}-Defaults</string>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>applicationGroupIdentifier</key>
<string>$(APPLICATION_GROUP_IDENTIFIER)</string>
<key>baseBundleIdentifier</key>
Expand Down
7 changes: 4 additions & 3 deletions BtchapShareExtension/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,24 @@ targets:
- path: ../Riot/Utils/UserNameColorGenerator.swift

# Tchap
- path: ../Btchap/Config/BuildSettings.swift
- path: ../Tchap/Config/CommonConfiguration.swift
- path: ../Tchap/Config/Configurable.swift
- path: ../Tchap/Constants
- path: ../Tchap/Extensions
- path: ../Btchap/Generated/InfoPlist.swift
- path: ../Tchap/Generated/Strings.swift
- path: ../Tchap/Managers/HomeServer
- path: ../Tchap/Managers/Room
- path: ../Tchap/Managers/ThirdPartyIDPlatformInfoResolver
- path: ../Tchap/Managers/User
- path: ../Tchap/Managers/DisplayName
- path: ../Tchap/Modules/Common/Style
- path: ../Tchap/Modules/Rooms/Views
- path: ../Tchap/Model
- path: ../Tchap/Utils

# Btchap
- path: ../Btchap/Config/BuildSettings.swift
- path: ../Btchap/Generated/InfoPlist.swift

# Resources
- path: ../Riot/Modules/Common/SegmentedViewController/SegmentedViewController.xib
buildPhase: resources
Expand Down
5 changes: 5 additions & 0 deletions Riot/Managers/Theme/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,9 @@ import UIKit
///
/// - Parameter button: The button to customise.
func applyStyle(onButton button: UIButton)

/// Apply the theme on a switch.
///
/// - Parameter switch: The switch to customise.
func applyStyle(onSwitch uiSwitch: UISwitch)
}
4 changes: 4 additions & 0 deletions Riot/Managers/Theme/Themes/DarkTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ class DarkTheme: NSObject, Theme {
button.setTitleColor(self.tintColor, for: .normal)
}

func applyStyle(onSwitch uiSwitch: UISwitch) {
uiSwitch.onTintColor = self.headerBackgroundColor
}

/// MARK: - Theme v2

lazy var colors: Colors = {
Expand Down
39 changes: 17 additions & 22 deletions Riot/Managers/Theme/Themes/DefaultTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DefaultTheme: NSObject, Theme {

// Note: We are not using UINavigationBarAppearance on iOS 13+ atm because of UINavigationBar directly include UISearchBar on their titleView that cause crop issues with UINavigationController pop.
func applyStyle(onNavigationBar navigationBar: UINavigationBar) {
navigationBar.tintColor = self.baseTextPrimaryColor
navigationBar.tintColor = self.tintColor
navigationBar.titleTextAttributes = [
NSAttributedString.Key.foregroundColor: self.baseTextPrimaryColor
]
Expand All @@ -108,30 +108,21 @@ class DefaultTheme: NSObject, Theme {
}

func applyStyle(onSearchBar searchBar: UISearchBar) {
searchBar.barStyle = .default
searchBar.tintColor = self.searchPlaceholderColor
searchBar.barTintColor = self.headerBackgroundColor
searchBar.searchBarStyle = .default
searchBar.barTintColor = self.baseColor
searchBar.isTranslucent = false
searchBar.backgroundImage = UIImage() // Remove top and bottom shadow
searchBar.tintColor = self.tintColor

if let searchBarTextField = searchBar.vc_searchTextField {
searchBarTextField.textColor = searchBar.tintColor
if #available(iOS 13.0, *) {
searchBar.searchTextField.backgroundColor = self.searchBackgroundColor
searchBar.searchTextField.textColor = self.searchPlaceholderColor
} else {
if let searchBarTextField = searchBar.vc_searchTextField {
searchBarTextField.textColor = self.searchPlaceholderColor
}
}
}
// func applyStyle(onSearchBar searchBar: UISearchBar) {
// searchBar.searchBarStyle = .default
// searchBar.barTintColor = self.baseColor
// searchBar.isTranslucent = false
// searchBar.backgroundImage = UIImage() // Remove top and bottom shadow
// searchBar.tintColor = self.tintColor
//
// if #available(iOS 13.0, *) {
// searchBar.searchTextField.backgroundColor = self.searchBackgroundColor
// searchBar.searchTextField.textColor = self.searchPlaceholderColor
// } else {
// if let searchBarTextField = searchBar.vc_searchTextField {
// searchBarTextField.textColor = self.searchPlaceholderColor
// }
// }
// }

func applyStyle(onTextField texField: UITextField) {
texField.textColor = self.textPrimaryColor
Expand All @@ -143,4 +134,8 @@ class DefaultTheme: NSObject, Theme {
button.tintColor = self.tintColor
button.setTitleColor(self.tintColor, for: .normal)
}

func applyStyle(onSwitch uiSwitch: UISwitch) {
uiSwitch.onTintColor = self.headerBackgroundColor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ limitations under the License.
- (void)userInterfaceThemeDidChange;

/**
Update the current style.
Update the current theme.
*/
- (void)updateWithStyle:(id<Style>)style;
- (void)updateTheme;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#import "GeneratedInterface-Swift.h"

@interface SegmentedViewController () <Stylable>
@interface SegmentedViewController ()
{
// Tell whether the segmented view is appeared (see viewWillAppear/viewWillDisappear).
BOOL isViewAppeared;
Expand Down Expand Up @@ -50,8 +50,6 @@ @interface SegmentedViewController () <Stylable>
id kThemeServiceDidChangeThemeNotificationObserver;
}

@property (nonatomic, strong) id<Style> currentStyle;

@end

@implementation SegmentedViewController
Expand All @@ -68,7 +66,6 @@ + (instancetype)instantiate
{
SegmentedViewController *segmentedViewController = [[[self class] alloc] initWithNibName:NSStringFromClass([SegmentedViewController class])
bundle:[NSBundle bundleForClass:[SegmentedViewController class]]];
segmentedViewController.currentStyle = Variant1Style.shared;
return segmentedViewController;
}

Expand Down Expand Up @@ -197,33 +194,37 @@ - (void)viewDidLoad

- (void)userInterfaceThemeDidChange
{
[self updateWithStyle:self.currentStyle];
[self updateTheme];
}

- (void)updateWithStyle:(id<Style>)style
- (void)updateTheme
{
self.currentStyle = style;

self.sectionHeaderTintColor = style.barActionColor;
self.sectionHeaderTintColor = ThemeService.shared.theme.tintColor;

UINavigationBar *navigationBar = self.navigationController.navigationBar;

if (navigationBar)
{
[style applyStyleOnNavigationBar:navigationBar];
[ThemeService.shared.theme applyStyleOnNavigationBar:navigationBar];
}

self.view.backgroundColor = style.backgroundColor;
self.view.backgroundColor = ThemeService.shared.theme.backgroundColor;

// @TODO Design the activvity indicator for Tchap
self.activityIndicator.backgroundColor = style.overlayBackgroundColor;
self.activityIndicator.backgroundColor = ThemeService.shared.theme.overlayBackgroundColor;

for (UIView* subview in self.selectionContainer.subviews) {
[subview removeFromSuperview];
}

[self createSegmentedViews];

[self setNeedsStatusBarAppearanceUpdate];
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
return self.currentStyle.statusBarStyle;
return ThemeService.shared.theme.statusBarStyle;
}

- (void)viewWillAppear:(BOOL)animated
Expand Down Expand Up @@ -294,7 +295,7 @@ - (void)createSegmentedViews
label.font = [UIFont systemFontOfSize:17];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = _sectionHeaderTintColor;
label.backgroundColor = self.currentStyle.barBackgroundColor;
label.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
label.accessibilityIdentifier = [NSString stringWithFormat:@"SegmentedVCSectionLabel%tu", index];

// the constraint defines the label frame
Expand Down
26 changes: 9 additions & 17 deletions Riot/Modules/Common/WebViewController/WebViewViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

#import "GeneratedInterface-Swift.h"

@interface WebViewViewController () <Stylable>

@property (nonatomic, strong) id<Style> currentStyle;
@interface WebViewViewController ()

// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
@property (nonatomic, weak) id kThemeServiceDidChangeThemeNotificationObserver;
Expand All @@ -36,10 +34,6 @@ @implementation WebViewViewController
- (instancetype)init
{
self = [super init];
if (self)
{
self.currentStyle = Variant1Style.shared;
}
return self;
}

Expand Down Expand Up @@ -75,37 +69,35 @@ - (void)viewWillAppear:(BOOL)animated

- (void)userInterfaceThemeDidChange
{
[self updateWithStyle:self.currentStyle];
[self updateTheme];
}

- (void)applyVariant2Style
{
[self updateWithStyle:Variant2Style.shared];
[self updateTheme];
}

- (void)updateWithStyle:(id<Style>)style
- (void)updateTheme
{
self.currentStyle = style;

UINavigationBar *navigationBar = self.navigationController.navigationBar;

if (navigationBar)
{
[style applyStyleOnNavigationBar:navigationBar];
[ThemeService.shared.theme applyStyleOnNavigationBar:navigationBar];
}

// @TODO Design the activvity indicator for Tchap
self.activityIndicator.backgroundColor = style.overlayBackgroundColor;
self.activityIndicator.backgroundColor = ThemeService.shared.theme.overlayBackgroundColor;

self.view.backgroundColor = style.backgroundColor;
webView.backgroundColor = style.backgroundColor;
self.view.backgroundColor = ThemeService.shared.theme.backgroundColor;
webView.backgroundColor = ThemeService.shared.theme.backgroundColor;

[self setNeedsStatusBarAppearanceUpdate];
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
return self.currentStyle.statusBarStyle;
return ThemeService.shared.theme.statusBarStyle;
}

- (void)dealloc
Expand Down
1 change: 1 addition & 0 deletions Tchap/Generated/InfoPlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal enum InfoPlist {
internal static let uiStatusBarTintParameters: [String: Any] = _document["UIStatusBarTintParameters"]
internal static let uiSupportedInterfaceOrientations: [String] = _document["UISupportedInterfaceOrientations"]
internal static let uiSupportedInterfaceOrientationsIpad: [String] = _document["UISupportedInterfaceOrientations~ipad"]
internal static let uiUserInterfaceStyle: String = _document["UIUserInterfaceStyle"]
internal static let uiViewControllerBasedStatusBarAppearance: Bool = _document["UIViewControllerBasedStatusBarAppearance"]
internal static let userDefaults: String = _document["UserDefaults"]
internal static let applicationGroupIdentifier: String = _document["applicationGroupIdentifier"]
Expand Down
3 changes: 0 additions & 3 deletions Tchap/Modules/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, PushNotificationServiceDe
self.appCoordinator = AppCoordinator(router: self.rootRouter)
self.appCoordinator.start()

// Setup default UIAppearance
Appearance.setup()

return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ final class AppVersionUpdateViewController: UIViewController {
// MARK: Private

private var viewModel: AppVersionUpdateViewModelType!
private var style: Style!

// MARK: Public

weak var delegate: AppVersionUpdateViewControllerDelegate?

// MARK: - Setup

class func instantiate(with viewModel: AppVersionUpdateViewModelType, style: Style = Variant2Style.shared) -> AppVersionUpdateViewController {
class func instantiate(with viewModel: AppVersionUpdateViewModelType) -> AppVersionUpdateViewController {
let viewController = StoryboardScene.AppVersionUpdateViewController.initialScene.instantiate()
viewController.viewModel = viewModel
viewController.style = style
return viewController
}

Expand All @@ -67,18 +65,16 @@ final class AppVersionUpdateViewController: UIViewController {

// MARK: - Private

private func update(style: Style) {
self.style = style
private func updateTheme() {
self.view.backgroundColor = ThemeService.shared().theme.backgroundColor

self.view.backgroundColor = style.backgroundColor

self.messageLabel.textColor = self.style.primarySubTextColor
style.applyStyle(onButton: self.cancelButton)
style.applyStyle(onButton: self.appStoreButton)
self.messageLabel.textColor = ThemeService.shared().theme.textTertiaryColor
ThemeService.shared().theme.applyStyle(onButton: self.cancelButton)
ThemeService.shared().theme.applyStyle(onButton: self.appStoreButton)
}

private func themeDidChange() {
self.update(style: self.style)
self.updateTheme()
}

private func setupViews() {
Expand Down
Loading

0 comments on commit 2f06c14

Please sign in to comment.