Skip to content
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

Add cursor prop to View and Touchables #760

Merged
merged 19 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from 17 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
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
1 change: 1 addition & 0 deletions Libraries/Components/View/ReactNativeViewViewConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ const ReactNativeViewConfig: ViewConfig = {
borderWidth: true,
bottom: true,
color: {process: require('../../StyleSheet/processColor')},
cursor: true,
decomposedMatrix: true,
direction: true,
display: true,
Expand Down
7 changes: 4 additions & 3 deletions Libraries/Components/View/ReactNativeViewViewConfigMacOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ const ReactNativeViewViewConfigMacOS = {
validAttributes: {
acceptsFirstMouse: true,
accessibilityTraits: true,
cursor: true,
draggedTypes: true,
enableFocusRing: true,
nextKeyViewTag: true,
onBlur: true,
onClick: true,
onDoubleClick: true,
Expand All @@ -48,12 +50,11 @@ const ReactNativeViewViewConfigMacOS = {
onFocus: true,
onKeyDown: true,
onKeyUp: true,
validKeysDown: true,
validKeysUp: true,
nextKeyViewTag: true,
onMouseEnter: true,
onMouseLeave: true,
tooltip: true,
ryanlntn marked this conversation as resolved.
Show resolved Hide resolved
validKeysDown: true,
ryanlntn marked this conversation as resolved.
Show resolved Hide resolved
validKeysUp: true,
},
};

Expand Down
6 changes: 6 additions & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType';
import type {Node} from 'react';
import type {ViewStyleProp} from '../../StyleSheet/StyleSheet';
import type {CursorValue} from '../../StyleSheet/StyleSheetTypes';
import type {
AccessibilityRole,
AccessibilityState,
Expand Down Expand Up @@ -633,4 +634,9 @@ export type ViewProps = $ReadOnly<{|
* @platform macos
*/
draggedTypes?: ?DraggedTypesType, // TODO(macOS GH#774)
ryanlntn marked this conversation as resolved.
Show resolved Hide resolved
ryanlntn marked this conversation as resolved.
Show resolved Hide resolved

/*
* Sets the type of mouse cursor, to show when the mouse pointer is over the view.
*/
cursor?: ?CursorValue, // TODO(macOS GH#774)
|}>;
25 changes: 25 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 @@ -584,6 +607,7 @@ export type ____ViewStyle_Internal = $ReadOnly<{|
borderTopWidth?: number | AnimatedNode,
opacity?: number | AnimatedNode,
elevation?: number,
cursor?: CursorValue,
|}>;

export type ____FontWeight_Internal =
Expand Down Expand Up @@ -638,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.
}

Saadnajmi marked this conversation as resolved.
Show resolved Hide resolved
@end

// RCTUIScrollView
Expand Down
37 changes: 37 additions & 0 deletions React/Views/RCTCursor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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) {
RCTCursorAuto,
RCTCursorArrow,
RCTCursorIBeam,
RCTCursorCrosshair,
RCTCursorClosedHand,
RCTCursorOpenHand,
RCTCursorPointingHand,
RCTCursorResizeLeft,
RCTCursorResizeRight,
RCTCursorResizeLeftRight,
RCTCursorResizeUp,
RCTCursorResizeDown,
RCTCursorResizeUpDown,
RCTCursorDisappearingItem,
RCTCursorIBeamCursorForVerticalLayout,
RCTCursorOperationNotAllowed,
RCTCursorDragLink,
RCTCursorDragCopy,
RCTCursorContextualMenu,
};

@interface RCTConvert (RCTCursor)

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

@end
103 changes: 103 additions & 0 deletions React/Views/RCTCursor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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)

RCT_ENUM_CONVERTER(
RCTCursor,
(@{
@"alias" : @(RCTCursorDragLink),
@"auto" : @(RCTCursorAuto),
@"col-resize" : @(RCTCursorResizeLeftRight),
@"context-menu" : @(RCTCursorContextualMenu),
@"copy" : @(RCTCursorDragCopy),
@"crosshair" : @(RCTCursorCrosshair),
@"default" : @(RCTCursorArrow),
@"disappearing-item" : @(RCTCursorDisappearingItem),
@"e-resize" : @(RCTCursorResizeRight),
@"grab" : @(RCTCursorOpenHand),
@"grabbing" : @(RCTCursorClosedHand),
@"n-resize" : @(RCTCursorResizeUp),
@"no-drop" : @(RCTCursorOperationNotAllowed),
@"not-allowed" : @(RCTCursorOperationNotAllowed),
@"pointer" : @(RCTCursorPointingHand),
@"row-resize" : @(RCTCursorResizeUpDown),
@"s-resize" : @(RCTCursorResizeDown),
@"text" : @(RCTCursorIBeam),
@"vertical-text" : @(RCTCursorIBeamCursorForVerticalLayout),
@"w-resize" : @(RCTCursorResizeLeft),
}),
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