Skip to content

Commit

Permalink
Merge branch 'facebook-main' into core-ios-dynamic-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Gleitman committed Oct 27, 2022
2 parents 2393f04 + 6a43faf commit 355c7d2
Show file tree
Hide file tree
Showing 33 changed files with 596 additions and 1,086 deletions.
35 changes: 18 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,11 @@ jobs:
description: The Android build type. Must be one of "Debug", "Release".
type: enum
enum: ["Debug", "Release"]
newarchitecture:
type: boolean
default: false
architecture:
default: "OldArch"
description: Which React Native architecture to use. Must be one of "NewArch", "OldArch".
type: enum
enum: [ "NewArch", "OldArch" ]
jsengine:
default: "Hermes"
description: Which JavaScript engine to use. Must be one of "Hermes", "JSC".
Expand All @@ -775,17 +777,6 @@ jobs:
- run_yarn
- attach_workspace:
at: .
- when:
condition:
equal: ["JSC", << parameters.jsengine >>]
steps:
- run:
name: Set enableHermes in buld.gradle to false
command: |
node ./scripts/set-rn-engine.js -e jsc
echo "Hermes disabled."
grep enableHermes: template/android/app/build.gradle
- run:
name: Create Android template project
command: |
Expand All @@ -796,10 +787,20 @@ jobs:
yarn
- run:
name: Build the template application for << parameters.flavor >> with New Architecture set to << parameters.newarchitecture >>, and using the << parameters.jsengine>> JS engine.
name: Build the template application for << parameters.flavor >> with Architecture set to << parameters.architecture >>, and using the << parameters.jsengine>> JS engine.
command: |
cd /tmp/$PROJECT_NAME/android/
./gradlew assemble<< parameters.flavor >> -PnewArchEnabled=<< parameters.newarchitecture >> -PREACT_NATIVE_MAVEN_LOCAL_REPO=/root/react-native/maven-local
if [[ << parameters.architecture >> == "NewArch" ]]; then
export ORG_GRADLE_PROJECT_newArchEnabled=true
else
export ORG_GRADLE_PROJECT_newArchEnabled=false
fi
if [[ << parameters.jsengine >> == "Hermes" ]]; then
export ORG_GRADLE_PROJECT_hermesEnabled=true
else
export ORG_GRADLE_PROJECT_hermesEnabled=false
fi
./gradlew assemble<< parameters.flavor >> -PREACT_NATIVE_MAVEN_LOCAL_REPO=/root/react-native/maven-local
# -------------------------
# JOBS: Test iOS Template
Expand Down Expand Up @@ -1602,7 +1603,7 @@ workflows:
- build_npm_package
matrix:
parameters:
newarchitecture: [true, false]
architecture: ["NewArch", "OldArch"]
jsengine: ["Hermes", "JSC"]
flavor: ["Debug", "Release"]
- test_buck
Expand Down
1 change: 1 addition & 0 deletions BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ rn_library(
"//xplat/js:node_modules__abort_19controller",
"//xplat/js:node_modules__anser",
"//xplat/js:node_modules__base64_19js",
"//xplat/js:node_modules__deprecated_19react_19native_19prop_19types",
"//xplat/js:node_modules__event_19target_19shim",
"//xplat/js:node_modules__invariant",
"//xplat/js:node_modules__memoize_19one",
Expand Down
7 changes: 7 additions & 0 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,13 @@ const ExportedForwardRef: React.AbstractComponent<
);
});

/**
* Switch to `deprecated-react-native-prop-types` for compatibility with future
* releases. This is deprecated and will be removed in the future.
*/
ExportedForwardRef.propTypes =
require('deprecated-react-native-prop-types').TextInputPropTypes;

