Skip to content

Commit

Permalink
[fabric] Revert to Core Cursor implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
shwanton committed May 1, 2024
1 parent b1010d3 commit e722e95
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,71 +32,6 @@

using namespace facebook::react;

#if TARGET_OS_OSX // [macOS
inline NSCursor* RCTNSCursorFromCursor(facebook::react::Cursor cursorValue) {
NSCursor *cursor = nil;

switch (cursorValue) {
case Cursor::Arrow:
cursor = [NSCursor arrowCursor];
break;
case Cursor::ClosedHand:
cursor = [NSCursor closedHandCursor];
break;
case Cursor::ContextualMenu:
cursor = [NSCursor contextualMenuCursor];
break;
case Cursor::Crosshair:
cursor = [NSCursor crosshairCursor];
break;
case Cursor::DisappearingItem:
cursor = [NSCursor disappearingItemCursor];
break;
case Cursor::DragCopy:
cursor = [NSCursor dragCopyCursor];
break;
case Cursor::DragLink:
cursor = [NSCursor dragLinkCursor];
break;
case Cursor::IBeam:
cursor = [NSCursor IBeamCursor];
break;
case Cursor::IBeamCursorForVerticalLayout:
cursor = [NSCursor IBeamCursorForVerticalLayout];
break;
case Cursor::OpenHand:
cursor = [NSCursor openHandCursor];
break;
case Cursor::OperationNotAllowed:
cursor = [NSCursor operationNotAllowedCursor];
break;
case Cursor::PointingHand:
cursor = [NSCursor pointingHandCursor];
break;
case Cursor::ResizeDown:
cursor = [NSCursor resizeDownCursor];
break;
case Cursor::ResizeLeft:
cursor = [NSCursor resizeLeftCursor];
break;
case Cursor::ResizeLeftRight:
cursor = [NSCursor resizeLeftRightCursor];
break;
case Cursor::ResizeRight:
cursor = [NSCursor resizeRightCursor];
break;
case Cursor::ResizeUp:
cursor = [NSCursor resizeUpCursor];
break;
case Cursor::ResizeUpDown:
cursor = [NSCursor resizeUpDownCursor];
break;
}

return cursor;
}
#endif // macOS]

@implementation RCTViewComponentView {
RCTUIColor *_backgroundColor; // [macOS]
CALayer *_borderLayer;
Expand Down Expand Up @@ -176,18 +111,6 @@ - (void)setBackgroundColor:(RCTUIColor *)backgroundColor // [macOS]
_backgroundColor = backgroundColor;
}

#if TARGET_OS_OSX // [macOS
- (void)resetCursorRects
{
[self discardCursorRects];
if (_props->cursor != Cursor::Auto)
{
NSCursor *cursor = NSCursorFromCursor(_props->cursor);
[self addCursorRect:self.bounds cursor:cursor];
}
}
#endif // macOS]

#pragma mark - RCTComponentViewProtocol

+ (ComponentDescriptorProvider)componentDescriptorProvider
Expand Down Expand Up @@ -347,7 +270,11 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &

// `cursor`
if (oldViewProps.cursor != newViewProps.cursor) {
needsInvalidateLayer = YES;
#if !TARGET_OS_OSX // [macOS]
needsInvalidateLayer = YES; // `cursor`
#else // [macOS
_cursor = NSCursorFromCursor(newViewProps.cursor);
#endif // macOS]
}

// `shouldRasterize`
Expand Down Expand Up @@ -544,13 +471,6 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
}
}

// `cursor`
if (oldViewProps.cursor != newViewProps.cursor) {
_cursor = nil;
if (newViewProps.cursor.has_value()) {
_cursor = RCTNSCursorFromCursor(newViewProps.cursor.value());
}
}
#endif // macOS]

_needsInvalidateLayer = _needsInvalidateLayer || needsInvalidateLayer;
Expand Down Expand Up @@ -753,13 +673,17 @@ static RCTBorderStyle RCTBorderStyleFromBorderStyle(BorderStyle borderStyle)
}

