Skip to content

Commit 2ddc578

Browse files
committed
Fix split views on Catalyst
1 parent 513458a commit 2ddc578

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

.github/workflows/build-test-and-docs.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ jobs:
165165
buildtarget PathsExample
166166
buildtarget ControlsExample
167167
buildtarget RandomNumberGeneratorExample
168-
# TODO test whether this works on Catalyst
169-
# buildtarget SplitExample
168+
buildtarget SplitExample
170169
171170
windows:
172171
runs-on: windows-latest

Examples/Bundler.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ identifier = 'dev.swiftcrossui.SplitExample'
3535
product = 'SplitExample'
3636
version = '0.1.0'
3737

38+
[[apps.SplitExample.overlays]]
39+
condition = "platform(macCatalyst)"
40+
interface_idiom = "mac"
41+
3842
[apps.SpreadsheetExample]
3943
identifier = 'dev.swiftcrossui.SpreadsheetExample'
4044
product = 'SpreadsheetExample'

Sources/UIKitBackend/UIKitBackend+SplitView.swift

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
11
import UIKit
22

3-
#if os(iOS)
3+
#if os(iOS) || targetEnvironment(macCatalyst)
44
final class SplitWidget: WrapperControllerWidget<UISplitViewController>,
55
UISplitViewControllerDelegate
66
{
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+
731
var resizeHandler: (() -> Void)?
8-
private let sidebarContainer: ContainerWidget
9-
private let mainContainer: ContainerWidget
32+
private let sidebarContainer: ColumnWidget
33+
private let mainContainer: ColumnWidget
1034

1135
init(sidebarWidget: some WidgetProtocol, mainWidget: some WidgetProtocol) {
1236
// 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)
1539

1640
super.init(child: UISplitViewController())
1741

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+
1848
child.delegate = self
1949

2050
child.preferredDisplayMode = .oneBesideSecondary
@@ -45,11 +75,6 @@ import UIKit
4575

4676
super.viewDidLoad()
4777
}
48-
49-
override func viewDidLayoutSubviews() {
50-
super.viewDidLayoutSubviews()
51-
resizeHandler?()
52-
}
5378
}
5479

5580
extension UIKitBackend {

0 commit comments

Comments
 (0)