From 5ebb9d2fcd77a92edf392cb53146a5e5fe85e8c9 Mon Sep 17 00:00:00 2001 From: Joshua Quick Date: Thu, 14 Oct 2021 17:56:32 -0700 Subject: [PATCH] fix(ios): drag-and-drop text in TextArea can crash on iOS 15 Fixes TIMOB-28556 --- iphone/Classes/TiUITextArea.h | 1 + iphone/Classes/TiUITextArea.m | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/iphone/Classes/TiUITextArea.h b/iphone/Classes/TiUITextArea.h index da9149a1ec5..42c79af8c79 100644 --- a/iphone/Classes/TiUITextArea.h +++ b/iphone/Classes/TiUITextArea.h @@ -18,6 +18,7 @@ @property (nonatomic, readwrite, assign) BOOL enableCopy; - (void)setTouchHandler:(TiUIView *)handler; +- (NSComparisonResult)comparePosition:(UITextPosition *)position toPosition:(UITextPosition *)other; @end diff --git a/iphone/Classes/TiUITextArea.m b/iphone/Classes/TiUITextArea.m index 81856722332..39ac15b04ad 100644 --- a/iphone/Classes/TiUITextArea.m +++ b/iphone/Classes/TiUITextArea.m @@ -38,6 +38,18 @@ - (void)setTouchHandler:(TiUIView *)handler touchHandler = handler; } +- (NSComparisonResult)comparePosition:(UITextPosition *)position toPosition:(UITextPosition *)other +{ + NSComparisonResult result = NSOrderedAscending; + @try { + result = [super comparePosition:position toPosition:other]; + } + @catch (NSException *ex) { + // Ignore exception that can occur on iOS 15 if "maxLength" trims text that was dragged-and-dropped. + } + return result; +} + - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view { //If the content view is of type TiUIView touch events will automatically propagate @@ -376,7 +388,7 @@ - (BOOL)textView:(UITextView *)tv shouldChangeTextInRange:(NSRange)range replace } } - return TRUE; + return YES; } - (void)setHandleLinks_:(id)args