Autocomplete: tweaks to view hierarchy

This commit is contained in:
James Magahern
2020-09-21 18:09:00 -07:00
parent 3086ed7eae
commit 14a28a0776
3 changed files with 31 additions and 5 deletions

View File

@@ -30,6 +30,8 @@ class AutocompleteViewController: UIViewController, UICollectionViewDelegate
}
public let collectionView: UICollectionView
private let autocompleteView: AutocompleteView
private let dataSource: UICollectionViewDiffableDataSource<Section, HistoryItem>
init() {
@@ -49,6 +51,8 @@ class AutocompleteViewController: UIViewController, UICollectionViewDelegate
collectionView.dequeueConfiguredReusableCell(using: cellRegistry, for: indexPath, item: item)
})
autocompleteView = AutocompleteView(collectionView: collectionView)
super.init(nibName: nil, bundle: nil)
collectionView.delegate = self
@@ -58,7 +62,7 @@ class AutocompleteViewController: UIViewController, UICollectionViewDelegate
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
override func loadView() {
self.view = collectionView
self.view = autocompleteView
}
// MARK: UICollectionViewDelegate
@@ -70,4 +74,24 @@ class AutocompleteViewController: UIViewController, UICollectionViewDelegate
delegate?.autocompleteController(self, didSelectHistoryItem: item)
}
}
private class AutocompleteView: UIView {
let collectionView: UICollectionView
init(collectionView: UICollectionView) {
self.collectionView = collectionView
super.init(frame: .zero)
addSubview(collectionView)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
collectionView.frame = bounds
}
}
}