Skip to content

Commit

Permalink
Fix Dimension for macOS (facebook#348)
Browse files Browse the repository at this point in the history
* Update scripts to publish react-native-macos-init

* Clean up merge markers

* Restored ios:macos RNTester parity except for InputAccessoryView.

* Revert "Restored ios:macos RNTester parity except for InputAccessoryView."

This reverts commit 5a67ae0.

* Remove unnecessary android builds and tar file upload.

* Fix Dimensions for macOS

* Update Podlock.file

* Restore previous 'window' dim behavior.

* Renamed windowSize to size.

Co-authored-by: React-Native Bot <[email protected]>
  • Loading branch information
tom-un and rnbot authored May 8, 2020
1 parent f5aebe5 commit 61638a2
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 56 deletions.
52 changes: 26 additions & 26 deletions RNTester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -348,34 +348,34 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
boost-for-react-native: a110407d9db2642fd2e1bcd7c5a51c81f2521dc9
DoubleConversion: a1bc12a74baa397a2609e0f10e19b8062d864053
FBLazyVector: c1a4e0c7c94510ed45096fd47fce665424d8c00a
FBReactNativeSpec: 9ae539b7e366b481cd690a3241bdd677af33bde1
FBLazyVector: f0e0df84578f80a66fd746f051e447b860b47bf3
FBReactNativeSpec: d3e3e305a38696069a21420e6c2dd79d067c73a9
Folly: feff29ba9d0b7c2e4f793a94942831d6cc5bbad7
glog: b3f6d74f3e2d33396addc0ee724d2b2b79fc3e00
RCTRequired: 313773d7d9e5e30b68fba394a49755ef2cbe2741
RCTTypeSafety: cdd9e2617c3692199c3bc5da791730472d440ae2
React: 151e5b0a6dbee207a711306a2ab3cf6b2d3059ea
React-ART: 7f68acd3818c6fe7e6430e0c0ef009383e68aee3
React-Core: fb668c18bbeb6812d55e86019e1bec201c3a059d
React-CoreModules: 396acc98714e3af464f1153252f8dfdb8507d016
React-cxxreact: 30dd117c1143c92c3cbb74b761bb44edbad801bd
React-jsi: c38f0d09305a4afa22e5d54f3a1622dd1d6be644
React-jsiexecutor: 72399803b25bafec90791d56c21f20f0240d32ce
React-jsinspector: 3513ab27e5587f87ee8e295c4a2b54485424547a
React-RCTActionSheet: 07e9fac815d5399b12a7f79a5593ce23135bcd1f
React-RCTAnimation: 3dd140a28b092e8a2562bcda3dfecf30ae07f064
React-RCTBlob: 602e263532c6bbfa9a6feedaac177b13eeeb8ff5
React-RCTImage: 54934276dea15f319e768b45f711e07009a2fdba
React-RCTLinking: 86c0eb052a95ae447e0d2b666ba6523b26ca58e1
React-RCTNetwork: 0b8a8d1e18a66dafced8c2cfc369a53ac68dce34
React-RCTPushNotification: dfce10fd71a0d171a64668156f4d8356ee1a9e82
React-RCTSettings: 59554f1a1a762c845997e380b83fd8041e29facd
React-RCTTest: 9ab0918fa68e349e0d0347a81e3404104037d88d
React-RCTText: 00a855d78dcaa9b992ff12e6fd282d654e8e300b
React-RCTVibration: 67d42e894e29edf4b33ba729e9f5885c04e41303
ReactCommon: 1ec21feb4a8d44be66747bd06134f587b8ae499f
Yoga: 22ba96ecfbe709bfef9b658a631013af9f6ebd45
RCTRequired: a573cb908cfc02fdaaf6e63e7e1c55e8153fc977
RCTTypeSafety: d58e22c29cb25122c11172a3121484a517b48ca5
React: 2b0d09dac43fd5a442dd412b2a07dcba5038b223
React-ART: 8b1fba341468349688d8c055d7305ee2b9fb0ac9
React-Core: 118f5e89b085aa6be453da4c31e30fd38c7bd7e3
React-CoreModules: 1eccf9a46ef23e9a31fc445a01225ee0a2a05936
React-cxxreact: 4c23c5df9b8d304a7daf572152bd0155ba38ca00
React-jsi: 54f8e7208d44c3f4cacbdee580c8bff7dc9a6655
React-jsiexecutor: 42cb111d20bee4f18a994f6c33a9973f3157da65
React-jsinspector: 60e026ea8263b4dcea8df64b12fac06642f6fdda
React-RCTActionSheet: 99c8723f606fd1b55cd5a3b794fd86d8b14677a5
React-RCTAnimation: bd0ee82d577e61e2c485903bf387d36294d954ac
React-RCTBlob: 20e60087c155b0f3bd0b2401ea43ffdd4a625648
React-RCTImage: 9afd4553833185d6099e82c990ff604ebc0a3804
React-RCTLinking: 9c03f63acb0da803efc3218509743e63d22256c0
React-RCTNetwork: 0893c8dff3c0cbf2bdb61444e9aae842f7824399
React-RCTPushNotification: 416b0e93705ca217c63e1ecd6d6b494281bea375
React-RCTSettings: 1778d7ecf07703bbfc7f565eac820447355513c0
React-RCTTest: 53a3563d3bf54d4342dd599518748f62cd0def14
React-RCTText: 8d87a5dcd9a50bfef8ae61d4a6da95e39dc9d2b3
React-RCTVibration: b7b18d0cf7cffa5ba48a006b13e5cac337b61701
ReactCommon: a309e51dec398e5095e9e07410fa25d9ef0fd4c2
Yoga: 135abc3b97d777f821297e5dff54e5cec85568f8

PODFILE CHECKSUM: 9bfdd5bfee61814974e42ca8fda603a38c2e241e
PODFILE CHECKSUM: 2bf56de39dc7e153b4f1637e0f4874f2591fc55a

COCOAPODS: 1.8.4
1 change: 0 additions & 1 deletion React-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ Pod::Spec.new do |s|
# [TODO(macOS ISS#2323203)
"**/MacOS/*"
ss.osx.exclude_files = "React/Modules/RCTRedBoxExtraDataViewController.{h,m}",
"React/UIUtils/*",
"React/Profiler/{RCTFPSGraph,RCTPerfMonitor}.*",
"React/Profiler/RCTProfileTrampoline-{arm,arm64,i386}.S",
"React/Base/RCTKeyCommands.*",
Expand Down
32 changes: 4 additions & 28 deletions React/Modules/RCTDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#import "RCTAccessibilityManager.h"
#import "RCTAssert.h"
#import "RCTEventDispatcher.h"
#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
#import "RCTUIUtils.h"
#endif // TODO(macOS ISS#2323203)
#import "RCTUtils.h"
#import <React/RCTUIKit.h> // TODO(macOS ISS#2323203)
#import "UIView+React.h" // TODO(macOS ISS#2323203)
Expand Down Expand Up @@ -98,6 +96,10 @@ static BOOL RCTIsIPhoneX() {

#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
RCTDimensions dimensions = RCTGetDimensions(bridge.accessibilityManager.multiplier);
#else // [TODO(macOS ISS#2323203)
RCTDimensions dimensions = RCTGetDimensions(rootView);
#endif // ]TODO(macOS ISS#2323203)

typeof (dimensions.window) window = dimensions.window;
NSDictionary<NSString *, NSNumber *> *dimsWindow = @{
@"width": @(window.width),
Expand All @@ -116,32 +118,6 @@ static BOOL RCTIsIPhoneX() {
@"window": dimsWindow,
@"screen": dimsScreen
};
#else // [TODO(macOS ISS#2323203)
if (rootView != nil) {
NSWindow *window = rootView.window;
if (window != nil) {
NSSize size = rootView.bounds.size;
return @{
@"window": @{
@"width": @(size.width),
@"height": @(size.height),
@"scale": @(window.backingScaleFactor),
},
@"rootTag" : rootView.reactTag,
};
}
}

// We don't have a root view or window yet so make something up
NSScreen *screen = [NSScreen screens].firstObject;
return @{
@"window": @{
@"width": @(screen.frame.size.width),
@"height": @(screen.frame.size.height),
@"scale": @(screen.backingScaleFactor),
},
};
#endif // ]TODO(macOS ISS#2323203)
}

- (void)dealloc
Expand Down
6 changes: 6 additions & 0 deletions React/UIUtils/RCTUIUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ typedef struct {
} window, screen;
} RCTDimensions;
extern __attribute__((visibility("default")))
#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
RCTDimensions RCTGetDimensions(CGFloat fontScale);
#else // [TODO(macOS ISS#2323203)
RCTDimensions RCTGetDimensions(RCTPlatformView *rootView);
#endif // ]TODO(macOS ISS#2323203)

#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
// Get font size multiplier for font base size (Large) by content size category
extern __attribute__((visibility("default")))
CGFloat RCTGetMultiplierForContentSizeCategory(UIContentSizeCategory category);
#endif // TODO(macOS ISS#2323203)

#ifdef __cplusplus
}
Expand Down
44 changes: 44 additions & 0 deletions React/UIUtils/RCTUIUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import "RCTUtils.h"

