Skip to content

Commit

Permalink
TextInput on iOS: Fixing selectAll feature for multiline text input
Browse files Browse the repository at this point in the history
Summary:
`selectAll:` does not work for UITextView when it's being called inside UITextView's delegate methods.

This is a bug in UIKit and this quite ugly workaround is only a known solution for it.

Changelog: [Bug][iOS] Fixed bug in implementation of <TextInput>'s selectOnFocus prop

Reviewed By: sammy-SC

Differential Revision: D18966755

fbshipit-source-id: 2ba15fa94570d463a2ea3490331fb879611dc6b8
  • Loading branch information
shergin authored and facebook-github-bot committed Dec 16, 2019
1 parent 96a6ffb commit e020576
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Libraries/Text/TextInput/Multiline/RCTUITextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ - (void)setContentOffset:(CGPoint)contentOffset animated:(__unused BOOL)animated
[super setContentOffset:contentOffset animated:NO];
}

- (void)selectAll:(id)sender
{
[super selectAll:sender];

// `selectAll:` does not work for UITextView when it's being called inside UITextView's delegate methods.
dispatch_async(dispatch_get_main_queue(), ^{
UITextRange *selectionRange = [self textRangeFromPosition:self.beginningOfDocument toPosition:self.endOfDocument];
[self setSelectedTextRange:selectionRange notifyDelegate:NO];
});
}

#pragma mark - Layout

- (CGFloat)preferredMaxLayoutWidth
Expand Down

0 comments on commit e020576

Please sign in to comment.