#if TARGET_OS_OSX // [macOS
static NSCursor *NSCursorFromCursor(Cursor cursor)
static NSCursor *NSCursorFromCursor(Cursor cursor)
{
switch (cursor) {
case Cursor::Auto:
return [NSCursor arrowCursor];
case Cursor::Alias:
return [NSCursor dragLinkCursor];
case Cursor::Arrow:
return [NSCursor arrowCursor];
case Cursor::Auto:
return [NSCursor arrowCursor];
case Cursor::ClosedHand:
return [NSCursor closedHandCursor];
case Cursor::ColumnResize:
return [NSCursor resizeLeftRightCursor];
case Cursor::ContextualMenu:
Expand All @@ -772,20 +696,34 @@ static RCTBorderStyle RCTBorderStyleFromBorderStyle(BorderStyle borderStyle)
return [NSCursor arrowCursor];
case Cursor::DisappearingItem:
return [NSCursor disappearingItemCursor];
case Cursor::DragCopy:
return [NSCursor dragCopyCursor];
case Cursor::DragLink:
return [NSCursor dragLinkCursor];
case Cursor::EastResize:
return [NSCursor resizeRightCursor];
case Cursor::Grab:
return [NSCursor openHandCursor];
case Cursor::Grabbing:
return [NSCursor closedHandCursor];
case Cursor::IBeam:
return [NSCursor IBeamCursor];
case Cursor::IBeamCursorForVerticalLayout:
return [NSCursor IBeamCursorForVerticalLayout];
case Cursor::NorthResize:
return [NSCursor resizeUpCursor];
case Cursor::NoDrop:
return [NSCursor operationNotAllowedCursor];
case Cursor::NotAllowed:
return [NSCursor operationNotAllowedCursor];
case Cursor::OpenHand:
return [NSCursor openHandCursor];
case Cursor::OperationNotAllowed:
return [NSCursor operationNotAllowedCursor];
case Cursor::Pointer:
return [NSCursor pointingHandCursor];
case Cursor::PointingHand:
return [NSCursor pointingHandCursor];
case Cursor::RowResize:
return [NSCursor resizeUpDownCursor];
case Cursor::SouthResize:
Expand All @@ -796,11 +734,22 @@ static RCTBorderStyle RCTBorderStyleFromBorderStyle(BorderStyle borderStyle)
return [NSCursor IBeamCursorForVerticalLayout];
case Cursor::WestResize:
return [NSCursor resizeLeftCursor];
case Cursor::ResizeDown:
return [NSCursor resizeDownCursor];
case Cursor::ResizeLeft:
return [NSCursor resizeLeftCursor];
case Cursor::ResizeLeftRight:
return [NSCursor resizeLeftRightCursor];
case Cursor::ResizeRight:
return [NSCursor resizeRightCursor];
case Cursor::ResizeUp:
return [NSCursor resizeUpCursor];
case Cursor::ResizeUpDown:
return [NSCursor resizeDownCursor];
}
}
#endif // macOS]


- (void)invalidateLayer
{
CALayer *layer = self.layer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,37 @@ enum class BorderCurve : uint8_t { Circular, Continuous };
enum class BorderStyle : uint8_t { Solid, Dotted, Dashed };

// [macOS [visionOS]
enum class Cursor : uint8_t {
Auto,
enum class Cursor : uint8_t {
Alias,
Arrow,
Auto,
ClosedHand,
ColumnResize,
ContextualMenu,
Copy,
Crosshair,
Default,
DisappearingItem,
DragCopy,
DragLink,
EastResize,
Grab,
Grabbing,
NorthResize,
IBeam,
IBeamCursorForVerticalLayout,
NoDrop,
NorthResize,
NotAllowed,
OpenHand,
OperationNotAllowed,
Pointer,
PointingHand,
ResizeDown,
ResizeLeft,
ResizeLeftRight,
ResizeRight,
ResizeUp,
ResizeUpDown,
RowResize,
SouthResize,
Text,
Expand Down

0 comments on commit e722e95

Please sign in to comment.