blob: d87c00d931219a6aa08da0124a811f2b0c243bfe (
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 © 2025 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.Background.normal
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.Background.normal
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
}
}
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.Background.selectedAlt
} else if isDisabled {
UIColor.Cell.Background.disabled
} else {
UIColor.Cell.Background.normal
}
case .green:
if isSelected || isHighlighted {
UIColor.Cell.Background.selected
} else if isDisabled {
UIColor.Cell.Background.disabled
} else {
UIColor.Cell.Background.normal
}
}
}
}
|