Skip to content

Commit

Permalink
Merge pull request #33 from surfstudio/SPT-1509-color-customization
Browse files Browse the repository at this point in the history
SPT-1509 DebugScreen, цветовая кастомизация
  • Loading branch information
chausovSurfStudio committed Jul 11, 2023
2 parents a62363f + 5fef3a8 commit 8fae4ef
Show file tree
Hide file tree
Showing 24 changed files with 396 additions and 27 deletions.
20 changes: 20 additions & 0 deletions DebugScreen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
B23477792A540D5C00F788A8 /* InfoTableSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = B23477782A540D5C00F788A8 /* InfoTableSection.swift */; };
B234777D2A541EDE00F788A8 /* HeaderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B234777C2A541EDE00F788A8 /* HeaderViewModel.swift */; };
B234F72D2A498BC600161F52 /* DebugScreen.docc in Sources */ = {isa = PBXBuildFile; fileRef = B234F72C2A498BC600161F52 /* DebugScreen.docc */; };
B2255DE12A4DC9180010A69D /* ColorScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2255DDE2A4DC9170010A69D /* ColorScheme.swift */; };
B2255DE22A4DC9180010A69D /* ButtonConfigurations.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2255DDF2A4DC9170010A69D /* ButtonConfigurations.swift */; };
B2255DE32A4DC9180010A69D /* ButtonAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2255DE02A4DC9170010A69D /* ButtonAppearance.swift */; };
B237FF5D2A28CBB90095FA33 /* LoggerActivationToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B237FF5C2A28CBB90095FA33 /* LoggerActivationToggle.swift */; };
B237FF632A2912D10095FA33 /* MainTableBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B237FF622A2912D10095FA33 /* MainTableBlock.swift */; };
B237FF652A2913DF0095FA33 /* LoggerSectionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = B237FF642A2913DF0095FA33 /* LoggerSectionComponent.swift */; };
Expand Down Expand Up @@ -216,6 +219,9 @@
B23477782A540D5C00F788A8 /* InfoTableSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoTableSection.swift; sourceTree = "<group>"; };
B234777C2A541EDE00F788A8 /* HeaderViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderViewModel.swift; sourceTree = "<group>"; };
B234F72C2A498BC600161F52 /* DebugScreen.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = DebugScreen.docc; sourceTree = "<group>"; };
B2255DDE2A4DC9170010A69D /* ColorScheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorScheme.swift; sourceTree = "<group>"; };
B2255DDF2A4DC9170010A69D /* ButtonConfigurations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonConfigurations.swift; sourceTree = "<group>"; };
B2255DE02A4DC9170010A69D /* ButtonAppearance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonAppearance.swift; sourceTree = "<group>"; };
B237FF5C2A28CBB90095FA33 /* LoggerActivationToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerActivationToggle.swift; sourceTree = "<group>"; };
B237FF622A2912D10095FA33 /* MainTableBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableBlock.swift; sourceTree = "<group>"; };
B237FF642A2913DF0095FA33 /* LoggerSectionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerSectionComponent.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -591,6 +597,16 @@
path = Views;
sourceTree = "<group>";
};
B2255DDD2A4DC9170010A69D /* Appearance */ = {
isa = PBXGroup;
children = (
B2255DE02A4DC9170010A69D /* ButtonAppearance.swift */,
B2255DDF2A4DC9170010A69D /* ButtonConfigurations.swift */,
B2255DDE2A4DC9170010A69D /* ColorScheme.swift */,
);
path = Appearance;
sourceTree = "<group>";
};
B237FF5E2A2910A30095FA33 /* Builders */ = {
isa = PBXGroup;
children = (
Expand All @@ -602,6 +618,7 @@
B237FF5F2A2910EE0095FA33 /* Models */ = {
isa = PBXGroup;
children = (
B2255DDD2A4DC9170010A69D /* Appearance */,
B237FF602A29126F0095FA33 /* Common */,
B237FF612A29127C0095FA33 /* Logger */,
B24B27DF2A37150B00624E29 /* Modules */,
Expand Down Expand Up @@ -1350,6 +1367,7 @@
B237FF652A2913DF0095FA33 /* LoggerSectionComponent.swift in Sources */,
B24B27E32A37153800624E29 /* FileViewerModel.swift in Sources */,
A4BDF49928512F7700651C61 /* Bundle.swift in Sources */,
B2255DE12A4DC9180010A69D /* ColorScheme.swift in Sources */,
B2CA74DD2A1743B700E91B24 /* FileViewerModuleOutput.swift in Sources */,
A47BDB44286A1249002326B8 /* Assets.swift in Sources */,
A4BDF49728512F7700651C61 /* UIWindow.swift in Sources */,
Expand Down Expand Up @@ -1387,6 +1405,7 @@
B2B1D4542A5307F400CC5A11 /* InfoTableViewAdapter.swift in Sources */,
B23477772A540D3D00F788A8 /* InfoTableItem.swift in Sources */,
B28F97EF2A2723AA0089C032 /* HeaderView.swift in Sources */,
B2255DE32A4DC9180010A69D /* ButtonAppearance.swift in Sources */,
B2CA74DF2A1743C700E91B24 /* FileViewerPresenter.swift in Sources */,
B2B1D44B2A52DBB000CC5A11 /* InfoTableViewOutput.swift in Sources */,
A4BDF4C428512FAA00651C61 /* MainViewOutput.swift in Sources */,
Expand All @@ -1413,6 +1432,7 @@
A4BDF4C828512FAA00651C61 /* DebugScreenCoordinator.swift in Sources */,
B28F97EC2A271FF30089C032 /* SelectionList.swift in Sources */,
B28F97EA2A271FC00089C032 /* CopiedText.swift in Sources */,
B2255DE22A4DC9180010A69D /* ButtonConfigurations.swift in Sources */,
B28F97E82A271FAF0089C032 /* FeatureToggle.swift in Sources */,
B2B1D43B2A52D6B400CC5A11 /* InfoTableModel.swift in Sources */,
A4BDF4BF28512FAA00651C61 /* SwitcherCell.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private extension BaseNavigationController {
appearance.setBackIndicatorImage(backImage, transitionMaskImage: backImage)

navigationBar.standardAppearance = appearance
navigationBar.tintColor = Colors.Buttons.Primary.normalBackground
navigationBar.tintColor = DebugScreenConfiguration.shared.colorScheme.textColor
}

}
Expand Down
21 changes: 16 additions & 5 deletions DebugScreen/Common/Extensions/UIKit/UIButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@ import UIKit
extension UIButton {

func configure(style: ActionStyle) {
var appearance = ButtonAppearance.appearance(for: style)

switch style {
case .primary:
appearance = DebugScreenConfiguration.shared.colorScheme.buttonConfigurations.primary
case .secondary:
appearance = DebugScreenConfiguration.shared.colorScheme.buttonConfigurations.secondary
case .destructive:
appearance = DebugScreenConfiguration.shared.colorScheme.buttonConfigurations.destructive
}

clipsToBounds = true
layer.cornerRadius = 12

titleLabel?.font = .systemFont(ofSize: 17, weight: .medium)
setTitleColor(style.titleColor, for: .normal)
setTitleColor(style.titleColor, for: .highlighted)
setTitleColor(style.titleColor, for: .disabled)
setTitleColor(appearance.textColor, for: .normal)
setTitleColor(appearance.textColor, for: .highlighted)
setTitleColor(appearance.textColor, for: .disabled)

set(backgroundColor: style.backgroundColor, for: .normal)
set(backgroundColor: style.highlightedBackgroundColor, for: [.highlighted, .selected])
set(backgroundColor: appearance.normalBackground, for: .normal)
set(backgroundColor: appearance.highlightedBackground, for: [.highlighted, .selected])
}

func set(backgroundColor: UIColor, for state: UIControl.State) {
Expand Down
2 changes: 1 addition & 1 deletion DebugScreen/Common/Extensions/UIKit/UITableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension UITableViewCell {

func setDefaultStyle() {
selectionStyle = .none
backgroundColor = Colors.Main.background
backgroundColor = DebugScreenConfiguration.shared.colorScheme.backgroundColor
}

}
79 changes: 79 additions & 0 deletions DebugScreen/Common/Models/Appearance/ButtonAppearance.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// ButtonAppearance.swift
//
//
// Created by Ilya Klimenyuk on 29.06.2023.
//

import UIKit

/// Debug screen button appearance.
///
/// Every debug screen button can be configured with custom background and text colors.
/// If custom colors haven't been initialized, the default colors will be used.
public struct ButtonAppearance {

// MARK: - Properties

/// Button's background color for highlighted and selected states.
private(set) var highlightedBackground: UIColor
/// Button's background color for normal state.
private(set) var normalBackground: UIColor
/// Button's text color for all states.
private(set) var textColor: UIColor

// MARK: - Initialization

/// Allows you to create appearance object with default values,
/// that depends on passed `style` parameter.
public init(style: ActionStyle,
highlightedBackground: UIColor? = nil,
normalBackground: UIColor? = nil,
textColor: UIColor? = nil) {
// Set default colors according to button style
self.init(highlightedBackground: style.highlightedBackgroundColor,
normalBackground: style.backgroundColor,
textColor: style.titleColor)

// Set custom colors (if needed)
if let highlightedBackground = highlightedBackground {
self.highlightedBackground = highlightedBackground
}

if let normalBackground = normalBackground {
self.normalBackground = normalBackground
}

if let textColor = textColor {
self.textColor = textColor
}
}

/// Allows you to create appearance object with your own custom values
private init(highlightedBackground: UIColor,
normalBackground: UIColor,
textColor: UIColor) {
self.highlightedBackground = highlightedBackground
self.normalBackground = normalBackground
self.textColor = textColor
}

// MARK: - Static Methods

/**
Get button appearance settings with selected style.
- Parameter style: Button action style.
- Returns: Button appearance.
For example, if we want to get primary button default appearance settings:
```swift
let primary: ButtonAppearance = .appearance(for: .primary)
```
*/
static func appearance(for style: ActionStyle) -> ButtonAppearance {
return .init(highlightedBackground: style.highlightedBackgroundColor,
normalBackground: style.backgroundColor,
textColor: style.titleColor)
}

}
39 changes: 39 additions & 0 deletions DebugScreen/Common/Models/Appearance/ButtonConfigurations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// ButtonConfigurations.swift
//
//
// Created by Ilya Klimenyuk on 29.06.2023.
//

/// Representation of all available action buttons apperance configurations.
public struct ButtonConfigurations {

// MARK: - Properties

/// Primary button apperance configuration.
private(set) var primary: ButtonAppearance = .appearance(for: .primary)
/// Secondary button appearance configuration.
private(set) var secondary: ButtonAppearance = .appearance(for: .secondary)
/// Destructive button apperance configuration.
private(set) var destructive: ButtonAppearance = .appearance(for: .destructive)

// MARK: - Initialization

public init(primary: ButtonAppearance? = nil,
secondary: ButtonAppearance? = nil,
destructive: ButtonAppearance? = nil) {

if let primary = primary {
self.primary = primary
}

if let secondary = secondary {
self.secondary = secondary
}

if let destructive = destructive {
self.destructive = destructive
}
}

}
59 changes: 59 additions & 0 deletions DebugScreen/Common/Models/Appearance/ColorScheme.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// ColorScheme.swift
//
//
// Created by Ilya Klimenyuk on 29.06.2023.
//

import UIKit

/// Representation of DebugScreen color scheme.
///
/// You can override all available color components.
/// If custom colors haven't been initialized, the default colors will be used.
public struct ColorScheme {

// MARK: - Properties

/// DebugScreen views background color.
private(set) var backgroundColor = Colors.Main.background
/// DebugScreen text color. Used for section headers and close icon.
private(set) var textColor = Colors.Text.primary
/// DebugScreen secondary text color. Used for section headers and labels at an info screens.
private(set) var textSecondaryColor = Colors.Text.secondary
/// DebugScreen action buttons appearance configurations.
private(set) var buttonConfigurations = ButtonConfigurations()

// MARK: - Initialization

public init(backgroundColor: UIColor? = nil,
textColor: UIColor? = nil,
textSecondaryColor: UIColor? = nil,
buttonConfigurations: ButtonConfigurations? = nil) {

if let backgroundColor = backgroundColor {
self.backgroundColor = backgroundColor
}

if let textColor = textColor {
self.textColor = textColor
}

if let textSecondaryColor = textSecondaryColor {
self.textSecondaryColor = textSecondaryColor
}

if let buttonConfigurations = buttonConfigurations {
self.buttonConfigurations = buttonConfigurations
}
}

// MARK: - Static Methods

/// Get DebugScreen default color scheme.
/// - Returns: Default color scheme.
static func `default`() -> ColorScheme {
return .init()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ private extension PlainTextCell {

func configureContainer() {
accessoryType = .disclosureIndicator
backgroundColor = Colors.Main.background
backgroundColor = DebugScreenConfiguration.shared.colorScheme.backgroundColor
}

func configureTitleLabel() {
titleLabel.font = .systemFont(ofSize: 16, weight: .regular)
titleLabel.textColor = Colors.Text.primary
titleLabel.textColor = DebugScreenConfiguration.shared.colorScheme.textColor
titleLabel.numberOfLines = 0
titleLabel.textAlignment = .left
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ private extension TwoLabelsCell {

func configureTitleLabel() {
titleLabel.font = .systemFont(ofSize: 14, weight: .regular)
titleLabel.textColor = Colors.Text.primary
titleLabel.textColor = DebugScreenConfiguration.shared.colorScheme.textColor
titleLabel.numberOfLines = 0
}

func configureValueLabel() {
valueLabel.font = .systemFont(ofSize: 14, weight: .regular)
valueLabel.textColor = Colors.Text.secondary
valueLabel.textColor = DebugScreenConfiguration.shared.colorScheme.textSecondaryColor
valueLabel.numberOfLines = 0
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct HeaderViewModel {

init(
text: String?,
textColor: UIColor = Colors.Text.primary,
backgroundColor: UIColor = Colors.Main.background,
textColor: UIColor = DebugScreenConfiguration.shared.colorScheme.textColor,
backgroundColor: UIColor = DebugScreenConfiguration.shared.colorScheme.backgroundColor,
font: UIFont = .systemFont(ofSize: 20, weight: .heavy)
) {
self.text = text
Expand Down
4 changes: 4 additions & 0 deletions DebugScreen/DebugScreenConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class DebugScreenConfiguration {
/// Default value is `false`.
public var isEnabledOnShake = false

/// DebugScreen color scheme.
/// You can initialize custom color scheme by setting all available colors.
public var colorScheme: ColorScheme = .default()

// MARK: - Initialization

private init() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension InfoTableViewAdapter: UITableViewDelegate {

let model = HeaderViewModel(
text: section.title?.uppercased(),
textColor: Colors.Text.secondary,
textColor: DebugScreenConfiguration.shared.colorScheme.textSecondaryColor,
backgroundColor: .clear,
font: .systemFont(ofSize: 14)
)
Expand All @@ -78,6 +78,16 @@ extension InfoTableViewAdapter: UITableViewDelegate {
return headerView
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
guard
let section = sections[safe: section],
!(section.title?.isEmpty ?? true)
else {
return 0.001
}
return 50
}

}

// MARK: - Private Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension InfoTableViewController: InfoTableViewInput {
private extension InfoTableViewController {

func configureAppearance(with title: String) {
view.backgroundColor = Colors.Main.background
view.backgroundColor = DebugScreenConfiguration.shared.colorScheme.backgroundColor

configureNavigationBar(with: title)
configureTableView()
Expand All @@ -65,7 +65,7 @@ private extension InfoTableViewController {

func configureTableView() {
tableView.contentInsetAdjustmentBehavior = .never
tableView.backgroundColor = Colors.Main.background
tableView.backgroundColor = DebugScreenConfiguration.shared.colorScheme.backgroundColor
tableView.contentInset = .init(top: 8,
left: 0,
bottom: 32,
Expand Down

0 comments on commit 8fae4ef

Please sign in to comment.