Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ export type TextInputEditingEvent =

// [macOS macOS-only
export type SettingChangeEvent = NativeSyntheticEvent<
$ReadOnly<{|
autoCorrectEnabled: boolean,
spellCheckEnabled: boolean,
grammarCheckEnabled: boolean,
|}>,
$ReadOnly<{
enabled: boolean,
}>,
>;

export type PasteEvent = NativeSyntheticEvent<
Expand All @@ -150,14 +148,14 @@ export type PasteEvent = NativeSyntheticEvent<
|}>,
>;

export type SubmitKeyEvent = $ReadOnly<{|
export type SubmitKeyEvent = $ReadOnly<{
key: string,
altKey?: ?boolean,
ctrlKey?: ?boolean,
metaKey?: ?boolean,
shiftKey?: ?boolean,
functionKey?: ?boolean,
|}>;
}>;
// macOS]

// [macOS
Expand Down Expand Up @@ -443,7 +441,7 @@ export type TextInputIOSProps = $ReadOnly<{
}>;

// [macOS
type MacOSProps = $ReadOnly<{|
export type TextInputMacOSProps = $ReadOnly<{
/**
* If `true`, clears the text field synchronously before `onSubmitEditing` is emitted.
*
Expand Down Expand Up @@ -528,7 +526,7 @@ type MacOSProps = $ReadOnly<{|
* @platform macos
*/
tooltip?: ?string,
|}>;
}>;
// macOS]

