Skip to content

Commit

Permalink
Add cursor style to View
Browse files Browse the repository at this point in the history
Summary: This brings in PR #760 to our repo.

Test Plan:
RNTester > View:

{F612877442}

Reviewers: skyle

Reviewed By: skyle

Subscribers: necolas, eliwhite

Differential Revision: https://phabricator.intern.facebook.com/D28158243

Tasks: T78743077

Signature: 28158243:1620330169:72c6c9e2371f2ac1a9edabedf3fd9d68468ccb8c

Remove Cursor for Text Component
  • Loading branch information
lyahdav authored and ryanlntn committed Aug 9, 2022
1 parent 2c8eff0 commit 6d81baf
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 83 deletions.
2 changes: 0 additions & 2 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
AccessibilityValue,
} from '../../Components/View/ViewAccessibility';
import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType';
import type {CursorValue} from '../../StyleSheet/StyleSheetTypes';
import type {
BlurEvent,
FocusEvent,
Expand Down Expand Up @@ -49,7 +48,6 @@ type Props = $ReadOnly<{|
accessibilityViewIsModal?: ?boolean,
accessible?: ?boolean,
children?: ?React.Node,
cursor?: ?CursorValue,
delayLongPress?: ?number,
delayPressIn?: ?number,
delayPressOut?: ?number,
Expand Down
1 change: 1 addition & 0 deletions Libraries/Components/View/ReactNativeStyleAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const ReactNativeStyleAttributes: {[string]: AnyAttributeType, ...} = {
borderTopLeftRadius: true,
borderTopRightRadius: true,
borderTopStartRadius: true,
cursor: true,
opacity: true,

/**
Expand Down
5 changes: 5 additions & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,9 @@ export type ViewProps = $ReadOnly<{|
* @platform macos
*/
draggedTypes?: ?DraggedTypesType, // TODO(macOS GH#774)

/*
* Sets the type of mouse cursor, to show when the mouse pointer is over the view.
*/
cursor?: ?CursorValue, // TODO(macOS GH#774)
|}>;
24 changes: 24 additions & 0 deletions Libraries/StyleSheet/StyleSheetTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ import type {NativeColorValue} from './PlatformColorValueTypes';

export type ____ColorValue_Internal = null | string | NativeColorValue;

export type CursorValue = ?(
| 'alias'
| 'auto'
| 'col-resize'
| 'context-menu'
| 'copy'
| 'crosshair'
| 'default'
| 'disappearing-item'
| 'e-resize'
| 'grab'
| 'grabbing'
| 'n-resize'
| 'no-drop'
| 'not-allowed'
| 'pointer'
| 'row-resize'
| 's-resize'
| 'text'
| 'vertical-text'
| 'w-resize'
)

export type ColorArrayValue = null | $ReadOnlyArray<____ColorValue_Internal>;
export type PointValue = {|
x: number,
Expand Down Expand Up @@ -639,6 +662,7 @@ export type ____TextStyle_Internal = $ReadOnly<{|
textDecorationColor?: ____ColorValue_Internal,
textTransform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase',
writingDirection?: 'auto' | 'ltr' | 'rtl',
cursor?: CursorValue,
|}>;

export type ____ImageStyle_Internal = $ReadOnly<{|
Expand Down
10 changes: 5 additions & 5 deletions Libraries/Text/RCTTextAttributes.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,27 @@ - (NSParagraphStyle *)effectiveParagraphStyle
alignment = NSTextAlignmentRight;
}
}

paragraphStyle.alignment = alignment;
isParagraphStyleUsed = YES;
}

if (_baseWritingDirection != NSWritingDirectionNatural) {
paragraphStyle.baseWritingDirection = _baseWritingDirection;
isParagraphStyleUsed = YES;
}

if (!isnan(_lineHeight)) {
CGFloat lineHeight = _lineHeight * self.effectiveFontSizeMultiplier;
paragraphStyle.minimumLineHeight = lineHeight;
paragraphStyle.maximumLineHeight = lineHeight;
isParagraphStyleUsed = YES;
}

if (isParagraphStyleUsed) {
return [paragraphStyle copy];
}

return nil;
}

