I am using the auto keyboard dismiss SwiftUI code from How to hide keyboard when using SwiftUI?
Under AnyGestureRecognizer, I'll like to cancel when the touch is still within the UITextView or if it is on a selected Text within a SwiftUI TextField (e.g. that user can drag to select a wider range of the text).
I've noticed that when I tap on the selected text (i.e. 'consequent' in the image below which is already selected), the touchesBegan function returns 'state = .began'. And touches.first?.view is returned as
▿ Optional<UIView>
- some : <UITextRangeView: 0x104f0b750; frame = (0 0; 0 0); opaque = NO; gestureRecognizers = <NSArray: 0x2832778a0>; layer = <CALayer: 0x283c06440>>
I tried to check if add a if statement to check if touches.first?.view is a UITextRange but it returns nil. How can I check for a UITextRangeView?. Thanks!