|
1 | 1 | import UIKit |
2 | 2 |
|
3 | | -#if os(iOS) |
| 3 | +#if os(iOS) || targetEnvironment(macCatalyst) |
4 | 4 | final class SplitWidget: WrapperControllerWidget<UISplitViewController>, |
5 | 5 | UISplitViewControllerDelegate |
6 | 6 | { |
| 7 | + private final class ColumnView: UIView { |
| 8 | + unowned var splitWidget: SplitWidget! |
| 9 | + |
| 10 | + @available(*, unavailable) |
| 11 | + required init?(coder: NSCoder) { |
| 12 | + fatalError("init(coder:) is not used for this view") |
| 13 | + } |
| 14 | + |
| 15 | + init() { |
| 16 | + super.init(frame: .zero) |
| 17 | + } |
| 18 | + |
| 19 | + override func layoutSubviews() { |
| 20 | + super.layoutSubviews() |
| 21 | + splitWidget.resizeHandler?() |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + private final class ColumnWidget: ContainerWidget { |
| 26 | + override func loadView() { |
| 27 | + view = ColumnView() |
| 28 | + } |
| 29 | + } |
| 30 | + |
7 | 31 | var resizeHandler: (() -> Void)? |
8 | | - private let sidebarContainer: ContainerWidget |
9 | | - private let mainContainer: ContainerWidget |
| 32 | + private let sidebarContainer: ColumnWidget |
| 33 | + private let mainContainer: ColumnWidget |
10 | 34 |
|
11 | 35 | init(sidebarWidget: some WidgetProtocol, mainWidget: some WidgetProtocol) { |
12 | 36 | // UISplitViewController requires its children to be controllers, not views |
13 | | - sidebarContainer = ContainerWidget(child: sidebarWidget) |
14 | | - mainContainer = ContainerWidget(child: mainWidget) |
| 37 | + sidebarContainer = ColumnWidget(child: sidebarWidget) |
| 38 | + mainContainer = ColumnWidget(child: mainWidget) |
15 | 39 |
|
16 | 40 | super.init(child: UISplitViewController()) |
17 | 41 |
|
| 42 | + sidebarContainer.parentWidget = self |
| 43 | + mainContainer.parentWidget = self |
| 44 | + childWidgets = [sidebarContainer, mainContainer] |
| 45 | + (sidebarContainer.view as! ColumnView).splitWidget = self |
| 46 | + (mainContainer.view as! ColumnView).splitWidget = self |
| 47 | + |
18 | 48 | child.delegate = self |
19 | 49 |
|
20 | 50 | child.preferredDisplayMode = .oneBesideSecondary |
@@ -45,11 +75,6 @@ import UIKit |
45 | 75 |
|
46 | 76 | super.viewDidLoad() |
47 | 77 | } |
48 | | - |
49 | | - override func viewDidLayoutSubviews() { |
50 | | - super.viewDidLayoutSubviews() |
51 | | - resizeHandler?() |
52 | | - } |
53 | 78 | } |
54 | 79 |
|
55 | 80 | extension UIKitBackend { |
|
0 commit comments