Skip to content

Commit 0ef7992

Browse files
authored
Merge pull request microsoft#760 from ryanlntn/feat/cursor
Add cursor prop to View and Touchables
2 parents 9f23049 + e6a4b5d commit 0ef7992

File tree

14 files changed

+324
-67
lines changed

14 files changed

+324
-67
lines changed

Libraries/Components/View/ReactNativeStyleAttributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const ReactNativeStyleAttributes: {[string]: AnyAttributeType, ...} = {
116116
borderTopLeftRadius: true,
117117
borderTopRightRadius: true,
118118
borderTopStartRadius: true,
119+
cursor: true,
119120
opacity: true,
120121

121122
/**

Libraries/Components/View/ReactNativeViewViewConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ const ReactNativeViewConfig: ViewConfig = {
273273
borderWidth: true,
274274
bottom: true,
275275
color: {process: require('../../StyleSheet/processColor')},
276+
cursor: true,
276277
decomposedMatrix: true,
277278
direction: true,
278279
display: true,

Libraries/Components/View/ReactNativeViewViewConfigMacOS.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const ReactNativeViewViewConfigMacOS = {
3939
accessibilityTraits: true,
4040
draggedTypes: true,
4141
enableFocusRing: true,
42+
nextKeyViewTag: true,
4243
onBlur: true,
4344
onClick: true,
4445
onDoubleClick: true,
@@ -48,12 +49,11 @@ const ReactNativeViewViewConfigMacOS = {
4849
onFocus: true,
4950
onKeyDown: true,
5051
onKeyUp: true,
51-
validKeysDown: true,
52-
validKeysUp: true,
53-
nextKeyViewTag: true,
5452
onMouseEnter: true,
5553
onMouseLeave: true,
5654
tooltip: true,
55+
validKeysDown: true,
56+
validKeysUp: true,
5757
},
5858
};
5959

Libraries/StyleSheet/StyleSheetTypes.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ import type {NativeColorValue} from './PlatformColorValueTypes';
1616

1717
export type ____ColorValue_Internal = null | string | NativeColorValue;
1818

19+
export type CursorValue = ?(
20+
| 'alias'
21+
| 'auto'
22+
| 'col-resize'
23+
| 'context-menu'
24+
| 'copy'
25+
| 'crosshair'
26+
| 'default'
27+
| 'disappearing-item'
28+
| 'e-resize'
29+
| 'grab'
30+
| 'grabbing'
31+
| 'n-resize'
32+
| 'no-drop'
33+
| 'not-allowed'
34+
| 'pointer'
35+
| 'row-resize'
36+
| 's-resize'
37+
| 'text'
38+
| 'vertical-text'
39+
| 'w-resize'
40+
);
41+
1942
export type ColorArrayValue = null | $ReadOnlyArray<____ColorValue_Internal>;
2043
export type PointValue = {|
2144
x: number,
@@ -584,6 +607,7 @@ export type ____ViewStyle_Internal = $ReadOnly<{|
584607
borderTopWidth?: number | AnimatedNode,
585608
opacity?: number | AnimatedNode,
586609
elevation?: number,
610+
cursor?: CursorValue,
587611
|}>;
588612

589613
export type ____FontWeight_Internal =
@@ -638,6 +662,7 @@ export type ____TextStyle_Internal = $ReadOnly<{|
638662
textDecorationColor?: ____ColorValue_Internal,
639663
textTransform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase',
640664
writingDirection?: 'auto' | 'ltr' | 'rtl',
665+
cursor?: CursorValue,
641666
|}>;
642667

643668
export type ____ImageStyle_Internal = $ReadOnly<{|

Libraries/Text/RCTTextAttributes.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,27 @@ - (NSParagraphStyle *)effectiveParagraphStyle
109109
alignment = NSTextAlignmentRight;
110110
}
111111
}
112-
112+
113113
paragraphStyle.alignment = alignment;
114114
isParagraphStyleUsed = YES;
115115
}
116-
116+
117117
if (_baseWritingDirection != NSWritingDirectionNatural) {
118118
paragraphStyle.baseWritingDirection = _baseWritingDirection;
119119
isParagraphStyleUsed = YES;
120120
}
121-
121+
122122
if (!isnan(_lineHeight)) {
123123
CGFloat lineHeight = _lineHeight * self.effectiveFontSizeMultiplier;
124124
paragraphStyle.minimumLineHeight = lineHeight;
125125
paragraphStyle.maximumLineHeight = lineHeight;
126126
isParagraphStyleUsed = YES;
127127
}
128-
128+
129129
if (isParagraphStyleUsed) {
130130
return [paragraphStyle copy];
131131
}
132-
132+
133133
return nil;
134134
}
135135

React/Base/macOS/RCTUIKit.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@ - (void)setBackgroundColor:(NSColor *)backgroundColor
423423
}
424424
}
425425

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

428435
// RCTUIScrollView

React/Views/RCTCursor.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <React/RCTConvert.h>
9+
10+
typedef NS_ENUM(NSInteger, RCTCursor) {
11+
RCTCursorAuto,
12+
RCTCursorArrow,
13+
RCTCursorIBeam,
14+
RCTCursorCrosshair,
15+
RCTCursorClosedHand,
16+
RCTCursorOpenHand,
17+
RCTCursorPointingHand,
18+
RCTCursorResizeLeft,
19+
RCTCursorResizeRight,
20+
RCTCursorResizeLeftRight,
21+
RCTCursorResizeUp,
22+
RCTCursorResizeDown,
23+
RCTCursorResizeUpDown,
24+
RCTCursorDisappearingItem,
25+
RCTCursorIBeamCursorForVerticalLayout,
26+
RCTCursorOperationNotAllowed,
27+
RCTCursorDragLink,
28+
RCTCursorDragCopy,
29+
RCTCursorContextualMenu,
30+
};
31+
32+
@interface RCTConvert (RCTCursor)
33+
34+
+ (RCTCursor)RCTCursor:(id)json;
35+
#if TARGET_OS_OSX // TODO(macOS GH#774)
36+
+ (NSCursor *)NSCursor:(RCTCursor)rctCursor;
37+
#endif // ]TODO(macOS GH#774)
38+
39+
@end

React/Views/RCTCursor.m

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <React/RCTCursor.h>
9+
10+
@implementation RCTConvert (RCTCursor)
11+
12+
RCT_ENUM_CONVERTER(
13+
RCTCursor,
14+
(@{
15+
@"alias" : @(RCTCursorDragLink),
16+
@"auto" : @(RCTCursorAuto),
17+
@"col-resize" : @(RCTCursorResizeLeftRight),
18+
@"context-menu" : @(RCTCursorContextualMenu),
19+
@"copy" : @(RCTCursorDragCopy),
20+
@"crosshair" : @(RCTCursorCrosshair),
21+
@"default" : @(RCTCursorArrow),
22+
@"disappearing-item" : @(RCTCursorDisappearingItem),
23+
@"e-resize" : @(RCTCursorResizeRight),
24+
@"grab" : @(RCTCursorOpenHand),
25+
@"grabbing" : @(RCTCursorClosedHand),
26+
@"n-resize" : @(RCTCursorResizeUp),
27+
@"no-drop" : @(RCTCursorOperationNotAllowed),
28+
@"not-allowed" : @(RCTCursorOperationNotAllowed),
29+
@"pointer" : @(RCTCursorPointingHand),
30+
@"row-resize" : @(RCTCursorResizeUpDown),
31+
@"s-resize" : @(RCTCursorResizeDown),
32+
@"text" : @(RCTCursorIBeam),
33+
@"vertical-text" : @(RCTCursorIBeamCursorForVerticalLayout),
34+
@"w-resize" : @(RCTCursorResizeLeft),
35+
}),
36+
RCTCursorAuto,
37+
integerValue)
38+
39+
#if TARGET_OS_OSX // TODO(macOS GH#774)
40+
+ (NSCursor *)NSCursor:(RCTCursor)rctCursor
41+
{
42+
NSCursor *cursor;
43+
44+
switch (rctCursor) {
45+
case RCTCursorArrow:
46+
cursor = [NSCursor arrowCursor];
47+
break;
48+
case RCTCursorClosedHand:
49+
cursor = [NSCursor closedHandCursor];
50+
break;
51+
case RCTCursorContextualMenu:
52+
cursor = [NSCursor contextualMenuCursor];
53+
break;
54+
case RCTCursorCrosshair:
55+
cursor = [NSCursor crosshairCursor];
56+
break;
57+
case RCTCursorDisappearingItem:
58+
cursor = [NSCursor disappearingItemCursor];
59+
break;
60+
case RCTCursorDragCopy:
61+
cursor = [NSCursor dragCopyCursor];
62+
break;
63+
case RCTCursorDragLink:
64+
cursor = [NSCursor dragLinkCursor];
65+
break;
66+
case RCTCursorIBeam:
67+
cursor = [NSCursor IBeamCursor];
68+
break;
69+
case RCTCursorIBeamCursorForVerticalLayout:
70+
cursor = [NSCursor IBeamCursorForVerticalLayout];
71+
break;
72+
case RCTCursorOpenHand:
73+
cursor = [NSCursor openHandCursor];
74+
break;
75+
case RCTCursorOperationNotAllowed:
76+
cursor = [NSCursor operationNotAllowedCursor];
77+
break;
78+
case RCTCursorPointingHand:
79+
cursor = [NSCursor pointingHandCursor];
80+
break;
81+
case RCTCursorResizeDown:
82+
cursor = [NSCursor resizeDownCursor];
83+
break;
84+
case RCTCursorResizeLeft:
85+
cursor = [NSCursor resizeLeftCursor];
86+
break;
87+
case RCTCursorResizeLeftRight:
88+
cursor = [NSCursor resizeLeftRightCursor];
89+
break;
90+
case RCTCursorResizeRight:
91+
cursor = [NSCursor resizeRightCursor];
92+
break;
93+
case RCTCursorResizeUp:
94+
cursor = [NSCursor resizeUpCursor];
95+
break;
96+
case RCTCursorResizeUpDown:
97+
cursor = [NSCursor resizeUpDownCursor];
98+
break;
99+
}
100+
101+
return cursor;
102+
}
103+
#endif // ]TODO(macOS GH#774)
104+
105+
@end

React/Views/RCTView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#import <React/RCTEventDispatcherProtocol.h> // TODO(OSS Candidate ISS#2710739)
1313
#import <React/RCTPointerEvents.h>
1414

15+
#if TARGET_OS_OSX // TODO(macOS GH#774)
16+
#import <React/RCTCursor.h>
17+
#endif // TODO(macOS GH#774)
18+
1519
#if !TARGET_OS_OSX // TODO(macOS GH#774)
1620
extern const UIAccessibilityTraits SwitchAccessibilityTrait;
1721
#endif // TODO(macOS GH#774)
@@ -123,6 +127,7 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
123127
/**
124128
* macOS Properties
125129
*/
130+
@property (nonatomic, assign) RCTCursor cursor;
126131

127132
@property (nonatomic, assign) CATransform3D transform3D;
128133

0 commit comments

Comments
 (0)