-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ExperimentsSettingsView.swift
88 lines (77 loc) · 4.57 KB
/
ExperimentsSettingsView.swift
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
79
80
81
82
83
84
85
86
87
88
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import UIKit
class ExperimentsSettingsView: UIView {
let customRemoteSettingsTextField: UITextField = .build { textField in
textField.placeholder = "URL to remote settings JSON"
textField.borderStyle = .roundedRect
}
let reloadButton: UIButton = .build { button in
button.setImage(UIImage(named: "nav-refresh"), for: .normal)
}
let usePreviewPrompt: UITextView = .build { prompt in
prompt.text = "Use Preview Collection (requires restart)"
}
let usePreviewToggle: UISwitch = .build()
let customExperimentDataTextView: UITextView = .build { textView in
textView.layer.cornerRadius = 8
textView.textContainer.lineFragmentPadding = 8.0
textView.layer.borderWidth = 1.0
textView.layer.borderColor = UIColor.gray.withAlphaComponent(0.2).cgColor
}
let updateButton: UIButton = .build { button in
button.setTitle("Reset", for: .normal)
button.backgroundColor = .systemRed
}
private let gapView: UIView = .build { view in
view.backgroundColor = .systemRed
}
convenience init() {
self.init(frame: .zero)
backgroundColor = .systemBackground
addSubviews(
customRemoteSettingsTextField,
reloadButton,
usePreviewPrompt,
usePreviewToggle,
customExperimentDataTextView,
updateButton,
gapView)
setupConstraints()
}
private func setupConstraints() {
NSLayoutConstraint.activate([
reloadButton.heightAnchor.constraint(equalTo: customRemoteSettingsTextField.heightAnchor),
reloadButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8.0),
reloadButton.widthAnchor.constraint(equalTo: reloadButton.heightAnchor),
reloadButton.topAnchor.constraint(equalTo: customRemoteSettingsTextField.topAnchor),
customRemoteSettingsTextField.heightAnchor.constraint(equalToConstant: 44.0),
customRemoteSettingsTextField.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8.0),
customRemoteSettingsTextField.trailingAnchor.constraint(equalTo: reloadButton.leadingAnchor, constant: -8.0),
customRemoteSettingsTextField.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor, constant: 8.0),
usePreviewPrompt.topAnchor.constraint(equalTo: customRemoteSettingsTextField.bottomAnchor, constant: 8.0),
usePreviewPrompt.heightAnchor.constraint(equalToConstant: 44.0),
usePreviewPrompt.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8.0),
usePreviewPrompt.trailingAnchor.constraint(equalTo: usePreviewToggle.leadingAnchor, constant: -8.0),
usePreviewPrompt.bottomAnchor.constraint(equalTo: customExperimentDataTextView.topAnchor, constant: 8.0),
usePreviewToggle.topAnchor.constraint(equalTo: customRemoteSettingsTextField.bottomAnchor, constant: 8.0),
usePreviewToggle.heightAnchor.constraint(equalToConstant: 44.0),
usePreviewToggle.leadingAnchor.constraint(equalTo: usePreviewPrompt.trailingAnchor, constant: 8.0),
usePreviewToggle.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8.0),
usePreviewToggle.bottomAnchor.constraint(equalTo: customExperimentDataTextView.topAnchor, constant: 8.0),
customExperimentDataTextView.topAnchor.constraint(equalTo: usePreviewPrompt.bottomAnchor, constant: 8.0),
customExperimentDataTextView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8.0),
customExperimentDataTextView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8.0),
customExperimentDataTextView.bottomAnchor.constraint(equalTo: updateButton.topAnchor, constant: -8.0),
updateButton.heightAnchor.constraint(equalToConstant: 44.0),
updateButton.leadingAnchor.constraint(equalTo: leadingAnchor),
updateButton.trailingAnchor.constraint(equalTo: trailingAnchor),
updateButton.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor),
gapView.topAnchor.constraint(equalTo: updateButton.bottomAnchor),
gapView.leadingAnchor.constraint(equalTo: leadingAnchor),
gapView.trailingAnchor.constraint(equalTo: trailingAnchor),
gapView.bottomAnchor.constraint(equalTo: bottomAnchor),
])
}
}