#if !TARGET_OS_OSX // TODO(macOS ISS#2323203)
RCTDimensions RCTGetDimensions(CGFloat fontScale)
{
UIScreen *mainScreen = UIScreen.mainScreen;
Expand Down Expand Up @@ -61,3 +62,46 @@ CGFloat RCTGetMultiplierForContentSizeCategory(UIContentSizeCategory category)
double value = multipliers[category].doubleValue;
return value > 0.0 ? value : 1.0;
}

#else // [TODO(macOS ISS#2323203)

RCTDimensions RCTGetDimensions(RCTPlatformView *rootView) {
RCTDimensions dimensions = {
{ 0, 0, 0, /*fontScale*/ 1 },
{ 0, 0, 0, /*fontScale*/ 1 }
};
NSScreen *screen = nil;
NSWindow *window = nil;
NSSize size;
if (rootView != nil) {
window = [rootView window];
size = [rootView frame].size;
} else {
// We don't have a root view so fall back to the app's key window
window = [NSApp keyWindow];
size = [window frame].size;
}

if (window != nil) {
screen = [window screen];
dimensions.window.width = size.width;
dimensions.window.height = size.height;
dimensions.window.scale = [window backingScaleFactor];
} else {
// We don't have a window yet so make something up
screen = [NSScreen mainScreen];
NSSize screenSize = [screen frame].size;
dimensions.window.width = screenSize.width;
dimensions.window.height = screenSize.height;
dimensions.window.scale = [screen backingScaleFactor];
}

NSSize screenSize = [screen frame].size;
dimensions.screen.width = screenSize.width;
dimensions.screen.height = screenSize.height;
dimensions.screen.scale = [screen backingScaleFactor];

return dimensions;
}

#endif // ]TODO(macOS ISS#2323203)
2 changes: 1 addition & 1 deletion scripts/react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fi

case "$CONFIGURATION" in
*Debug*)
if [[ "$PLATFORM_NAME" == *simulator ]]; then
if [[ "$PLATFORM_NAME" == *simulator || "$PLATFORM_NAME" == macosx ]]; then
if [[ "$FORCE_BUNDLING" ]]; then
echo "FORCE_BUNDLING enabled; continuing to bundle."
else
Expand Down

0 comments on commit 61638a2

Please sign in to comment.