2019-10-16 20:03:47 +03:00
|
|
|
/*
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-03-18 02:47:51 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-03-18 02:47:51 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTDeviceInfo.h"
|
|
|
|
|
2019-08-22 00:28:16 +03:00
|
|
|
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
|
|
|
#import <React/RCTAccessibilityManager.h>
|
|
|
|
#import <React/RCTAssert.h>
|
2019-12-11 21:02:12 +03:00
|
|
|
#import <React/RCTConstants.h>
|
2020-10-14 12:37:51 +03:00
|
|
|
#import <React/RCTEventDispatcherProtocol.h>
|
2019-08-22 00:28:16 +03:00
|
|
|
#import <React/RCTUIUtils.h>
|
|
|
|
#import <React/RCTUtils.h>
|
|
|
|
|
|
|
|
#import "CoreModulesPlugins.h"
|
|
|
|
|
|
|
|
using namespace facebook::react;
|
|
|
|
|
|
|
|
@interface RCTDeviceInfo () <NativeDeviceInfoSpec>
|
|
|
|
@end
|
2017-03-18 02:47:51 +03:00
|
|
|
|
|
|
|
@implementation RCTDeviceInfo {
|
|
|
|
UIInterfaceOrientation _currentInterfaceOrientation;
|
2019-04-11 00:08:42 +03:00
|
|
|
NSDictionary *_currentInterfaceDimensions;
|
2017-03-18 02:47:51 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 21:39:18 +03:00
|
|
|
@synthesize moduleRegistry = _moduleRegistry;
|
2017-03-18 02:47:51 +03:00
|
|
|
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2017-08-07 16:45:24 +03:00
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2017-03-18 02:47:51 +03:00
|
|
|
- (dispatch_queue_t)methodQueue
|
|
|
|
{
|
|
|
|
return dispatch_get_main_queue();
|
|
|
|
}
|
|
|
|
|
2020-12-13 05:58:58 +03:00
|
|
|
- (void)setModuleRegistry:(RCTModuleRegistry *)moduleRegistry
|
2017-03-18 02:47:51 +03:00
|
|
|
{
|
2020-12-13 05:58:58 +03:00
|
|
|
_moduleRegistry = moduleRegistry;
|
2017-03-18 02:47:51 +03:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(didReceiveNewContentSizeMultiplier)
|
|
|
|
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
|
2020-12-13 05:58:58 +03:00
|
|
|
object:[moduleRegistry moduleForName:"AccessibilityManager"]];
|
remove most of tvOS remnants from the code (#29407)
Summary:
Refs: [0.62 release](https://reactnative.dev/blog/#moving-apple-tv-to-react-native-tvos), https://github.com/facebook/react-native/issues/28706, https://github.com/facebook/react-native/issues/28743, https://github.com/facebook/react-native/issues/29018
This PR removes most of the tvOS remnants in the code. Most of the changes are related to the tvOS platform removal from `.podspec` files, tvOS specific conditionals removal (Obj-C + JS) or tvOS CI/testing pipeline related code.
In addition to the changes listed above I have removed the deprecated `Platform.isTVOS` method. I'm not sure how `Platform.isTV` method is correlated with Android TV devices support which is technically not deprecated in the core so I left this method untouched for now.
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->
* **[Internal] [Removed]** - remove most of tvOS remnants from the code:
* `TVEventHandler`, `TVTouchable`, `RCTTVView`, `RCTTVRemoteHandler` and `RCTTVNavigationEventEmitter`
* **[Internal] [Removed]** - remove `TARGET_TV_OS` flag and all the usages
* **[iOS] [Removed]** - remove deprecated `Platform.isTVOS` method
* **[iOS] [Removed]** - remove deprecated and TV related props from View:
* `isTVSelectable`, `hasTVPreferredFocus` and `tvParallaxProperties`
* **[iOS] [Removed]** - remove `BackHandler` utility implementation
Pull Request resolved: https://github.com/facebook/react-native/pull/29407
Test Plan: Local tests (and iOS CI run) do not yield any errors, but I'm not sure how the CI pipeline would react to those changes. That is the reason why this PR is being posted as Draft. Some tweaks and code adjustment could be required.
Reviewed By: PeteTheHeat
Differential Revision: D22619441
Pulled By: shergin
fbshipit-source-id: 9aaf3840c5e8bd469c2cfcfa7c5b441ef71b30b6
2020-09-29 07:24:45 +03:00
|
|
|
|
2017-03-18 02:47:51 +03:00
|
|
|
_currentInterfaceOrientation = [RCTSharedApplication() statusBarOrientation];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(interfaceOrientationDidChange)
|
|
|
|
name:UIApplicationDidChangeStatusBarOrientationNotification
|
|
|
|
object:nil];
|
2019-04-11 00:08:42 +03:00
|
|
|
|
2020-12-13 05:58:58 +03:00
|
|
|
_currentInterfaceDimensions = RCTExportedDimensions(_moduleRegistry);
|
2019-04-11 00:08:42 +03:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
2020-03-09 08:58:01 +03:00
|
|
|
selector:@selector(interfaceFrameDidChange)
|
|
|
|
name:UIApplicationDidBecomeActiveNotification
|
|
|
|
object:nil];
|
2019-12-11 21:02:12 +03:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
2020-03-09 08:58:01 +03:00
|
|
|
selector:@selector(interfaceFrameDidChange)
|
|
|
|
name:RCTUserInterfaceStyleDidChangeNotification
|
|
|
|
object:nil];
|
2017-03-18 02:47:51 +03:00
|
|
|
}
|
|
|
|
|
2020-03-09 08:58:01 +03:00
|
|
|
static BOOL RCTIsIPhoneX()
|
|
|
|
{
|
2018-07-06 05:10:28 +03:00
|
|
|
static BOOL isIPhoneX = NO;
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
RCTAssertMainQueue();
|
|
|
|
|
2018-09-17 07:38:47 +03:00
|
|
|
CGSize screenSize = [UIScreen mainScreen].nativeBounds.size;
|
|
|
|
CGSize iPhoneXScreenSize = CGSizeMake(1125, 2436);
|
|
|
|
CGSize iPhoneXMaxScreenSize = CGSizeMake(1242, 2688);
|
|
|
|
CGSize iPhoneXRScreenSize = CGSizeMake(828, 1792);
|
2020-12-09 19:28:08 +03:00
|
|
|
CGSize iPhone12ScreenSize = CGSizeMake(1170, 2532);
|
|
|
|
CGSize iPhone12MiniScreenSize = CGSizeMake(1080, 2340);
|
|
|
|
CGSize iPhone12ProMaxScreenSize = CGSizeMake(1284, 2778);
|
2018-09-17 07:38:47 +03:00
|
|
|
|
2020-03-09 08:58:01 +03:00
|
|
|
isIPhoneX = CGSizeEqualToSize(screenSize, iPhoneXScreenSize) ||
|
2020-12-09 19:28:08 +03:00
|
|
|
CGSizeEqualToSize(screenSize, iPhoneXMaxScreenSize) || CGSizeEqualToSize(screenSize, iPhoneXRScreenSize) ||
|
|
|
|
CGSizeEqualToSize(screenSize, iPhone12ScreenSize) || CGSizeEqualToSize(screenSize, iPhone12MiniScreenSize) ||
|
|
|
|
CGSizeEqualToSize(screenSize, iPhone12ProMaxScreenSize);
|
|
|
|
;
|
2018-07-06 05:10:28 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return isIPhoneX;
|
|
|
|
}
|
|
|
|
|
2020-12-13 05:58:58 +03:00
|
|
|
static NSDictionary *RCTExportedDimensions(RCTModuleRegistry *moduleRegistry)
|
2017-03-18 02:47:51 +03:00
|
|
|
{
|
|
|
|
RCTAssertMainQueue();
|
2020-10-12 22:47:18 +03:00
|
|
|
RCTDimensions dimensions;
|
2020-12-13 05:58:58 +03:00
|
|
|
if (moduleRegistry) {
|
2020-10-12 22:47:18 +03:00
|
|
|
dimensions = RCTGetDimensions(
|
2020-12-13 05:58:58 +03:00
|
|
|
((RCTAccessibilityManager *)[moduleRegistry moduleForName:"AccessibilityManager"]).multiplier ?: 1.0);
|
2020-10-12 22:47:18 +03:00
|
|
|
} else {
|
2020-12-13 05:58:58 +03:00
|
|
|
RCTAssert(false, @"ModuleRegistry must be set to properly init dimensions.");
|
2020-10-12 22:47:18 +03:00
|
|
|
}
|
2020-03-09 08:58:01 +03:00
|
|
|
__typeof(dimensions.window) window = dimensions.window;
|
2019-04-11 00:08:42 +03:00
|
|
|
NSDictionary<NSString *, NSNumber *> *dimsWindow = @{
|
2020-03-09 08:58:01 +03:00
|
|
|
@"width" : @(window.width),
|
|
|
|
@"height" : @(window.height),
|
|
|
|
@"scale" : @(window.scale),
|
|
|
|
@"fontScale" : @(window.fontScale)
|
2018-01-29 22:07:37 +03:00
|
|
|
};
|
2019-08-22 00:28:16 +03:00
|
|
|
__typeof(dimensions.screen) screen = dimensions.screen;
|
2019-04-11 00:08:42 +03:00
|
|
|
NSDictionary<NSString *, NSNumber *> *dimsScreen = @{
|
2020-03-09 08:58:01 +03:00
|
|
|
@"width" : @(screen.width),
|
|
|
|
@"height" : @(screen.height),
|
|
|
|
@"scale" : @(screen.scale),
|
|
|
|
@"fontScale" : @(screen.fontScale)
|
2018-01-29 22:07:37 +03:00
|
|
|
};
|
2020-03-09 08:58:01 +03:00
|
|
|
return @{@"window" : dimsWindow, @"screen" : dimsScreen};
|
2017-03-18 02:47:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary<NSString *, id> *)constantsToExport
|
2019-02-05 04:41:36 +03:00
|
|
|
{
|
|
|
|
return [self getConstants];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary<NSString *, id> *)getConstants
|
2017-03-18 02:47:51 +03:00
|
|
|
{
|
Run getConstants method statements on main queue
Summary:
If a NativeModule requires main queue setup, its `getConstants()` method must be executed on the main thead. The legacy NativeModule infra takes care of this for us. With TurboModules, however, all synchronous methods, including `getConstants()`, execute on the JS thread. Therefore, if a TurboModule requires main queue setup, and exports constants, we must execute its `getConstants()` method body on the main queue explicitly.
**Notes:**
- The changes in this diff should be a noop when TurboModules is off, because `RCTUnsafeExecuteOnMainQueueSync` synchronously execute its block on the current thread if the current thread is the main thread.
- If a NativeModule doens't have the `requiresMainQueueSetup` method, but has the `constantsToExport` method, both NativeModules and TurboModules assume that it requires main queue setup.
## Script
```
const exec = require("../lib/exec");
const abspath = require("../lib/abspath");
const relpath = require("../lib/relpath");
const readFile = (filename) => require("fs").readFileSync(filename, "utf8");
const writeFile = (filename, content) =>
require("fs").writeFileSync(filename, content);
function main() {
const tmFiles = exec("cd ~/fbsource && xbgs -n 10000 -l constantsToExport")
.split("\n")
.filter(Boolean);
const filesWithoutConstantsToExport = [];
const filesWithConstantsToExportButNotGetConstants = [];
const filesExplicitlyNotRequiringMainQueueSetup = [];
tmFiles
.filter((filename) => {
if (filename.includes("microsoft-fork-of-react-native")) {
return false;
}
return /\.mm?$/.test(filename);
})
.map(abspath)
.forEach((filename) => {
const code = readFile(filename);
const relFilename = relpath(filename);
if (!/constantsToExport\s*{/.test(code)) {
filesWithoutConstantsToExport.push(relFilename);
return;
}
if (!/getConstants\s*{/.test(code)) {
filesWithConstantsToExportButNotGetConstants.push(relFilename);
return;
}
if (/requiresMainQueueSetup\s*{/.test(code)) {
const requiresMainQueueSetupRegex = /requiresMainQueueSetup\s*{\s*return\s+(?<requiresMainQueueSetup>YES|NO)/;
const requiresMainQueueSetupRegexMatch = requiresMainQueueSetupRegex.exec(
code
);
if (!requiresMainQueueSetupRegexMatch) {
throw new Error(
"Detected requiresMainQueueSetup method in file " +
relFilename +
" but was unable to parse the method return value"
);
}
const {
requiresMainQueueSetup,
} = requiresMainQueueSetupRegexMatch.groups;
if (requiresMainQueueSetup == "NO") {
filesExplicitlyNotRequiringMainQueueSetup.push(relFilename);
return;
}
}
const getConstantsTypeRegex = () => /-\s*\((?<type>.*)\)getConstants\s*{/;
const getConstantsTypeRegexMatch = getConstantsTypeRegex().exec(code);
if (!getConstantsTypeRegexMatch) {
throw new Error(
`Failed to parse return type of getConstants method in file ${relFilename}`
);
}
const getConstantsType = getConstantsTypeRegexMatch.groups.type;
const getConstantsBody = code
.split(getConstantsTypeRegex())[2]
.split("\n}")[0];
const newGetConstantsBody = `
__block ${getConstantsType} constants;
RCTUnsafeExecuteOnMainQueueSync(^{${getConstantsBody
.replace(/\n/g, "\n ")
.replace(/_bridge/g, "self->_bridge")
.replace(/return /g, "constants = ")}
});
return constants;
`;
writeFile(
filename,
code
.replace(getConstantsBody, newGetConstantsBody)
.replace("#import", "#import <React/RCTUtils.h>\n#import")
);
});
console.log("Files without constantsToExport: ");
filesWithoutConstantsToExport.forEach((file) => console.log(file));
console.log();
console.log("Files with constantsToExport but no getConstants: ");
filesWithConstantsToExportButNotGetConstants.forEach((file) =>
console.log(file)
);
console.log();
console.log("Files with requiresMainQueueSetup = NO: ");
filesExplicitlyNotRequiringMainQueueSetup.forEach((file) =>
console.log(file)
);
}
if (!module.parent) {
main();
}
```
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D21797048
fbshipit-source-id: a822a858fecdbe976e6197f8339e509dc7cd917f
2020-06-03 08:58:04 +03:00
|
|
|
__block NSDictionary<NSString *, id> *constants;
|
2020-12-13 05:58:58 +03:00
|
|
|
RCTModuleRegistry *moduleRegistry = _moduleRegistry;
|
Run getConstants method statements on main queue
Summary:
If a NativeModule requires main queue setup, its `getConstants()` method must be executed on the main thead. The legacy NativeModule infra takes care of this for us. With TurboModules, however, all synchronous methods, including `getConstants()`, execute on the JS thread. Therefore, if a TurboModule requires main queue setup, and exports constants, we must execute its `getConstants()` method body on the main queue explicitly.
**Notes:**
- The changes in this diff should be a noop when TurboModules is off, because `RCTUnsafeExecuteOnMainQueueSync` synchronously execute its block on the current thread if the current thread is the main thread.
- If a NativeModule doens't have the `requiresMainQueueSetup` method, but has the `constantsToExport` method, both NativeModules and TurboModules assume that it requires main queue setup.
## Script
```
const exec = require("../lib/exec");
const abspath = require("../lib/abspath");
const relpath = require("../lib/relpath");
const readFile = (filename) => require("fs").readFileSync(filename, "utf8");
const writeFile = (filename, content) =>
require("fs").writeFileSync(filename, content);
function main() {
const tmFiles = exec("cd ~/fbsource && xbgs -n 10000 -l constantsToExport")
.split("\n")
.filter(Boolean);
const filesWithoutConstantsToExport = [];
const filesWithConstantsToExportButNotGetConstants = [];
const filesExplicitlyNotRequiringMainQueueSetup = [];
tmFiles
.filter((filename) => {
if (filename.includes("microsoft-fork-of-react-native")) {
return false;
}
return /\.mm?$/.test(filename);
})
.map(abspath)
.forEach((filename) => {
const code = readFile(filename);
const relFilename = relpath(filename);
if (!/constantsToExport\s*{/.test(code)) {
filesWithoutConstantsToExport.push(relFilename);
return;
}
if (!/getConstants\s*{/.test(code)) {
filesWithConstantsToExportButNotGetConstants.push(relFilename);
return;
}
if (/requiresMainQueueSetup\s*{/.test(code)) {
const requiresMainQueueSetupRegex = /requiresMainQueueSetup\s*{\s*return\s+(?<requiresMainQueueSetup>YES|NO)/;
const requiresMainQueueSetupRegexMatch = requiresMainQueueSetupRegex.exec(
code
);
if (!requiresMainQueueSetupRegexMatch) {
throw new Error(
"Detected requiresMainQueueSetup method in file " +
relFilename +
" but was unable to parse the method return value"
);
}
const {
requiresMainQueueSetup,
} = requiresMainQueueSetupRegexMatch.groups;
if (requiresMainQueueSetup == "NO") {
filesExplicitlyNotRequiringMainQueueSetup.push(relFilename);
return;
}
}
const getConstantsTypeRegex = () => /-\s*\((?<type>.*)\)getConstants\s*{/;
const getConstantsTypeRegexMatch = getConstantsTypeRegex().exec(code);
if (!getConstantsTypeRegexMatch) {
throw new Error(
`Failed to parse return type of getConstants method in file ${relFilename}`
);
}
const getConstantsType = getConstantsTypeRegexMatch.groups.type;
const getConstantsBody = code
.split(getConstantsTypeRegex())[2]
.split("\n}")[0];
const newGetConstantsBody = `
__block ${getConstantsType} constants;
RCTUnsafeExecuteOnMainQueueSync(^{${getConstantsBody
.replace(/\n/g, "\n ")
.replace(/_bridge/g, "self->_bridge")
.replace(/return /g, "constants = ")}
});
return constants;
`;
writeFile(
filename,
code
.replace(getConstantsBody, newGetConstantsBody)
.replace("#import", "#import <React/RCTUtils.h>\n#import")
);
});
console.log("Files without constantsToExport: ");
filesWithoutConstantsToExport.forEach((file) => console.log(file));
console.log();
console.log("Files with constantsToExport but no getConstants: ");
filesWithConstantsToExportButNotGetConstants.forEach((file) =>
console.log(file)
);
console.log();
console.log("Files with requiresMainQueueSetup = NO: ");
filesExplicitlyNotRequiringMainQueueSetup.forEach((file) =>
console.log(file)
);
}
if (!module.parent) {
main();
}
```
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D21797048
fbshipit-source-id: a822a858fecdbe976e6197f8339e509dc7cd917f
2020-06-03 08:58:04 +03:00
|
|
|
RCTUnsafeExecuteOnMainQueueSync(^{
|
|
|
|
constants = @{
|
2020-12-13 05:58:58 +03:00
|
|
|
@"Dimensions" : RCTExportedDimensions(moduleRegistry),
|
Run getConstants method statements on main queue
Summary:
If a NativeModule requires main queue setup, its `getConstants()` method must be executed on the main thead. The legacy NativeModule infra takes care of this for us. With TurboModules, however, all synchronous methods, including `getConstants()`, execute on the JS thread. Therefore, if a TurboModule requires main queue setup, and exports constants, we must execute its `getConstants()` method body on the main queue explicitly.
**Notes:**
- The changes in this diff should be a noop when TurboModules is off, because `RCTUnsafeExecuteOnMainQueueSync` synchronously execute its block on the current thread if the current thread is the main thread.
- If a NativeModule doens't have the `requiresMainQueueSetup` method, but has the `constantsToExport` method, both NativeModules and TurboModules assume that it requires main queue setup.
## Script
```
const exec = require("../lib/exec");
const abspath = require("../lib/abspath");
const relpath = require("../lib/relpath");
const readFile = (filename) => require("fs").readFileSync(filename, "utf8");
const writeFile = (filename, content) =>
require("fs").writeFileSync(filename, content);
function main() {
const tmFiles = exec("cd ~/fbsource && xbgs -n 10000 -l constantsToExport")
.split("\n")
.filter(Boolean);
const filesWithoutConstantsToExport = [];
const filesWithConstantsToExportButNotGetConstants = [];
const filesExplicitlyNotRequiringMainQueueSetup = [];
tmFiles
.filter((filename) => {
if (filename.includes("microsoft-fork-of-react-native")) {
return false;
}
return /\.mm?$/.test(filename);
})
.map(abspath)
.forEach((filename) => {
const code = readFile(filename);
const relFilename = relpath(filename);
if (!/constantsToExport\s*{/.test(code)) {
filesWithoutConstantsToExport.push(relFilename);
return;
}
if (!/getConstants\s*{/.test(code)) {
filesWithConstantsToExportButNotGetConstants.push(relFilename);
return;
}
if (/requiresMainQueueSetup\s*{/.test(code)) {
const requiresMainQueueSetupRegex = /requiresMainQueueSetup\s*{\s*return\s+(?<requiresMainQueueSetup>YES|NO)/;
const requiresMainQueueSetupRegexMatch = requiresMainQueueSetupRegex.exec(
code
);
if (!requiresMainQueueSetupRegexMatch) {
throw new Error(
"Detected requiresMainQueueSetup method in file " +
relFilename +
" but was unable to parse the method return value"
);
}
const {
requiresMainQueueSetup,
} = requiresMainQueueSetupRegexMatch.groups;
if (requiresMainQueueSetup == "NO") {
filesExplicitlyNotRequiringMainQueueSetup.push(relFilename);
return;
}
}
const getConstantsTypeRegex = () => /-\s*\((?<type>.*)\)getConstants\s*{/;
const getConstantsTypeRegexMatch = getConstantsTypeRegex().exec(code);
if (!getConstantsTypeRegexMatch) {
throw new Error(
`Failed to parse return type of getConstants method in file ${relFilename}`
);
}
const getConstantsType = getConstantsTypeRegexMatch.groups.type;
const getConstantsBody = code
.split(getConstantsTypeRegex())[2]
.split("\n}")[0];
const newGetConstantsBody = `
__block ${getConstantsType} constants;
RCTUnsafeExecuteOnMainQueueSync(^{${getConstantsBody
.replace(/\n/g, "\n ")
.replace(/_bridge/g, "self->_bridge")
.replace(/return /g, "constants = ")}
});
return constants;
`;
writeFile(
filename,
code
.replace(getConstantsBody, newGetConstantsBody)
.replace("#import", "#import <React/RCTUtils.h>\n#import")
);
});
console.log("Files without constantsToExport: ");
filesWithoutConstantsToExport.forEach((file) => console.log(file));
console.log();
console.log("Files with constantsToExport but no getConstants: ");
filesWithConstantsToExportButNotGetConstants.forEach((file) =>
console.log(file)
);
console.log();
console.log("Files with requiresMainQueueSetup = NO: ");
filesExplicitlyNotRequiringMainQueueSetup.forEach((file) =>
console.log(file)
);
}
if (!module.parent) {
main();
}
```
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D21797048
fbshipit-source-id: a822a858fecdbe976e6197f8339e509dc7cd917f
2020-06-03 08:58:04 +03:00
|
|
|
// Note:
|
|
|
|
// This prop is deprecated and will be removed in a future release.
|
|
|
|
// Please use this only for a quick and temporary solution.
|
|
|
|
// Use <SafeAreaView> instead.
|
|
|
|
@"isIPhoneX_deprecated" : @(RCTIsIPhoneX()),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return constants;
|
2017-03-18 02:47:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveNewContentSizeMultiplier
|
|
|
|
{
|
2020-12-11 21:39:18 +03:00
|
|
|
RCTModuleRegistry *moduleRegistry = _moduleRegistry;
|
2017-06-21 04:42:46 +03:00
|
|
|
RCTExecuteOnMainQueue(^{
|
2020-03-09 08:58:01 +03:00
|
|
|
// Report the event across the bridge.
|
2017-03-18 02:47:51 +03:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
2020-12-13 05:58:58 +03:00
|
|
|
[[moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"didUpdateDimensions"
|
|
|
|
body:RCTExportedDimensions(moduleRegistry)];
|
2017-03-18 02:47:51 +03:00
|
|
|
#pragma clang diagnostic pop
|
2017-06-21 04:42:46 +03:00
|
|
|
});
|
2017-03-18 02:47:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)interfaceOrientationDidChange
|
|
|
|
{
|
2019-08-22 00:28:16 +03:00
|
|
|
__weak __typeof(self) weakSelf = self;
|
2017-06-21 04:42:46 +03:00
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
[weakSelf _interfaceOrientationDidChange];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_interfaceOrientationDidChange
|
|
|
|
{
|
2017-03-18 02:47:51 +03:00
|
|
|
UIInterfaceOrientation nextOrientation = [RCTSharedApplication() statusBarOrientation];
|
|
|
|
|
|
|
|
// Update when we go from portrait to landscape, or landscape to portrait
|
|
|
|
if ((UIInterfaceOrientationIsPortrait(_currentInterfaceOrientation) &&
|
|
|
|
!UIInterfaceOrientationIsPortrait(nextOrientation)) ||
|
|
|
|
(UIInterfaceOrientationIsLandscape(_currentInterfaceOrientation) &&
|
|
|
|
!UIInterfaceOrientationIsLandscape(nextOrientation))) {
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
2020-12-13 05:58:58 +03:00
|
|
|
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"didUpdateDimensions"
|
|
|
|
body:RCTExportedDimensions(_moduleRegistry)];
|
2017-03-18 02:47:51 +03:00
|
|
|
#pragma clang diagnostic pop
|
2020-03-09 08:58:01 +03:00
|
|
|
}
|
2017-03-18 02:47:51 +03:00
|
|
|
|
|
|
|
_currentInterfaceOrientation = nextOrientation;
|
|
|
|
}
|
|
|
|
|
2019-04-11 00:08:42 +03:00
|
|
|
- (void)interfaceFrameDidChange
|
|
|
|
{
|
2019-08-22 00:28:16 +03:00
|
|
|
__weak __typeof(self) weakSelf = self;
|
2019-04-11 00:08:42 +03:00
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
[weakSelf _interfaceFrameDidChange];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_interfaceFrameDidChange
|
|
|
|
{
|
2020-12-13 05:58:58 +03:00
|
|
|
NSDictionary *nextInterfaceDimensions = RCTExportedDimensions(_moduleRegistry);
|
2019-04-11 00:08:42 +03:00
|
|
|
|
|
|
|
if (!([nextInterfaceDimensions isEqual:_currentInterfaceDimensions])) {
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
2020-12-11 21:39:18 +03:00
|
|
|
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"didUpdateDimensions"
|
|
|
|
body:nextInterfaceDimensions];
|
2019-04-11 00:08:42 +03:00
|
|
|
#pragma clang diagnostic pop
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentInterfaceDimensions = nextInterfaceDimensions;
|
|
|
|
}
|
|
|
|
|
Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams
Summary:
## Summary
Please check out D21035209.
## Changes
- Codemod all ObjC NativeModule `getTurboModuleWithJsInvoker:nativeInvoker:perfLogger` methods to `getTurboModule:(const ObjCTurboModule::Args)`
## Script
```
var withSpaces = (...args) => args.join('\s*')
var regexString = withSpaces(
'-',
'\(',
'std::shared_ptr',
'<',
'(?<turboModuleClass>(facebook::react::|react::|::|)TurboModule)',
'>',
'\)',
'getTurboModuleWithJsInvoker',
':',
'\(',
'std::shared_ptr',
'<',
'(?<fbNamespace>(facebook::react::|react::|::|))CallInvoker',
'>',
'\)',
'(?<jsInvokerInstance>[A-Za-z0-9]+)',
'nativeInvoker',
':',
'\(',
'std::shared_ptr',
'<',
'(facebook::react::|react::|::|)CallInvoker',
'>',
'\)',
'(?<nativeInvokerInstance>[A-Za-z0-9]+)',
'perfLogger',
':',
'\(',
'id',
'<',
'RCTTurboModulePerformanceLogger',
'>',
'\)',
'(?<perfLoggerInstance>[A-Za-z0-9]+)',
'{',
'return',
'std::make_shared',
'<',
'(?<specName>(facebook::react::|react::|::|)Native[%A-Za-z0-9]+SpecJSI)',
'>',
'\(',
'self',
',',
'\k<jsInvokerInstance>',
',',
'\k<nativeInvokerInstance>',
',',
'\k<perfLoggerInstance>',
'\)',
';',
'}',
)
var replaceString = `- (std::shared_ptr<$<turboModuleClass>>) getTurboModule:(const $<fbNamespace>ObjCTurboModule::InitParams &)params
{
return std::make_shared<$<specName>>(params);
}`
const exec = require('../lib/exec');
const abspath = require('../lib/abspath');
const relpath = require('../lib/relpath');
const readFile = (filename) => require('fs').readFileSync(filename, 'utf8');
const writeFile = (filename, content) => require('fs').writeFileSync(filename, content);
function main() {
const tmFiles = exec('cd ~/fbsource && xbgs -n 10000 -l getTurboModuleWithJsInvoker:').split('\n').filter(Boolean);
tmFiles
.filter((filename) => !filename.includes('microsoft-fork-of-react-native'))
.map(abspath)
.forEach((filename) => {
const source = readFile(filename);
const newSource = source.replace(new RegExp(regexString, 'g'), replaceString);
if (source == newSource) {
console.log(relpath(filename));
}
writeFile(filename, newSource);
});
}
if (!module.parent) {
main();
}
```
## Re-generating diff
```
> hg revert -r .^ --all
> node index.js # run script
```
Changelog: [iOS][Changed] - Make all ObjC NativeModules create TurboModules using ObjCTurboModule::Args
Reviewed By: PeteTheHeat
Differential Revision: D21036265
fbshipit-source-id: 404bcc548d1775ef23d793527606d02fe384a0a2
2020-04-17 03:23:39 +03:00
|
|
|
- (std::shared_ptr<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params
|
2019-08-22 00:28:16 +03:00
|
|
|
{
|
Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams
Summary:
## Summary
Please check out D21035209.
## Changes
- Codemod all ObjC NativeModule `getTurboModuleWithJsInvoker:nativeInvoker:perfLogger` methods to `getTurboModule:(const ObjCTurboModule::Args)`
## Script
```
var withSpaces = (...args) => args.join('\s*')
var regexString = withSpaces(
'-',
'\(',
'std::shared_ptr',
'<',
'(?<turboModuleClass>(facebook::react::|react::|::|)TurboModule)',
'>',
'\)',
'getTurboModuleWithJsInvoker',
':',
'\(',
'std::shared_ptr',
'<',
'(?<fbNamespace>(facebook::react::|react::|::|))CallInvoker',
'>',
'\)',
'(?<jsInvokerInstance>[A-Za-z0-9]+)',
'nativeInvoker',
':',
'\(',
'std::shared_ptr',
'<',
'(facebook::react::|react::|::|)CallInvoker',
'>',
'\)',
'(?<nativeInvokerInstance>[A-Za-z0-9]+)',
'perfLogger',
':',
'\(',
'id',
'<',
'RCTTurboModulePerformanceLogger',
'>',
'\)',
'(?<perfLoggerInstance>[A-Za-z0-9]+)',
'{',
'return',
'std::make_shared',
'<',
'(?<specName>(facebook::react::|react::|::|)Native[%A-Za-z0-9]+SpecJSI)',
'>',
'\(',
'self',
',',
'\k<jsInvokerInstance>',
',',
'\k<nativeInvokerInstance>',
',',
'\k<perfLoggerInstance>',
'\)',
';',
'}',
)
var replaceString = `- (std::shared_ptr<$<turboModuleClass>>) getTurboModule:(const $<fbNamespace>ObjCTurboModule::InitParams &)params
{
return std::make_shared<$<specName>>(params);
}`
const exec = require('../lib/exec');
const abspath = require('../lib/abspath');
const relpath = require('../lib/relpath');
const readFile = (filename) => require('fs').readFileSync(filename, 'utf8');
const writeFile = (filename, content) => require('fs').writeFileSync(filename, content);
function main() {
const tmFiles = exec('cd ~/fbsource && xbgs -n 10000 -l getTurboModuleWithJsInvoker:').split('\n').filter(Boolean);
tmFiles
.filter((filename) => !filename.includes('microsoft-fork-of-react-native'))
.map(abspath)
.forEach((filename) => {
const source = readFile(filename);
const newSource = source.replace(new RegExp(regexString, 'g'), replaceString);
if (source == newSource) {
console.log(relpath(filename));
}
writeFile(filename, newSource);
});
}
if (!module.parent) {
main();
}
```
## Re-generating diff
```
> hg revert -r .^ --all
> node index.js # run script
```
Changelog: [iOS][Changed] - Make all ObjC NativeModules create TurboModules using ObjCTurboModule::Args
Reviewed By: PeteTheHeat
Differential Revision: D21036265
fbshipit-source-id: 404bcc548d1775ef23d793527606d02fe384a0a2
2020-04-17 03:23:39 +03:00
|
|
|
return std::make_shared<NativeDeviceInfoSpecJSI>(params);
|
2019-08-22 00:28:16 +03:00
|
|
|
}
|
2017-03-18 02:47:51 +03:00
|
|
|
|
|
|
|
@end
|
2019-08-22 00:28:16 +03:00
|
|
|
|
2020-03-09 08:58:01 +03:00
|
|
|
Class RCTDeviceInfoCls(void)
|
|
|
|
{
|
2019-08-22 00:28:16 +03:00
|
|
|
return RCTDeviceInfo.class;
|
|
|
|
}
|