Skip to content

Add cursor style to Text #1469

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

Merged
merged 5 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Libraries/Text/BaseText/RCTBaseTextViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/

#import <React/RCTBaseTextViewManager.h>
#if TARGET_OS_OSX // [TODO(macOS GH#774)
#import <React/RCTCursor.h>
#endif // ]TODO(macOS GH#774)

@implementation RCTBaseTextViewManager

Expand Down Expand Up @@ -56,4 +59,8 @@ - (RCTShadowView *)shadowView
RCT_REMAP_SHADOW_PROPERTY(isHighlighted, textAttributes.isHighlighted, BOOL)
RCT_REMAP_SHADOW_PROPERTY(textTransform, textAttributes.textTransform, RCTTextTransform)

#if TARGET_OS_OSX // [TODO(macOS GH#774)
RCT_REMAP_SHADOW_PROPERTY(cursor, textAttributes.cursor, RCTCursor)
#endif // ]TODO(macOS GH#774)

@end
12 changes: 9 additions & 3 deletions Libraries/Text/RCTTextAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
*/

#import <React/RCTUIKit.h> // TODO(macOS GH#774)

#import <React/RCTTextDecorationLineType.h>
#import <React/RCTDynamicTypeRamp.h> // TODO(macOS GH#774)
#import <React/RCTFontSmoothing.h> // TODO(OSS Candidate ISS#2710739)

#import <React/RCTFontSmoothing.h> // TODO(macOS GH#774)
#import "RCTTextTransform.h"

#if TARGET_OS_OSX // [TODO(macOS GH#774)
#import <React/RCTCursor.h>
#endif // ]TODO(macOS GH#774)

NS_ASSUME_NONNULL_BEGIN

extern NSString *const RCTTextAttributesIsHighlightedAttributeName;
Expand Down Expand Up @@ -61,6 +63,10 @@ extern NSString *const RCTTextAttributesTagAttributeName;
@property (nonatomic, assign) UIUserInterfaceLayoutDirection layoutDirection;
@property (nonatomic, assign) RCTTextTransform textTransform;

#if TARGET_OS_OSX // [TODO(macOS GH#774)
@property (nonatomic, assign) RCTCursor cursor;
#endif // ]TODO(macOS GH#774)

#pragma mark - Inheritance

- (void)applyTextAttributes:(RCTTextAttributes *)textAttributes;
Expand Down
17 changes: 17 additions & 0 deletions Libraries/Text/RCTTextAttributes.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#import <React/RCTFont.h>
#import <React/RCTLog.h>

#if TARGET_OS_OSX // [TODO(macOS GH#774)
#import <React/RCTCursor.h>
#endif // ]TODO(macOS GH#774)

NSString *const RCTTextAttributesIsHighlightedAttributeName = @"RCTTextAttributesIsHighlightedAttributeName";
NSString *const RCTTextAttributesFontSmoothingAttributeName = @"RCTTextAttributesFontSmoothingAttributeName"; // TODO(OSS Candidate ISS#2710739)
NSString *const RCTTextAttributesTagAttributeName = @"RCTTextAttributesTagAttributeName";
Expand Down Expand Up @@ -45,6 +49,9 @@ - (instancetype)init
// [TODO(macOS GH#774)
_foregroundColor = [RCTTextAttributes defaultForegroundColor];
// ]TODO(macOS GH#774)
#if TARGET_OS_OSX // [TODO(macOS GH#774)
_cursor = RCTCursorAuto;
#endif // ]TODO(macOS GH#774)
}

return self;
Expand Down Expand Up @@ -94,6 +101,10 @@ - (void)applyTextAttributes:(RCTTextAttributes *)textAttributes
_tag = textAttributes->_tag ?: _tag;
_layoutDirection = textAttributes->_layoutDirection != UIUserInterfaceLayoutDirectionLeftToRight ? textAttributes->_layoutDirection : _layoutDirection;
_textTransform = textAttributes->_textTransform != RCTTextTransformUndefined ? textAttributes->_textTransform : _textTransform;

#if TARGET_OS_OSX // [TODO(macOS GH#774)
_cursor = textAttributes->_cursor != RCTCursorAuto ? textAttributes->_cursor : _cursor;
#endif // ]TODO(macOS GH#774)
}

- (NSParagraphStyle *)effectiveParagraphStyle
Expand Down Expand Up @@ -210,6 +221,12 @@ - (NSParagraphStyle *)effectiveParagraphStyle
attributes[RCTTextAttributesTagAttributeName] = _tag;
}

#if TARGET_OS_OSX // [TODO(macOS GH#774)
if (_cursor != RCTCursorAuto) {
attributes[NSCursorAttributeName] = [RCTConvert NSCursor:_cursor];
}
#endif // ]TODO(macOS GH#774)

return [attributes copy];
}

Expand Down
4 changes: 0 additions & 4 deletions Libraries/Text/Text/RCTTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

#if TARGET_OS_OSX // [TODO(macOS GH#774)

#endif // ]TODO(macOS GH#774)

#if DEBUG // TODO(macOS GH#774) description is a debug-only feature
- (NSString *)description
{
Expand Down
29 changes: 29 additions & 0 deletions packages/rn-tester/js/examples/Text/TextExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -1303,4 +1303,33 @@ exports.examples = [
);
},
},
// [TODO(macOS GH#774)
{
title: 'Cursor',
render: function (): React.Node {
return (
<View>
<Text style={{cursor: 'pointer'}} selectable={true}>
This text has pointer cursor.
</Text>
</View>
);
},
},
{
title: 'Cursor nested (virtual) text',
render: function (): React.Node {
return (
<View>
<Text selectable={true}>
This text has regular cursor.{' '}
<Text style={{cursor: 'pointer'}}>
This text has pointer cursor.
</Text>
</Text>
</View>
);
},
},
// ]TODO(macOS GH#774)
];