Skip to content

Commit bf3dfdf

Browse files
committed
0.1.4
1 parent 6dce58e commit bf3dfdf

File tree

6 files changed

+35
-198
lines changed

6 files changed

+35
-198
lines changed

Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ let package = Package(
1515
),
1616
],
1717
dependencies: [
18-
.package(url: "https://github.com/nathantannar4/Engine", from: "0.1.1"),
19-
.package(url: "https://github.com/nathantannar4/Turbocharger", from: "0.1.1"),
18+
.package(url: "https://github.com/nathantannar4/Engine", from: "0.1.3"),
19+
.package(url: "https://github.com/nathantannar4/Turbocharger", from: "0.1.2"),
2020
],
2121
targets: [
2222
.target(

Sources/Transmission/Sources/Hosting/HostingController.swift

+2-10
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ open class HostingController<
5252
}
5353

5454
if #available(iOS 16.0, *) {
55-
// Sync SwiftUI/UIKit animation
56-
try? view?.unsafeSetValue(true, forKey: "allowUIKitAnimationsForNextUpdate")
55+
try? swift_setFieldValue("allowUIKitAnimationsForNextUpdate", true, view)
5756
performTransition()
5857
} else {
5958
withCATransaction {
@@ -62,8 +61,7 @@ open class HostingController<
6261
}
6362
} else if tracksContentSize {
6463
if #available(iOS 16.0, *) {
65-
// Sync SwiftUI/UIKit animation
66-
try? view?.unsafeSetValue(true, forKey: "allowUIKitAnimationsForNextUpdate")
64+
try? swift_setFieldValue("allowUIKitAnimationsForNextUpdate", true, view)
6765
if let popoverPresentationController = presentationController as? UIPopoverPresentationController,
6866
let containerView = popoverPresentationController.containerView
6967
{
@@ -117,12 +115,6 @@ open class _HostingController<
117115
public required init?(coder aDecoder: NSCoder) {
118116
fatalError("init(coder:) has not been implemented")
119117
}
120-
121-
deinit {
122-
#if DEBUG
123-
print("Deinit HostingController<\(String(describing: Content.self))>")
124-
#endif
125-
}
126118
}
127119

128120
#endif

Sources/Transmission/Sources/Hosting/HostingView.swift

+30-31
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,40 @@
55
#if os(iOS)
66

77
import SwiftUI
8+
import Engine
89
import Turbocharger
910

1011
open class HostingView<
1112
Content: View
12-
>: _UIHostingView<_HostingViewContent<Content>> {
13+
>: _UIHostingView<Content> {
1314

1415
public var content: Content {
15-
get { adapter.content }
16-
set { adapter.content = newValue }
16+
get {
17+
if #available(iOS 16.0, *) {
18+
return rootView
19+
} else {
20+
do {
21+
return try swift_getFieldValue("_rootView", Content.self, self)
22+
} catch {
23+
fatalError("\(error)")
24+
}
25+
}
26+
}
27+
set {
28+
if #available(iOS 16.0, *) {
29+
rootView = newValue
30+
} else {
31+
do {
32+
var flags = try swift_getFieldValue("propertiesNeedingUpdate", UInt16.self, self)
33+
try swift_setFieldValue("_rootView", newValue, self)
34+
flags |= 1
35+
try swift_setFieldValue("propertiesNeedingUpdate", flags, self)
36+
setNeedsLayout()
37+
} catch {
38+
fatalError("\(error)")
39+
}
40+
}
41+
}
1742
}
1843

1944
public var disablesSafeArea: Bool = false
@@ -25,12 +50,8 @@ open class HostingView<
2550
return super.safeAreaInsets
2651
}
2752

28-
private let adapter: HostingViewContentAdapter<Content>
29-
3053
public init(content: Content) {
31-
let adapter = HostingViewContentAdapter(content: content)
32-
self.adapter = adapter
33-
super.init(rootView: _HostingViewContent(adapter: adapter))
54+
super.init(rootView: content)
3455
backgroundColor = nil
3556
}
3657

@@ -43,7 +64,7 @@ open class HostingView<
4364
}
4465

4566
@available(iOS, obsoleted: 13.0, renamed: "init(content:)")
46-
public required init(rootView: _HostingViewContent<Content>) {
67+
public required init(rootView: Content) {
4768
fatalError("init(rootView:) has not been implemented")
4869
}
4970

@@ -55,26 +76,4 @@ open class HostingView<
5576
}
5677
}
5778

58-
private class HostingViewContentAdapter<Content: View>: ObservableObject {
59-
var content: Content {
60-
didSet {
61-
withCATransaction {
62-
self.objectWillChange.send()
63-
}
64-
}
65-
}
66-
67-
init(content: Content) {
68-
self.content = content
69-
}
70-
}
71-
72-
public struct _HostingViewContent<Content: View>: View {
73-
@ObservedObject fileprivate var adapter: HostingViewContentAdapter<Content>
74-
75-
public var body: some View {
76-
adapter.content
77-
}
78-
}
79-
8079
#endif

Sources/Transmission/Sources/Hosting/HostingWindow.swift

-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ open class HostingWindow<Content: View>: UIWindow {
3939
fatalError("init(coder:) has not been implemented")
4040
}
4141

42-
deinit {
43-
#if DEBUG
44-
print("Deinit HostingWindow<\(String(describing: Content.self))>")
45-
#endif
46-
}
47-
4842
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
4943
let result = super.hitTest(point, with: event)
5044
if result == rootViewController?.view || result == self {

Sources/Transmission/Sources/Supporting Files/UnsafeReflectable.swift

-148
This file was deleted.

Sources/Transmission/Sources/View/PresentationLinkAdapter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#if os(iOS)
66

77
import SwiftUI
8-
import EngineCore
8+
import Engine
99
import Turbocharger
1010

1111
/// A modifier that presents a destination view in a new `UIViewController`.

0 commit comments

Comments
 (0)