Skip to content

Commit

Permalink
Fix spellCheck and autoCorrect props (microsoft#1292)
Browse files Browse the repository at this point in the history
Summary: This fixes `autoCorrect` to correctly map to `automaticSpellingCorrectionEnabled`, and `spellCheck` to map to `continuousSpellCheckingEnabled`.

Note: automaticTextReplacementEnabled is a different feature than automaticSpellingCorrectionEnabled
https://developer.apple.com/documentation/appkit/nstextview/1449210-automatictextreplacementenabled
https://developer.apple.com/documentation/appkit/nstextview/1449254-isautomaticspellingcorrectionena

Co-authored-by: Scott Kyle <skyle@fb.com>
# Conflicts:
#	Libraries/Text/TextInput/Singleline/RCTUITextField.h
#	Libraries/Text/TextInput/Singleline/RCTUITextField.m
  • Loading branch information
lyahdav authored and christophpurrer committed Aug 9, 2022
1 parent a4882c2 commit c30fc6b
Show file tree
Hide file tree
Showing 21 changed files with 345 additions and 21 deletions.
1 change: 1 addition & 0 deletions Libraries/Components/Touchable/TouchableBounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class TouchableBounce extends React.Component<Props, State> {
!this.props.disabled
}
focusable={this.props.focusable !== false && !this.props.disabled}
cursor={this.props.cursor}
tooltip={this.props.tooltip}
onMouseEnter={this.props.onMouseEnter}
onMouseLeave={this.props.onMouseLeave}
Expand Down
1 change: 1 addition & 0 deletions Libraries/Components/Touchable/TouchableHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class TouchableHighlight extends React.Component<Props, State> {
}
focusable={this.props.focusable !== false && !this.props.disabled}
tooltip={this.props.tooltip}
cursor={this.props.cursor}
onMouseEnter={this.props.onMouseEnter}
onMouseLeave={this.props.onMouseLeave}
onDragEnter={this.props.onDragEnter}
Expand Down
1 change: 1 addition & 0 deletions Libraries/Components/Touchable/TouchableOpacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class TouchableOpacity extends React.Component<Props, State> {
}
focusable={this.props.focusable !== false && !this.props.disabled}
tooltip={this.props.tooltip}
cursor={this.props.cursor}
onMouseEnter={this.props.onMouseEnter}
onMouseLeave={this.props.onMouseLeave}
onDragEnter={this.props.onDragEnter}
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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 @@ -48,6 +49,7 @@ 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ReactNativeViewViewConfigMacOS = {
validAttributes: {
acceptsFirstMouse: true,
accessibilityTraits: true,
cursor: true,
draggedTypes: true,
enableFocusRing: true,
onBlur: 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)

/*
* 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
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 ISS#2323203)
#import <React/RCTCursor.h>
#endif // TODO(macOS ISS#2323203)

@implementation RCTBaseTextViewManager

Expand Down Expand Up @@ -55,4 +58,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 ISS#2323203)
RCT_REMAP_SHADOW_PROPERTY(cursor, textAttributes.cursor, RCTCursor)
#endif // TODO(macOS ISS#2323203)

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

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

#import <React/RCTTextDecorationLineType.h>
#import <React/RCTFontSmoothing.h> // TODO(OSS Candidate ISS#2710739)
Expand Down Expand Up @@ -59,6 +62,10 @@ extern NSString *const RCTTextAttributesTagAttributeName;
@property (nonatomic, assign) UIUserInterfaceLayoutDirection layoutDirection;
@property (nonatomic, assign) RCTTextTransform textTransform;

#if TARGET_OS_OSX // TODO(macOS ISS#2323203)
@property (nonatomic, assign) RCTCursor cursor;
#endif // TODO(macOS ISS#2323203)

#pragma mark - Inheritance

- (void)applyTextAttributes:(RCTTextAttributes *)textAttributes;
Expand Down
26 changes: 21 additions & 5 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 ISS#2323203)
#import <React/RCTCursor.h>
#endif // TODO(macOS ISS#2323203)

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 ISS#2323203)
_cursor = RCTCursorAuto;
#endif // TODO(macOS ISS#2323203)
}

return self;
Expand Down Expand Up @@ -93,6 +100,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 ISS#2323203)
_cursor = textAttributes->_cursor != RCTCursorAuto ? textAttributes->_cursor : _cursor;
#endif // TODO(macOS ISS#2323203)
}

- (NSParagraphStyle *)effectiveParagraphStyle
Expand All @@ -109,27 +120,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 Expand Up @@ -209,6 +220,11 @@ - (NSParagraphStyle *)effectiveParagraphStyle
attributes[RCTTextAttributesTagAttributeName] = _tag;
}

#if TARGET_OS_OSX // TODO(macOS ISS#2323203)
if (_cursor != RCTCursorAuto) {
attributes[NSCursorAttributeName] = [RCTConvert NSCursor:_cursor];
}
#endif // TODO(macOS ISS#2323203)
return [attributes copy];
}

Expand Down
5 changes: 5 additions & 0 deletions Libraries/Text/Text/RCTTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ - (instancetype)initWithFrame:(CGRect)frame
}

#if TARGET_OS_OSX // [TODO(macOS GH#774)
- (void)setCursor:(RCTCursor)cursor
{
// This is required because the RCTTextViewManager inherits from RCTViewManager which has a cursor prop.
}

- (NSView *)hitTest:(NSPoint)point
{
// We will forward mouse events to the NSTextView ourselves.
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
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
Loading

0 comments on commit c30fc6b

Please sign in to comment.