export type TextInputAndroidProps = $ReadOnly<{
Expand Down Expand Up @@ -624,7 +622,7 @@ export type PastedTypesType = PasteType | $ReadOnlyArray<PasteType>; // [macOS]
export type TextInputProps = $ReadOnly<{
...$Diff<ViewProps, $ReadOnly<{style: ?ViewStyleProp}>>,
...TextInputIOSProps,
...MacOSProps, // [macOS]
...TextInputMacOSProps, // [macOS]
...TextInputAndroidProps,

/**
Expand Down Expand Up @@ -2043,6 +2041,7 @@ const autoCompleteWebToTextContentTypeMap = {
const ExportedForwardRef: component(
ref: React.RefSetter<TextInputInstance>,
...props: React.ElementConfig<typeof InternalTextInput>
// $FlowFixMe[incompatible-call]
) = React.forwardRef(function TextInput(
{
allowFontScaling = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
Expand Down
11 changes: 10 additions & 1 deletion packages/react-native/Libraries/Image/RCTImageLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -629,14 +629,23 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
[self setUp];
}

#if TARGET_OS_OSX // [macOS
BOOL useDefaultLoading = [loadHandler respondsToSelector:@selector(defaultLoadingURL:)];
if (useDefaultLoading) {
NSMutableURLRequest *updatedRequest = [request mutableCopy];
updatedRequest.URL = [loadHandler defaultLoadingURL:request.URL];
request = updatedRequest;
}
#endif // macOS]

__weak RCTImageLoader *weakSelf = self;
dispatch_async(_URLRequestQueue, ^{
__typeof(self) strongSelf = weakSelf;
if (atomic_load(cancelled.get()) || !strongSelf) {
return;
}

if (loadHandler) {
if (loadHandler && !useDefaultLoading) { // [macOS]
dispatch_block_t cancelLoadLocal;
if ([loadHandler conformsToProtocol:@protocol(RCTImageURLLoaderWithAttribution)]) {
RCTImageURLLoaderRequest *loaderRequest = [(id<RCTImageURLLoaderWithAttribution>)loadHandler
Expand Down
8 changes: 8 additions & 0 deletions packages/react-native/Libraries/Image/RCTImageURLLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;
*/
- (BOOL)shouldCacheLoadedImages;

#if TARGET_OS_OSX // [macOS
/**
* If defined, the image loading of the RCTImageLoader will be used to load the image using
* the returned URL. This allows rewriting the URL before the image loader starts the request.
*/
- (NSURL *)defaultLoadingURL:(NSURL *)requestURL;
#endif // macOS]

@end

NS_ASSUME_NONNULL_END
25 changes: 6 additions & 19 deletions packages/react-native/Libraries/Image/RCTImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_bridge = bridge;
#if TARGET_OS_OSX // [macOS
self.wantsLayer = YES;
_resizeMode = RCTResizeModeCover;
_imageView.contentMode = (UIViewContentMode)RCTResizeModeCover;
[_imageView unregisterDraggedTypes];
#endif // macOS]
_imageView = [RCTUIImageViewAnimated new];
_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Expand Down Expand Up @@ -195,10 +198,6 @@ - (void)updateWithImage:(UIImage *)image
#else // [macOS
image.capInsets = _capInsets;
image.resizingMode = NSImageResizingModeTile;
} else if (_resizeMode == RCTResizeModeCover) {
if (!NSEqualSizes(self.bounds.size, NSZeroSize)) {
image = RCTFillImagePreservingAspectRatio(image, self.bounds.size, self.window.backingScaleFactor ?: 1.0);
}
#endif // macOS]
} else if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, _capInsets)) {
// Applying capInsets of 0 will switch the "resizingMode" of the image to "tile" which is undesired
Expand Down Expand Up @@ -284,21 +283,9 @@ - (void)setResizeMode:(RCTResizeMode)resizeMode
if (_resizeMode == RCTResizeModeRepeat) {
// Repeat resize mode is handled by the UIImage. Use scale to fill
// so the repeated image fills the UIImageView.
#if !TARGET_OS_OSX // [macOS]
_imageView.contentMode = UIViewContentModeScaleToFill;
#else // [macOS
_imageView.imageScaling = NSImageScaleAxesIndependently;
#endif // macOS]
} else {
#if !TARGET_OS_OSX // [macOS]
_imageView.contentMode = (UIViewContentMode)resizeMode;
#else // [macOS
// This relies on having previously resampled the image to a size that exceeds the image view.
if (resizeMode == RCTResizeModeCover) {
resizeMode = RCTResizeModeCenter;
}
_imageView.imageScaling = (NSImageScaling)resizeMode;
#endif // macOS]
}

if ([self shouldReloadImageSourceAfterResize]) {
Expand Down Expand Up @@ -566,7 +553,7 @@ - (void)reactSetFrame:(CGRect)frame
!RCTShouldReloadImageForSizeChange(_targetSize, idealSize)) // [macOS
#if TARGET_OS_OSX
// Since macOS doen't support UIViewContentModeScaleAspectFill, we have to manually resample the image
// If we're in cover mode we need to ensure that the image is re-sampled to the correct size when the container size (shrinking
// If we're in cover mode we need to ensure that the image is re-sampled to the correct size when the container size (shrinking
// being the most obvious case) otherwise we will end up in a state an image will not properly scale inside its container
&& (RCTResizeModeFromUIViewContentMode(_imageView.contentMode) != RCTResizeModeCover ||
(imageSize.width == idealSize.width && imageSize.height == idealSize.height))
Expand Down Expand Up @@ -617,13 +604,13 @@ - (void)didMoveToWindow
[self reloadImage];
}
}

#if TARGET_OS_OSX // [macOS
- (void)viewDidChangeBackingProperties
{
[self reloadImage];
}

