Remote tabs: finishing touches
This commit is contained in:
@@ -28,6 +28,30 @@ struct LabelContentConfiguration : UIContentConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
struct TextFieldContentConfiguration : UIContentConfiguration
|
||||
{
|
||||
var text: String = ""
|
||||
var placeholderText: String? = nil
|
||||
var textChanged: ((String) -> Void)
|
||||
|
||||
func makeContentView() -> UIView & UIContentView {
|
||||
let textField = UITextField(frame: .zero)
|
||||
textField.borderStyle = .roundedRect
|
||||
textField.autocorrectionType = .no
|
||||
textField.autocapitalizationType = .none
|
||||
|
||||
return GenericContentView<UITextField, TextFieldContentConfiguration>(configuration: self, view: textField) { config, textField in
|
||||
textField.text = config.text
|
||||
textField.placeholder = config.placeholderText
|
||||
textField.addAction(UIAction { _ in config.textChanged(textField.text ?? "") }, for: .editingChanged)
|
||||
}
|
||||
}
|
||||
|
||||
func updated(for state: UIConfigurationState) -> TextFieldContentConfiguration {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
struct ButtonContentConfiguration : UIContentConfiguration
|
||||
{
|
||||
var menu: UIMenu
|
||||
@@ -56,11 +80,13 @@ class GeneralSettingsViewController: UIViewController
|
||||
{
|
||||
enum Section: String, CaseIterable {
|
||||
case searchEngine = "Search Engine"
|
||||
case syncServer = "Sync Server"
|
||||
}
|
||||
|
||||
typealias Item = String
|
||||
|
||||
static let SearchProviderPopupItem = "searchProvider.popup"
|
||||
static let SyncServerItem = "syncServer.field"
|
||||
|
||||
let dataSource: UICollectionViewDiffableDataSource<Section, Item>
|
||||
let collectionView: UICollectionView
|
||||
@@ -109,7 +135,7 @@ class GeneralSettingsViewController: UIViewController
|
||||
if idiom == .mac {
|
||||
return LabelContentConfiguration(
|
||||
text: sectionName + ": ",
|
||||
insets: UIEdgeInsets(top: 0, left: 10.0, bottom: 0, right: 10.0),
|
||||
insets: UIEdgeInsets(top: 0.0, left: 10.0, bottom: 0, right: 10.0),
|
||||
textAlignment: .right
|
||||
)
|
||||
} else {
|
||||
@@ -141,11 +167,19 @@ class GeneralSettingsViewController: UIViewController
|
||||
})
|
||||
|
||||
cell.contentConfiguration = ButtonContentConfiguration(menu: menu)
|
||||
|
||||
#if !targetEnvironment(macCatalyst)
|
||||
cell.backgroundConfiguration = UIBackgroundConfiguration.listGroupedCell()
|
||||
#endif
|
||||
} else if identifier == Self.SyncServerItem {
|
||||
cell.contentConfiguration = TextFieldContentConfiguration(
|
||||
text: Settings.shared.syncServer,
|
||||
placeholderText: "https://sync.server.com",
|
||||
textChanged: { newString in
|
||||
Settings.shared.syncServer = newString
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
#if !targetEnvironment(macCatalyst)
|
||||
cell.backgroundConfiguration = UIBackgroundConfiguration.listGroupedCell()
|
||||
#endif
|
||||
}
|
||||
|
||||
let sectionHeaderRegistry = UICollectionView.SupplementaryRegistration<UICollectionViewCell>(elementKind: UICollectionView.elementKindSectionHeader, handler: {
|
||||
@@ -189,6 +223,7 @@ class GeneralSettingsViewController: UIViewController
|
||||
// iOS
|
||||
// snapshot.appendItems(Settings.SearchProviderSetting.allCases.map { $0.rawValue }, toSection: .searchEngine)
|
||||
snapshot.appendItems([ Self.SearchProviderPopupItem ], toSection: .searchEngine)
|
||||
snapshot.appendItems([ Self.SyncServerItem ], toSection: .syncServer)
|
||||
dataSource.apply(snapshot, animatingDifferences: false)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user