Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25.2k
feat: [iOS] add caretHeight and caretYoffset to TextInput component#37147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e8e577e148d1621f1d08bf55a9fff91c45f1f3fd22File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -668,6 +668,20 @@ export interface TextInputProps | ||
| */ | ||
| caretHidden?: boolean | undefined; | ||
| /** | ||
| * Allows to adjust caret height. | ||
| * The default value is 0, which means the height of the caret will be calculated automatically | ||
| * @platform ios | ||
| */ | ||
| caretHeight?: number | undefined; | ||
| /** | ||
| * Allows to adjust caret position relative to the Y axis | ||
| * The default value is 0. | ||
| * @platform ios | ||
| */ | ||
| caretYOffset?: number | undefined; | ||
sammy-SC marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * If true, context menu is hidden. The default value is false. | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -591,6 +591,20 @@ export type Props = $ReadOnly<{| | ||
| */ | ||
| caretHidden?: ?boolean, | ||
| /** | ||
| * Allows to adjust caret height. | ||
| * The default value is 0, which means the height of the caret will be calculated automatically | ||
| * @platform ios | ||
| */ | ||
| caretYOffset?: ?number, | ||
sammy-SC marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Allows to adjust caret position relative to the Y axis | ||
| * The default value is 0. | ||
| * @platform ios | ||
| */ | ||
| caretYHeight?: ?number, | ||
sammy-SC marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| /* | ||
| * If `true`, contextMenuHidden is hidden. The default value is `false`. | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -365,6 +365,20 @@ type IOSProps = $ReadOnly<{| | ||
| * @platform ios | ||
| */ | ||
| smartInsertDelete?: ?boolean, | ||
| /** | ||
| * Allows to adjust caret height. | ||
| * The default value is 0, which means the height of the caret will be calculated automatically | ||
| * @platform ios | ||
| */ | ||
| caretYOffset?: ?number, | ||
sammy-SC marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Allows to adjust caret position relative to the Y axis | ||
| * The default value is 0. | ||
| * @platform ios | ||
| */ | ||
| caretHeight?: ?number, | ||
sammy-SC marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| |}>; | ||
| type AndroidProps = $ReadOnly<{| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -13,6 +13,33 @@ | ||
| #import <React/RCTBackedTextInputDelegateAdapter.h> | ||
| #import <React/RCTTextAttributes.h> | ||
| // subclass needs to be created as UITextSelectionRect is an abstract base class | ||
| @interface RCTTextSelectionRect : UITextSelectionRect | ||
| @property (nonatomic, assign) CGRect rect; | ||
| @property (nonatomic, assign) NSWritingDirection writingDirection; | ||
| @property (nonatomic, assign) BOOL containsStart; // Returns YES if the rect contains the start of the selection. | ||
| @property (nonatomic, assign) BOOL containsEnd; // Returns YES if the rect contains the end of the selection. | ||
| @property (nonatomic, assign) BOOL isVertical; // Returns YES if the rect is for vertically oriented text. | ||
| @end | ||
| @implementation RCTTextSelectionRect { | ||
| CGRect _customRect; | ||
| NSWritingDirection _customWritingDirection; | ||
| BOOL _customContainsStart; | ||
| BOOL _customContainsEnd; | ||
| BOOL _customIsVertical; | ||
| } | ||
| @synthesize rect = _customRect; | ||
| @synthesize writingDirection = _customWritingDirection; | ||
| @synthesize containsStart = _customContainsStart; | ||
| @synthesize containsEnd = _customContainsEnd; | ||
| @synthesize isVertical = _customIsVertical; | ||
| @end | ||
| @implementation RCTUITextView { | ||
| UILabel *_placeholderView; | ||
| UITextView *_detachedTextView; | ||
| @@ -307,11 +334,44 @@ - (void)_updatePlaceholder | ||
| - (CGRect)caretRectForPosition:(UITextPosition *)position | ||
| { | ||
| CGRect originalRect = [super caretRectForPosition:position]; | ||
| if (_caretHidden) { | ||
| return CGRectZero; | ||
| } | ||
| return [super caretRectForPosition:position]; | ||
| if(_caretYOffset != 0) { | ||
| originalRect.origin.y += _caretYOffset; | ||
| } | ||
| if(_caretHeight != 0) { | ||
| originalRect.size.height = _caretHeight; | ||
| } | ||
| return originalRect; | ||
| } | ||
| - (NSArray<UITextSelectionRect *> *)selectionRectsForRange:(UITextRange *)range { | ||
| NSArray *superRects = [super selectionRectsForRange:range]; | ||
| if(_caretYOffset != 0 && _caretHeight != 0) { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The block should only be executed if both properties are set. | ||
| NSMutableArray *customTextSelectionRects = [NSMutableArray array]; | ||
| for (UITextSelectionRect *rect in superRects) { | ||
| RCTTextSelectionRect *customTextRect = [[RCTTextSelectionRect alloc] init]; | ||
| customTextRect.rect = CGRectMake(rect.rect.origin.x, rect.rect.origin.y + _caretYOffset, rect.rect.size.width, _caretHeight); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This then needs to handle Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The block should only be executed if both properties are set. | ||
| customTextRect.writingDirection = rect.writingDirection; | ||
| customTextRect.containsStart = rect.containsStart; | ||
| customTextRect.containsEnd = rect.containsEnd; | ||
| customTextRect.isVertical = rect.isVertical; | ||
| [customTextSelectionRects addObject:customTextRect]; | ||
| } | ||
| return customTextSelectionRects; | ||
| } | ||
| return superRects; | ||
| } | ||
| #pragma mark - Utility Methods | ||
Uh oh!
There was an error while loading. Please reload this page.