Skip to content

Commit 15d5d6d

Browse files
committed
Merge branch '_bugfix/Refactoring'
2 parents d9d36ea + 4d51b87 commit 15d5d6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+357
-245
lines changed

AppTheming/Classes/AppearanceManager.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ protocol AppearanceManagerProtocol {
1414
}
1515

1616
public enum AppearanceManager {
17-
1817
static func getComponentName(_ appearanceName: String) -> (String, String?) {
1918
let components = appearanceName.components(separatedBy: ":")
20-
2119
if components.count > 1 {
2220
return (components.first!, components.last)
2321
}
24-
2522
return (appearanceName, nil)
2623
}
2724

@@ -33,7 +30,7 @@ public enum AppearanceManager {
3330
if let themeObj: ThemeModel = theme.value as? ThemeModel {
3431

3532
let components = getComponentName(theme.key)
36-
33+
// Setup 'appearance' from Theme
3734
if let classTy: AppearanceManagerProtocol = Reflection.swiftClassFromString(components.0) as? AppearanceManagerProtocol {
3835

3936
var appearanceContainer: [UIAppearanceContainer.Type]?
@@ -50,19 +47,6 @@ public enum AppearanceManager {
5047
}
5148
}
5249

53-
extension ThemesManager {
54-
55-
public static func setStatusBarBackgroundColor(_ color: UIColor?) {
56-
57-
if
58-
let color = color,
59-
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as? UIView,
60-
statusBar.responds(to: #selector(setter: UIView.backgroundColor)) {
61-
statusBar.backgroundColor = color
62-
}
63-
}
64-
}
65-
6650
extension UIView: AppearanceManagerProtocol {
6751

6852
public func setUpAppearance(theme: ThemeModel, containerClass: [UIAppearanceContainer.Type]?) -> UIAppearance {
@@ -161,7 +145,7 @@ extension UINavigationBar {
161145
}
162146

163147
override public class func setBackgroundImage(_ image: Any) {
164-
148+
// defaultImage
165149
var defaultImage: UIImage? = ThemesManager.getImage(image)
166150
var landScapeImage: UIImage?
167151

@@ -177,11 +161,8 @@ extension UINavigationBar {
177161
}
178162

179163
extension UITabBar {
180-
181164
override public class func setBackgroundImage(_ image: Any) {
182-
183165
let appearance = self.appearance()
184-
185166
if let defaultImage = ThemesManager.getImage(image) {
186167
appearance.backgroundImage = defaultImage
187168
}

AppTheming/Classes/ThemeComponents/SearchBar+Theme.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ extension UISearchBar: ThemeProtocol {
5353
// MARK: - Key-Value Observing
5454
// swiftlint:disable block_based_kvo
5555
override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
56-
guard let searchField = searchUITextField, let att = searchBarAttributes, !att.isEmpty else {
57-
return
58-
}
56+
guard let searchField = searchUITextField, let att = searchBarAttributes, !att.isEmpty else { return }
5957
if keyPath == #keyPath(UISearchBar.placeholder),
6058
let sting = searchField.attributedPlaceholder?.string {
6159
// Update placeHolder
@@ -129,8 +127,8 @@ private extension UISearchBar {
129127
if textColor != nil {
130128
searchField.textColor = textColor
131129
att[.foregroundColor] = textColor
132-
//let label = UILabel.appearance(whenContainedInInstancesOf: [UISearchBar.self])
133-
//label.textColor = textColor
130+
// let label = UILabel.appearance(whenContainedInInstancesOf: [UISearchBar.self])
131+
// label.textColor = textColor
134132
}
135133
if let sting = searchField.attributedPlaceholder?.string, !att.isEmpty {
136134
searchField.attributedPlaceholder = NSAttributedString(string: sting, attributes: att)

AppTheming/Classes/ThemeComponents/SegmentControll+Theme.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@
77

88
import Foundation
99

10-
extension UISegmentedControl: ThemeProtocol {
10+
extension UISegmentedControl: ControlThemeProtocol {
11+
// check view state, to update style
12+
open func getThemeSubType() -> String? { nil }
1113

12-
public func updateTheme(_ theme: ThemeModel) {
13-
if let text = theme["tintColor"] as? String, let color: UIColor = ThemesManager.getColor(text) {
14+
public func update(themeDic: ThemeModel, state: UIControl.State) {
15+
if let text = themeDic["tintColor"] as? String, let color: UIColor = ThemesManager.getColor(text) {
1416
self.tintColor = color
1517
}
1618

17-
if #available(iOS 13, *), (theme["iOS12Style"] as? Bool) ?? false {
19+
if #available(iOS 13, *), (themeDic["iOS12Style"] as? Bool) ?? false {
1820
// Update with iOS 12 style
1921
var textFont: UIFont = .systemFont(ofSize: 13, weight: .regular)
20-
if let text = theme["textfont"] as? String, let font: UIFont = ThemesManager.getFont(text) {
22+
if let text = themeDic["textfont"] as? String, let font: UIFont = ThemesManager.getFont(text) {
2123
textFont = font
2224
}
2325
var textcolor: UIColor = .white
24-
if let text = theme["textcolor"] as? String, let color: UIColor = ThemesManager.getColor(text) {
26+
if let text = themeDic["textcolor"] as? String, let color: UIColor = ThemesManager.getColor(text) {
2527
textcolor = color
2628
}
2729
ensureiOS12Style(font: textFont, textColor: textcolor)

AppTheming/Classes/ThemeComponents/View+Themes.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ extension UIView {
3737
// Swizzling out view's layoutSubviews property for Updating Visual theme
3838
private static func swizzleLayoutSubview() {
3939
// need to be Swizzled only once.
40-
guard !hasSwizzled else {
41-
return
42-
}
40+
guard !hasSwizzled else { return }
4341
hasSwizzled = true
4442
instanceMethodSwizzling(UIView.self, #selector(layoutSubviews), #selector(swizzledLayoutSubviews))
4543
}

AppTheming/Classes/ThemesManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ open class ThemesManager {
7070

7171
// Get theme component
7272
guard let currentTheme: ThemeModel = ThemesManager.getViewComponent(name, styleName: styleName) else {
73-
//ftLog("FTError: Theme of type \(styleName) not avaialble for class \(name)" )
73+
// ftLog("FTError: Theme of type \(styleName) not avaialble for class \(name)" )
7474
return nil
7575
}
7676

AppTheming/Tests/ClassMethodSwizzlingTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import XCTest
1111

1212
private final class TestSwizzling {
13-
@objc dynamic func getMessage() -> String { return "getMessage" }
14-
@objc dynamic func swizzledMessage() -> String { return "swizzledMessage" }
13+
@objc dynamic func getMessage() -> String { "getMessage" }
14+
@objc dynamic func swizzledMessage() -> String { "swizzledMessage" }
1515

1616
// Swizzling out view's layoutSubviews property for Updating Visual theme
1717
static func swizzleTestMethod() {
@@ -26,7 +26,7 @@ final class ClassMethodSwizzlingTests: XCTestCase {
2626
XCTAssertNotNil(temp)
2727
XCTAssertEqual(temp.getMessage(), "getMessage")
2828
XCTAssertEqual(temp.swizzledMessage(), "swizzledMessage")
29-
TestSwizzling.swizzleTestMethod() //Swizzle method and test again
29+
TestSwizzling.swizzleTestMethod() // Swizzle method and test again
3030
XCTAssertEqual(temp.getMessage(), "swizzledMessage")
3131
XCTAssertEqual(temp.swizzledMessage(), "getMessage")
3232
}

AppTheming/Tests/CollectionViewThemeTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class CollectionViewThemeTests: XCTestCase {
2323
ThemesManager.setupThemes(themes: themeContent)
2424
}
2525
else {
26-
XCTFail()
26+
XCTFail("Should have valid theme")
2727
}
2828
}
2929

@@ -35,9 +35,9 @@ final class CollectionViewThemeTests: XCTestCase {
3535
collectionView.backgroundView = tempView
3636
collectionView.theme = "collectionRed"
3737
// then
38-
XCTAssertNotNil(value)
38+
XCTAssertNotNil(value, "Should have valid value")
3939
XCTAssertEqual(tempView.theme, "viewR")
40-
XCTAssertEqual(tempView.backgroundColor, value)
40+
XCTAssertEqual(tempView.backgroundColor, value, "Should have same backgroundColor")
4141
}
4242

4343
func testCollectionViewTheme() {
@@ -48,7 +48,7 @@ final class CollectionViewThemeTests: XCTestCase {
4848
collectionView.backgroundView = tempView
4949
collectionView.theme = ThemeStyle.defaultStyle
5050
// then
51-
XCTAssertNotNil(value)
51+
XCTAssertNotNil(value, "Should have valid value")
5252
XCTAssertEqual(tempView.theme, ThemeStyle.defaultStyle)
5353
XCTAssertEqual(tempView.backgroundColor, value)
5454
}

AppTheming/Tests/CustomUIElementsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class CustomUIElementsTests: XCTestCase {
2121
ThemesManager.setupThemes(themes: themeContent, imageSourceBundle: nil)
2222
}
2323
else {
24-
XCTFail()
24+
XCTFail("Should have valid theme")
2525
}
2626
}
2727

AppTheming/Tests/ThemesTests.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ final class ThemesTests: XCTestCase {
2121
ThemesManager.setupThemes(themes: themeContent, imageSourceBundle: [bundle])
2222
}
2323
else {
24-
XCTFail()
24+
XCTFail("Should have valid theme")
2525
}
2626
}
2727

2828
// MARK: Theme Manager
2929

30-
3130
// MARK: View Component
3231
func testComponent() {
3332
let value = ThemesManager.getViewComponent("UILabel", styleName: "system14R")
@@ -68,7 +67,7 @@ final class ThemesTests: XCTestCase {
6867
}
6968

7069
func testRGBIntColor() {
71-
let value = UIColor(rgb: 13158600)
70+
let value = UIColor(rgb: 13_158_600)
7271
XCTAssertNotNil(value)
7372
XCTAssertEqual(value.hexString(), "#C8C8C8".lowercased())
7473
XCTAssertEqual(value.hexAlphaString(), "#C8C8C8FF".lowercased())
@@ -77,7 +76,7 @@ final class ThemesTests: XCTestCase {
7776
}
7877

7978
func testRGBAIntColor() {
80-
let value = UIColor(rgb: 13158600, a: 0.5)
79+
let value = UIColor(rgb: 13_158_600, a: 0.5)
8180
XCTAssertNotNil(value)
8281
XCTAssertEqual(value.hexAlphaString(), "#C8C8C87F".lowercased())
8382
let actualValue = UIColor(red: 200, green: 200, blue: 200, a: 0.5)

CoreUI/Classes/Contollers/ViewControllerProtocol.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ import UIKit
1111
public protocol ViewControllerProtocol where Self: UIViewController {
1212
var modelStack: AnyObject? { get set }
1313

14-
//Setup View
14+
// Setup View
1515
func setupCoreView()
1616
// MARK: Navigation Bar
17-
//Bydefalut leftButton action is set to 'leftButtonAction'
17+
// Bydefalut leftButton action is set to 'leftButtonAction'
1818
func setupNavigationbar(title: String, leftButton: UIBarButtonItem?, rightButton: UIBarButtonItem?)
19-
//invokes's 'popViewController' if not rootViewController or-else invokes 'dismiss'
19+
// invokes's 'popViewController' if not rootViewController or-else invokes 'dismiss'
2020
func dismissSelf(_ animated: Bool)
21-
//Navigation bar defalut Actions
21+
// Navigation bar defalut Actions
2222
func leftButtonAction()
2323
func rightButtonAction()
2424
// MARK: Keyboard notification.
2525
func registerKeyboardNotifications()
26-
//Notifications will be unregistered in 'deinit'
26+
// Notifications will be unregistered in 'deinit'
2727
func unregisterKeyboardNotifications()
2828
// MARK: Alert ViewController
2929
func showAlert(title: String?, message: String?, action: UIAlertAction?, actions: [UIAlertAction]?)

0 commit comments

Comments
 (0)