Skip to content
Merged
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
4 changes: 3 additions & 1 deletion Libraries/Image/RCTImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
name:UIApplicationDidEnterBackgroundNotification
object:nil];
_imageView = [[UIImageView alloc] init];
#else
_imageView = [[NSImageView alloc] init];
#endif // TODO(macOS ISS#2323203)
_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:_imageView];
#endif // TODO(macOS ISS#2323203)
}
return self;
}
Expand Down
6 changes: 2 additions & 4 deletions Libraries/react-native/react-native-implementation.macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,14 @@ module.exports = {
get VirtualizedList() {
return require('VirtualizedList');
},
/*
get VirtualizedSectionList() {
return require('VirtualizedSectionList');
},*/
},

// APIs
/*
get ActionSheetIOS() {
return require('ActionSheetIOS');
},*/
},
get Alert() {
return require('Alert');
},
Expand Down
9 changes: 7 additions & 2 deletions React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,12 @@ BOOL RCTRunningInAppExtension(void)
}

// TODO: replace with a more robust solution
return RCTSharedApplication().keyWindow;
for (UIWindow *window in RCTSharedApplication().windows) {
if (window.keyWindow) {
return window;
}
}
return nil;
}

UIViewController *__nullable RCTPresentedViewController(void)
Expand Down Expand Up @@ -835,7 +840,7 @@ BOOL RCTIsLocalAssetURL(NSURL *__nullable imageURL)
#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];
#else // [TODO(macOS ISS#2323203)
image = [bundle imageForResource:imageName];
image = [bundle imageForResource:imageName];
#endif // ]TODO(macOS ISS#2323203)
if (image) {
RCTLogWarn(@"Image %@ not found in mainBundle, but found in %@", imageName, bundle);
Expand Down
57 changes: 25 additions & 32 deletions React/Modules/RCTRedBox.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ - (void)loadExtraDataViewController;
@end

#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
@interface RCTRedBoxWindow : UIWindow <UITableViewDelegate, UITableViewDataSource>
@interface RCTRedBoxWindow : NSObject <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UIViewController *rootViewController;
@property (nonatomic, weak) id<RCTRedBoxWindowActionDelegate> actionDelegate;
@end

Expand All @@ -42,19 +43,11 @@ @implementation RCTRedBoxWindow

- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
#if TARGET_OS_TV
self.windowLevel = UIWindowLevelAlert + 1000;
#else
self.windowLevel = UIWindowLevelStatusBar - 1;
#endif
self.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1];
self.hidden = YES;

UIViewController *rootController = [UIViewController new];
self.rootViewController = rootController;
UIView *rootView = rootController.view;
rootView.backgroundColor = [UIColor clearColor];
if ((self = [super init])) {
_rootViewController = [UIViewController new];
UIView *rootView = _rootViewController.view;
rootView.frame = frame;
rootView.backgroundColor = [UIColor blackColor];

const CGFloat buttonHeight = 60;

Expand Down Expand Up @@ -133,8 +126,8 @@ - (instancetype)initWithFrame:(CGRect)frame
[extraButton setTitleColor:[UIColor colorWithWhite:1 alpha:0.5] forState:UIControlStateHighlighted];
[extraButton addTarget:self action:@selector(showExtraDataViewController) forControlEvents:UIControlEventTouchUpInside];

CGFloat buttonWidth = self.bounds.size.width / 4;
CGFloat bottomButtonHeight = self.bounds.size.height - buttonHeight - [self bottomSafeViewHeight];
CGFloat buttonWidth = frame.size.width / 4;
CGFloat bottomButtonHeight = frame.size.height - buttonHeight - [self bottomSafeViewHeight];

dismissButton.frame = CGRectMake(0, bottomButtonHeight, buttonWidth, buttonHeight);
reloadButton.frame = CGRectMake(buttonWidth, bottomButtonHeight, buttonWidth, buttonHeight);
Expand All @@ -152,7 +145,7 @@ - (instancetype)initWithFrame:(CGRect)frame

UIView *bottomSafeView = [UIView new];
bottomSafeView.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1];
bottomSafeView.frame = CGRectMake(0, self.bounds.size.height - [self bottomSafeViewHeight], self.bounds.size.width, [self bottomSafeViewHeight]);
bottomSafeView.frame = CGRectMake(0, frame.size.height - [self bottomSafeViewHeight], frame.size.width, [self bottomSafeViewHeight]);

[rootView addSubview:bottomSafeView];
}
Expand Down Expand Up @@ -190,30 +183,29 @@ - (void)showErrorMessage:(NSString *)message withStack:(NSArray<RCTJSStackFrame
NSString *messageWithoutAnsi = [self stripAnsi:message];

// Show if this is a new message, or if we're updating the previous message
if ((self.hidden && !isUpdate) || (!self.hidden && isUpdate && [_lastErrorMessage isEqualToString:messageWithoutAnsi])) {
BOOL hidden = !self.rootViewController.isBeingPresented;
if ((hidden && !isUpdate) || (!hidden && isUpdate && [_lastErrorMessage isEqualToString:messageWithoutAnsi])) {
_lastStackTrace = stack;
// message is displayed using UILabel, which is unable to render text of
// unlimited length, so we truncate it
_lastErrorMessage = [messageWithoutAnsi substringToIndex:MIN((NSUInteger)10000, messageWithoutAnsi.length)];

[_stackTraceTableView reloadData];

if (self.hidden) {
if (hidden) {
[_stackTraceTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
atScrollPosition:UITableViewScrollPositionTop
animated:NO];
[RCTKeyWindow().rootViewController presentViewController:self.rootViewController
animated:YES
completion:nil];
}

[self makeKeyAndVisible];
[self becomeFirstResponder];
}
}

- (void)dismiss
{
self.hidden = YES;
[self resignFirstResponder];
[RCTSharedApplication().delegate.window makeKeyWindow];
[self.rootViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)reload
Expand Down Expand Up @@ -554,13 +546,13 @@ - (void)showErrorMessage:(NSString *)message withStack:(NSArray<RCTJSStackFrame
if (!_visible) {
_visible = YES;
[_window center];
if (!RCTRunningInTestEnvironment()) {
[NSApp runModalForWindow:_window];
}
else {
[NSApp activateIgnoringOtherApps:YES];
[[NSApp mainWindow] makeKeyAndOrderFront:_window];
}
if (!RCTRunningInTestEnvironment()) {
[NSApp runModalForWindow:_window];
}
else {
[NSApp activateIgnoringOtherApps:YES];
[[NSApp mainWindow] makeKeyAndOrderFront:_window];
}
}
}
}
Expand Down Expand Up @@ -881,6 +873,7 @@ - (void)loadExtraDataViewController {
#else // ]TODO(macOS ISS#2323203)
dispatch_async(dispatch_get_main_queue(), ^{
[self->_window dismiss];
self->_window = nil; // TODO(OSS Candidate ISS#2710739): release _window now to ensure its UIKit ivars are dealloc'd on the main thread as the RCTRedBox can be dealloc'd on a background thread.
});
#endif // TODO(macOS ISS#2323203)
}
Expand Down