blob: c799388434e128af10646a54929aa666c7128eb5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
//
// UIBackgroundConfiguration+Extensions.swift
// MullvadVPN
//
// Created by pronebird on 09/11/2023.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//
import UIKit
extension UIBackgroundConfiguration {
/// Type of cell selection used in Mullvad UI.
enum CellSelectionType {
/// Dimmed blue .
case dimmed
/// Bright green.
case green
}
/// Returns a plain cell background configuration adapted for Mullvad UI.
/// - Returns: a background configuration
static func mullvadListPlainCell() -> UIBackgroundConfiguration {
var config = listPlainCell()
config.backgroundColor = UIColor.Cell.backgroundColor
return config
}
/// Returns the corresponding grouped cell background configuration adapted for Mullvad UI.
/// - Returns: a background configuration
static func mullvadListGroupedCell() -> UIBackgroundConfiguration {
var config = listGroupedCell()
config.backgroundColor = UIColor.Cell.backgroundColor
return config
}
/// Adapt background configuration for the cell state and selection type.
///
/// - Parameters:
/// - state: a cell state.
/// - selectionType: a desired selecton type.
/// - Returns: new background configuration.
func adapted(for state: UICellConfigurationState, selectionType: CellSelectionType) -> UIBackgroundConfiguration {
var config = self
config.backgroundColor = state.mullvadCellBackgroundColor(selectionType: selectionType)
return config
}
/// Apply an error outline around the cell indicating an error.
mutating func applyValidationErrorStyle() {
cornerRadius = 10
strokeWidth = 1
strokeColor = UIColor.Cell.validationErrorBorderColor
}
}
extension UICellConfigurationState {
/// Produce background color for the given state and cell selection type.
///
/// - Parameter selectionType: cell selection type.
/// - Returns: a background color to apply to cell.
func mullvadCellBackgroundColor(selectionType: UIBackgroundConfiguration.CellSelectionType) -> UIColor {
switch selectionType {
case .dimmed:
if isSelected || isHighlighted {
UIColor.Cell.selectedAltBackgroundColor
} else {
UIColor.Cell.backgroundColor
}
case .green:
if isSelected || isHighlighted {
UIColor.Cell.selectedBackgroundColor
} else {
UIColor.Cell.backgroundColor
}
}
}
}
|