// $FlowFixMe[prop-missing]
ExportedForwardRef.State = {
currentlyFocusedInput: TextInputState.currentlyFocusedInput,
Expand Down
6 changes: 6 additions & 0 deletions Libraries/Image/Image.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ Image.queryCache = queryCache;
* comment and run Flow. */
Image.resolveAssetSource = resolveAssetSource;

/**
* Switch to `deprecated-react-native-prop-types` for compatibility with future
* releases. This is deprecated and will be removed in the future.
*/
Image.propTypes = require('deprecated-react-native-prop-types').ImagePropTypes;

const styles = StyleSheet.create({
base: {
overflow: 'hidden',
Expand Down
6 changes: 6 additions & 0 deletions Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ Image.queryCache = queryCache;
* delete this comment and run Flow. */
Image.resolveAssetSource = resolveAssetSource;

/**
* Switch to `deprecated-react-native-prop-types` for compatibility with future
* releases. This is deprecated and will be removed in the future.
*/
Image.propTypes = require('deprecated-react-native-prop-types').ImagePropTypes;

const styles = StyleSheet.create({
base: {
overflow: 'hidden',
Expand Down
16 changes: 8 additions & 8 deletions Libraries/LogBox/LogBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,16 @@ if (__DEV__) {
if (LogBoxData.isLogBoxErrorMessage(String(args[0]))) {
originalConsoleError(...args);
return;
} else {
// Be sure to pass LogBox warnings through.
originalConsoleWarn(...args);
}

try {
if (!isRCTLogAdviceWarning(...args)) {
const {category, message, componentStack} = parseLogBoxLog(args);

if (!LogBoxData.isMessageIgnored(message.content)) {
// Be sure to pass LogBox warnings through.
originalConsoleWarn(...args);

LogBoxData.addLog({
level: 'warn',
category,
Expand Down Expand Up @@ -205,12 +205,12 @@ if (__DEV__) {
args[0] = `Warning: ${filterResult.finalFormat}`;
const {category, message, componentStack} = parseLogBoxLog(args);

if (!LogBoxData.isMessageIgnored(message.content)) {
// Interpolate the message so they are formatted for adb and other CLIs.
// This is different than the message.content above because it includes component stacks.
const interpolated = parseInterpolation(args);
originalConsoleError(interpolated.message.content);
// Interpolate the message so they are formatted for adb and other CLIs.
// This is different than the message.content above because it includes component stacks.
const interpolated = parseInterpolation(args);
originalConsoleError(interpolated.message.content);

if (!LogBoxData.isMessageIgnored(message.content)) {
LogBoxData.addLog({
level,
category,
Expand Down
6 changes: 6 additions & 0 deletions Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ const Text: React.AbstractComponent<

Text.displayName = 'Text';

/**
* Switch to `deprecated-react-native-prop-types` for compatibility with future
* releases. This is deprecated and will be removed in the future.
*/
Text.propTypes = require('deprecated-react-native-prop-types').TextPropTypes;

/**
* Returns false until the first time `newValue` is true, after which this will
* always return true. This is necessary to lazily initialize `Pressability` so
Expand Down
18 changes: 16 additions & 2 deletions Libraries/Utilities/HMRClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,23 @@ Error: ${e.message}`;
}
});

client.on('close', data => {
client.on('close', closeEvent => {
LoadingView.hide();
setHMRUnavailableReason('Disconnected from Metro.');

// https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1
// https://www.rfc-editor.org/rfc/rfc6455.html#section-7.1.5
const isNormalOrUnsetCloseReason =
closeEvent.code === 1000 ||
closeEvent.code === 1005 ||
closeEvent.code == null;

if (isNormalOrUnsetCloseReason) {
setHMRUnavailableReason('Disconnected from Metro.');
} else {
setHMRUnavailableReason(
`Disconnected from Metro (${closeEvent.code}: "${closeEvent.reason}").`,
);
}
});

if (isEnabled) {
Expand Down
9 changes: 8 additions & 1 deletion Libraries/WebSocket/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const CLOSED = 3;

const CLOSE_NORMAL = 1000;

// Abnormal closure where no code is provided in a control frame
// https://www.rfc-editor.org/rfc/rfc6455.html#section-7.1.5
const CLOSE_ABNORMAL = 1006;

const WEBSOCKET_EVENTS = ['close', 'error', 'message', 'open'];

let nextWebSocketId = 0;
Expand Down Expand Up @@ -260,6 +264,7 @@ class WebSocket extends (EventTarget(...WEBSOCKET_EVENTS): any) {
new WebSocketEvent('close', {
code: ev.code,
reason: ev.reason,
// TODO: missing `wasClean` (exposed on iOS as `clean` but missing on Android)
}),
);
this._unregisterEvents();
Expand All @@ -277,7 +282,9 @@ class WebSocket extends (EventTarget(...WEBSOCKET_EVENTS): any) {
);
this.dispatchEvent(
new WebSocketEvent('close', {
message: ev.message,
code: CLOSE_ABNORMAL,
reason: ev.message,
// TODO: Expose `wasClean`
}),
);
this._unregisterEvents();
Expand Down
1 change: 1 addition & 0 deletions React/CoreModules/CoreModulesPlugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Class RCTWebSocketModuleCls(void) __attribute__((used));
Class RCTDevLoadingViewCls(void) __attribute__((used));
Class RCTDevSplitBundleLoaderCls(void) __attribute__((used));
Class RCTEventDispatcherCls(void) __attribute__((used));
Class RCTBlobManagerCls(void) __attribute__((used));

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions React/CoreModules/CoreModulesPlugins.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Class RCTCoreModulesClassProvider(const char *name) {
{"PerfMonitor", RCTPerfMonitorCls},
{"DevMenu", RCTDevMenuCls},
{"DevSettings", RCTDevSettingsCls},
{"BlobModule", RCTBlobManagerCls},
{"RedBox", RCTRedBoxCls},
{"LogBox", RCTLogBoxCls},
{"WebSocketExecutor", RCTWebSocketExecutorCls},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react;

/**
* An enum that specifies the algorithm to use when loading theJS Engine. {@link #JSC} will load
* JavaScriptCore first and fail if it is not available. {@link #HERMES} will load Hermes first and
* fail if it is not available.
*/
public enum JSEngineResolutionAlgorithm {
JSC,
HERMES
}
18 changes: 0 additions & 18 deletions ReactAndroid/src/main/java/com/facebook/react/JSInterpreter.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.app.Application;
import android.content.Context;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.hermes.reactexecutor.HermesExecutor;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.infer.annotation.Assertions;
Expand All @@ -40,6 +41,8 @@
/** Builder class for {@link ReactInstanceManager} */
public class ReactInstanceManagerBuilder {

private static final String TAG = ReactInstanceManagerBuilder.class.getSimpleName();

private final List<ReactPackage> mPackages = new ArrayList<>();

private @Nullable String mJSBundleAssetUrl;
Expand All @@ -64,7 +67,7 @@ public class ReactInstanceManagerBuilder {
private @Nullable Map<String, RequestHandler> mCustomPackagerCommandHandlers;
private @Nullable ReactPackageTurboModuleManagerDelegate.Builder mTMMDelegateBuilder;
private @Nullable SurfaceDelegateFactory mSurfaceDelegateFactory;
private JSInterpreter jsInterpreter = JSInterpreter.OLD_LOGIC;
private JSEngineResolutionAlgorithm jsEngineResolutionAlgorithm = null;

/* package protected */ ReactInstanceManagerBuilder() {}

Expand Down Expand Up @@ -118,28 +121,12 @@ public ReactInstanceManagerBuilder setJSBundleLoader(JSBundleLoader jsBundleLoad
}

/**
* Sets the jsEngine as JSC or HERMES as per the setJsEngineAsHermes call Uses the enum {@link
* JSInterpreter}
*
* @param jsInterpreter
*/
private void setJSEngine(JSInterpreter jsInterpreter) {
this.jsInterpreter = jsInterpreter;
}

/**
* Utility setter to set the required JSEngine as HERMES or JSC Defaults to OLD_LOGIC if not
* called by the host app
*
* @param hermesEnabled hermesEnabled = true sets the JS Engine as HERMES and JSC otherwise
* Sets the JS Engine to load as either Hermes or JSC. If not set, the default is JSC with a
* Hermes fallback.
*/
public ReactInstanceManagerBuilder setJsEngineAsHermes(boolean hermesEnabled) {
if (hermesEnabled) {
setJSEngine(JSInterpreter.HERMES);
} else {
setJSEngine(JSInterpreter.JSC);
}
return this;
private void setJSEngineResolutionAlgorithm(
@Nullable JSEngineResolutionAlgorithm jsEngineResolutionAlgorithm) {
this.jsEngineResolutionAlgorithm = jsEngineResolutionAlgorithm;
}

/**
Expand Down Expand Up @@ -365,7 +352,11 @@ private JavaScriptExecutorFactory getDefaultJSExecutorFactory(

// if nothing is specified, use old loading method
// else load the required engine
if (jsInterpreter == JSInterpreter.OLD_LOGIC) {
if (jsEngineResolutionAlgorithm == null) {
FLog.w(
TAG,
"You're not setting the JS Engine Resolution Algorithm. "
+ "We'll try to load JSC first, and if it fails we'll fallback to Hermes");
try {
// If JSC is included, use it as normal
initializeSoLoaderIfNecessary(applicationContext);
Expand All @@ -378,7 +369,7 @@ private JavaScriptExecutorFactory getDefaultJSExecutorFactory(
HermesExecutor.loadLibrary();
return new HermesExecutorFactory();
}
} else if (jsInterpreter == JSInterpreter.HERMES) {
} else if (jsEngineResolutionAlgorithm == JSEngineResolutionAlgorithm.HERMES) {
HermesExecutor.loadLibrary();
return new HermesExecutorFactory();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,12 @@ protected String getJSMainModuleName() {
* default ones, you'll want to include more packages here.
*/
protected abstract List<ReactPackage> getPackages();

/**
* Returns the {@link JSEngineResolutionAlgorithm} to be used when loading the JS engine. If null,
* will try to load JSC first and fallback to Hermes if JSC is not available.
*/
protected @Nullable JSEngineResolutionAlgorithm getJSEngineResolutionAlgorithm() {
return null;
}
}
Loading

0 comments on commit 355c7d2

Please sign in to comment.