Skip to content

Commit ab8a334

Browse files
committed
fix: wrong selection coordinates on focus (iOS 16+)
1 parent 3e059e7 commit ab8a334

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

ios/observers/FocusedInputObserver.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,18 @@ public class FocusedInputObserver: NSObject {
142142
setupObservers()
143143
// dispatch onSelectionChange on focus
144144
if let textInput = responder as? UITextInput {
145-
updateSelectionPosition(textInput: textInput, sendEvent: onSelectionChange)
145+
if #available(iOS 16.0, *),
146+
let textView = textInput as? UITextView,
147+
textView.textLayoutManager != nil
148+
{
149+
// Using TextKit 2: layout may not be ready, so defer
150+
DispatchQueue.main.async {
151+
updateSelectionPosition(textInput: textInput, sendEvent: self.onSelectionChange)
152+
}
153+
} else {
154+
// TextKit 1 (or pre-iOS 16): coords are ready synchronously
155+
updateSelectionPosition(textInput: textInput, sendEvent: onSelectionChange)
156+
}
146157
}
147158

148159
syncUpLayout()

0 commit comments

Comments
 (0)