Post

Replies

Boosts

Views

Activity

How to restore specific scenes in SwiftUI
I'm trying to implement multiple window support for my app, but the system restores the wrong scene when the app is relaunched. Here's my code: import SwiftUI @main struct TestApp: App { @Environment(\.openWindow) private var openWindow var body: some Scene { WindowGroup(id: "Navigator") { Button { openWindow(id: "Editor", value: "test") } label: { Text("Open Window") } } WindowGroup(id: "Editor", for: String.self) { id in Text(id.wrappedValue ?? "none") } } } If I run the app and tap the button, the Editor window opens. If I force quit and open the app again, the app still has two windows open but both are Navigator windows. I've tried adding handlesExternalEvents to the Scene and advertising an activity with .userActivity(isActive:), neither changes this behaviour. Any advice?
0
0
229
Jul ’24
Tapping a TextKit 2 backed UITextView moves the caret to a random location
With the upcoming launch of Apple Intelligence and Writing Tools, we've been forced to migrate our text editing app to TextKit 2. As soon as we released the update, we immediately got complaints about incorrect selection behaviour, where the user would tap a word to begin editing, but the caret would be shown in an undefined location, often dozens of paragraphs below the selected content. To reproduce: Create a UITextView backed by a standard TextKit 2 stack and a large amount of text (50,000+ words) - see sample project below Scroll quickly through the text view (at least 20% of the way down) Tap once to select a position in the document. Expected: The caret appears at the location the user tapped, and UITextView.selectedRange is the range of the text at the location of the tap. This is the behaviour of TextKit 1 based UITextViews. Actual: The caret is positioned at an undefined location (often completely off screen), and the selectedRange is different to the range at the location of the tap, often by several thousand. There is no pattern to the magnitude of the discrepancy. This incorrect behaviour occurs consistently in the sample project on the simulator, but you may need to hide the keyboard by pulling down, then repeat steps 2-3 a few times. This happens on iPhone and iPad, and on iOS 17, 18, and 18.1. Do you have any insight into why this might be happening or how to work around this issue? Sample code is here: https://github.com/nathantesler/textkit2-issue/tree/master
2
0
416
Sep ’24