Expand Down
7 changes: 7 additions & 0 deletions React/Base/macOS/RCTUIKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@ - (void)setBackgroundColor:(NSColor *)backgroundColor
}
}

// We purposely don't use RCTCursor for the parameter type here because it would introduce an import cycle:
// RCTUIKit > RCTCursor > RCTConvert > RCTUIKit
- (void)setCursor:(NSInteger)cursor
{
// This method is required to be defined due to [RCTVirtualTextViewManager view] returning a RCTUIView.
}

@end

// RCTUIScrollView
Expand Down
8 changes: 8 additions & 0 deletions React/Views/RCTCursor.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTConvert.h>

typedef NS_ENUM(NSInteger, RCTCursor) {
Expand Down Expand Up @@ -25,5 +32,6 @@ typedef NS_ENUM(NSInteger, RCTCursor) {
@interface RCTConvert (RCTCursor)

+ (RCTCursor)RCTCursor:(id)json;
+ (NSCursor *)NSCursor:(RCTCursor)rctCursor;

@end
71 changes: 71 additions & 0 deletions React/Views/RCTCursor.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTCursor.h>

@implementation RCTConvert (RCTCursor)
Expand Down Expand Up @@ -29,4 +36,68 @@ @implementation RCTConvert (RCTCursor)
RCTCursorAuto,
integerValue)

+ (NSCursor *)NSCursor:(RCTCursor)rctCursor
{
NSCursor *cursor;

switch (rctCursor) {
case RCTCursorArrow:
cursor = [NSCursor arrowCursor];
break;
case RCTCursorClosedHand:
cursor = [NSCursor closedHandCursor];
break;
case RCTCursorContextualMenu:
cursor = [NSCursor contextualMenuCursor];
break;
case RCTCursorCrosshair:
cursor = [NSCursor crosshairCursor];
break;
case RCTCursorDisappearingItem:
cursor = [NSCursor disappearingItemCursor];
break;
case RCTCursorDragCopy:
cursor = [NSCursor dragCopyCursor];
break;
case RCTCursorDragLink:
cursor = [NSCursor dragLinkCursor];
break;
case RCTCursorIBeam:
cursor = [NSCursor IBeamCursor];
break;
case RCTCursorIBeamCursorForVerticalLayout:
cursor = [NSCursor IBeamCursorForVerticalLayout];
break;
case RCTCursorOpenHand:
cursor = [NSCursor openHandCursor];
break;
case RCTCursorOperationNotAllowed:
cursor = [NSCursor operationNotAllowedCursor];
break;
case RCTCursorPointingHand:
cursor = [NSCursor pointingHandCursor];
break;
case RCTCursorResizeDown:
cursor = [NSCursor resizeDownCursor];
break;
case RCTCursorResizeLeft:
cursor = [NSCursor resizeLeftCursor];
break;
case RCTCursorResizeLeftRight:
cursor = [NSCursor resizeLeftRightCursor];
break;
case RCTCursorResizeRight:
cursor = [NSCursor resizeRightCursor];
break;
case RCTCursorResizeUp:
cursor = [NSCursor resizeUpCursor];
break;
case RCTCursorResizeUpDown:
cursor = [NSCursor resizeUpDownCursor];
break;
}

return cursor;
}

@end
5 changes: 5 additions & 0 deletions React/Views/RCTView.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#import <React/RCTEventDispatcherProtocol.h> // TODO(OSS Candidate ISS#2710739)
#import <React/RCTPointerEvents.h>

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

#if !TARGET_OS_OSX // TODO(macOS GH#774)
extern const UIAccessibilityTraits SwitchAccessibilityTrait;
#endif // TODO(macOS GH#774)
Expand Down Expand Up @@ -119,6 +123,7 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
/**
* macOS Properties
*/
@property (nonatomic, assign) RCTCursor cursor;

@property (nonatomic, assign) CATransform3D transform3D;

Expand Down
Loading

0 comments on commit 6d81baf

Please sign in to comment.