- (RCTPlatformView *)reactAccessibilityElement
{
return _imageView;
Expand Down
11 changes: 1 addition & 10 deletions packages/react-native/Libraries/Image/RCTResizeMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,12 @@
#import <React/RCTConvert.h>

typedef NS_ENUM(NSInteger, RCTResizeMode) {
#if !TARGET_OS_OSX // [macOS]
RCTResizeModeCover = UIViewContentModeScaleAspectFill,
RCTResizeModeContain = UIViewContentModeScaleAspectFit,
RCTResizeModeStretch = UIViewContentModeScaleToFill,
RCTResizeModeCenter = UIViewContentModeCenter,
RCTResizeModeRepeat = -1, // Use negative values to avoid
RCTResizeModeNone = UIViewContentModeTopLeft,
#else // [macOS
RCTResizeModeCover = -2, // Not supported by NSImageView
RCTResizeModeContain = NSImageScaleProportionallyUpOrDown,
RCTResizeModeStretch = NSImageScaleAxesIndependently,
RCTResizeModeCenter = -3, // assumes NSImageAlignmentCenter
RCTResizeModeRepeat = -1,
RCTResizeModeNone = NSImageScaleNone,
#endif // macOS]
RCTResizeModeRepeat = -1, // Use negative values to avoid conflicts with iOS enum values.
};

static inline RCTResizeMode RCTResizeModeFromUIViewContentMode(UIViewContentMode mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const bubblingEventTypes = {

const directEventTypes = {
...PlatformBaseViewConfigIos.directEventTypes,
topDoubleClick: {
registrationName: 'onDoubleClick',
},
topDragEnter: {
registrationName: 'onDragEnter',
},
Expand Down Expand Up @@ -67,6 +70,7 @@ const validAttributesForNonEventProps = {

// Props for bubbling and direct events
const validAttributesForEventProps = ConditionallyIgnoredEventHandlers({
onDoubleClick: true,
onBlur: true,
onDragEnter: true,
onDragLeave: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -14,11 +14,6 @@

import type {ColorValue} from './StyleSheet';

import {
ColorWithSystemEffectMacOSPrivate,
DynamicColorMacOSPrivate,
} from './PlatformColorValueTypes.macos';

export type DynamicColorMacOSTuple = {
light: ColorValue,
dark: ColorValue,
Expand All @@ -29,12 +24,7 @@ export type DynamicColorMacOSTuple = {
export const DynamicColorMacOS = (
tuple: DynamicColorMacOSTuple,
): ColorValue => {
return DynamicColorMacOSPrivate({
light: tuple.light,
dark: tuple.dark,
highContrastLight: tuple.highContrastLight,
highContrastDark: tuple.highContrastDark,
});
throw new Error('DynamicColorMacOS is not available on this platform.');
};

export type SystemEffectMacOS =
Expand All @@ -48,5 +38,7 @@ export const ColorWithSystemEffectMacOS = (
color: ColorValue,
effect: SystemEffectMacOS,
): ColorValue => {
return ColorWithSystemEffectMacOSPrivate(color, effect);
throw new Error(
'ColorWithSystemEffectMacOS is not available on this platform.',
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ - (RCTShadowView *)shadowView

#if TARGET_OS_OSX // [macOS
RCT_REMAP_SHADOW_PROPERTY(cursor, textAttributes.cursor, RCTCursor)
RCT_REMAP_SHADOW_PROPERTY(href, textAttributes.href, NSString)
#endif // macOS]

@end
1 change: 1 addition & 0 deletions packages/react-native/Libraries/Text/RCTTextAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern NSString *const RCTTextAttributesTagAttributeName;

#if TARGET_OS_OSX // [macOS
@property (nonatomic, assign) RCTCursor cursor;
@property (nonatomic, copy, nullable) NSString *href;
#endif // macOS]

#pragma mark - Inheritance
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/Libraries/Text/RCTTextAttributes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ - (void)applyTextAttributes:(RCTTextAttributes *)textAttributes
textAttributes->_textTransform != RCTTextTransformUndefined ? textAttributes->_textTransform : _textTransform;
#if TARGET_OS_OSX // [macOS
_cursor = textAttributes->_cursor != RCTCursorAuto ? textAttributes->_cursor : _cursor;
_href = textAttributes->_href ?: _href;
#endif // macOS]
}

Expand Down Expand Up @@ -237,6 +238,9 @@ - (NSParagraphStyle *)effectiveParagraphStyle
if (_cursor != RCTCursorAuto) {
attributes[NSCursorAttributeName] = NSCursorFromRCTCursor(_cursor);
}
if (_href) {
attributes[NSLinkAttributeName] = [RCTConvert NSURL:_href];
}
#endif // macOS]

return [attributes copy];
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/Libraries/Text/Text/RCTTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

NS_ASSUME_NONNULL_BEGIN

#if !TARGET_OS_OSX // [macOS]
@interface RCTTextView : RCTUIView // [macOS]
#else // [macOS
@interface RCTTextView : RCTUIView <ExtensibleNativeMenuProtocol>
#endif // macOS]

- (instancetype)initWithEventDispatcher:(id<RCTEventDispatcherProtocol>)eventDispatcher; // [macOS]

Expand Down
Loading