Skip to content

Commit 55ea3eb

Browse files
author
JWI
committed
removing weak self captures for debugging
1 parent 0794d2c commit 55ea3eb

File tree

1 file changed

+5
-47
lines changed

1 file changed

+5
-47
lines changed

Sources/SwiftCrossUI/Scenes/WindowGroupNode.swift

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ public final class WindowGroupNode<Content: View>: SceneGraphNode {
4444
self.window = window
4545
parentEnvironment = environment
4646

47-
backend.setResizeHandler(ofWindow: window) { [weak self] newSize in
48-
guard let self else {
49-
return
50-
}
47+
backend.setResizeHandler(ofWindow: window) { newSize in
5148
_ = self.update(
5249
self.scene,
5350
proposedWindowSize: newSize,
@@ -58,10 +55,7 @@ public final class WindowGroupNode<Content: View>: SceneGraphNode {
5855
)
5956
}
6057

61-
backend.setWindowEnvironmentChangeHandler(of: window) { [weak self] in
62-
guard let self else {
63-
return
64-
}
58+
backend.setWindowEnvironmentChangeHandler(of: window) {
6559
_ = self.update(
6660
self.scene,
6761
proposedWindowSize: backend.size(ofWindow: window),
@@ -110,11 +104,6 @@ public final class WindowGroupNode<Content: View>: SceneGraphNode {
110104
parentEnvironment = environment
111105

112106
if let newScene = newScene {
113-
// Don't set default size even if it has changed. We only set that once
114-
// at window creation since some backends don't have a concept of
115-
// 'default' size which would mean that setting the default size every time
116-
// the default size changed would resize the window (which is incorrect
117-
// behaviour).
118107
backend.setTitle(ofWindow: window, to: newScene.title)
119108
backend.setResizability(ofWindow: window, to: newScene.resizability.isResizable)
120109
scene = newScene
@@ -125,9 +114,8 @@ public final class WindowGroupNode<Content: View>: SceneGraphNode {
125114
rootEnvironment: environment
126115
)
127116

128-
// Assign onResize manually
129-
newEnvironment.onResize = { [weak self] _ in
130-
guard let self = self else { return }
117+
// Assign onResize manually, strong capture
118+
newEnvironment.onResize = { _ in
131119
_ = self.update(
132120
self.scene,
133121
proposedWindowSize: backend.size(ofWindow: window),
@@ -144,8 +132,6 @@ public final class WindowGroupNode<Content: View>: SceneGraphNode {
144132

145133
let dryRunResult: ViewUpdateResult?
146134
if !windowSizeIsFinal {
147-
// Perform a dry-run update of the root view to check if the window
148-
// needs to change size.
149135
let contentResult = viewGraph.update(
150136
with: newScene?.body,
151137
proposedSize: proposedWindowSize,
@@ -161,9 +147,6 @@ public final class WindowGroupNode<Content: View>: SceneGraphNode {
161147
environment: environment
162148
)
163149

164-
// Restart the window update if the content has caused the window to
165-
// change size. To avoid infinite recursion, we take the view's word
166-
// and assume that it will take on the minimum/maximum size it claimed.
167150
if let newWindowSize {
168151
return update(
169152
scene,
@@ -184,40 +167,17 @@ public final class WindowGroupNode<Content: View>: SceneGraphNode {
184167
dryRun: false
185168
)
186169

187-
// The Gtk 3 backend has some broken sizing code that can't really be
188-
// fixed due to the design of Gtk 3. Our layout system underestimates
189-
// the size of the new view due to the button not being in the Gtk 3
190-
// widget hierarchy yet (which prevents Gtk 3 from computing the
191-
// natural sizes of the new buttons). One fix seems to be removing
192-
// view size reuse (currently the second check in ViewGraphNode.update)
193-
// and I'm not exactly sure why, but that makes things awfully slow.
194-
// The other fix is to add an alternative path to
195-
// Gtk3Backend.naturalSize(of:) for buttons that moves non-realized
196-
// buttons to a secondary window before measuring their natural size,
197-
// but that's super janky, easy to break if the button in the real
198-
// window is inheriting styles from its ancestors, and I'm not sure
199-
// how to hide the window (it's probably terrible for performance too).
200-
//
201-
// I still have no clue why this size underestimation (and subsequent
202-
// mis-sizing of the window) had the symptom of all buttons losing
203-
// their labels temporarily; Gtk 3 is a temperamental beast.
204-
//
205-
// Anyway, Gtk3Backend isn't really intended to be a recommended
206-
// backend so I think this is a fine solution for now (people should
207-
// only use Gtk3Backend if they can't use GtkBackend).
208170
if let dryRunResult, finalContentResult.size != dryRunResult.size {
209171
print(
210172
"""
211173
warning: Final window content size didn't match dry-run size. This is a sign that
212-
either view size caching is broken or that backend.naturalSize(of:) is
174+
either view size caching is broken or that backend.naturalSize(of:) is
213175
broken (or both).
214176
-> dryRunResult.size: \(dryRunResult.size)
215177
-> finalContentResult.size: \(finalContentResult.size)
216178
"""
217179
)
218180

219-
// Give the view graph one more chance to sort itself out to fail
220-
// as gracefully as possible.
221181
let newWindowSize = computeNewWindowSize(
222182
currentProposedSize: proposedWindowSize,
223183
backend: backend,
@@ -236,8 +196,6 @@ public final class WindowGroupNode<Content: View>: SceneGraphNode {
236196
}
237197
}
238198

239-
// Set this even if the window isn't programmatically resizable
240-
// because the window may still be user resizable.
241199
if scene.resizability.isResizable {
242200
backend.setMinimumSize(
243201
ofWindow: window,

0 commit comments

Comments
 (0)