From 4841e1bae068a1742cd195fa9fbf4b67531fd344 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Wed, 25 Aug 2021 02:19:40 -0700 Subject: [PATCH 001/986] Add first-class support to ReactInstanceManager for Activity-less usage Summary: I'm not sure if we'll ever need to do more than this (probably!) but I want to have a specific option for Activity-less usage, so that our logic in ReactInstanceManager and elsewhere is more clear. I want to be able to confidently assert that the Activity is present and correct, or never present, depending on if this `requireActivity` flag is set; instead of adding else statements that imply "well, the Activity should be here, hope everything is okay" which feels hacky. Doesn't change much for now, but it's an additional constraint in the RN Android codebase that we need to explicitly embed in code so that we can point to it, and so that the logic is more clear. Changelog: [Internal] Reviewed By: javache, motiz88 Differential Revision: D30504616 fbshipit-source-id: d2abdb7c4765a16113c9517406cdbb8cf42822ff --- .../facebook/react/ReactInstanceManager.java | 42 ++++++++++++------- .../react/ReactInstanceManagerBuilder.java | 12 ++++++ .../com/facebook/react/ReactNativeHost.java | 6 +++ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 3792fe60c963..9980ff8c1c67 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -156,12 +156,14 @@ public interface ReactInstanceEventListener { /* accessed from any thread */ private final JavaScriptExecutorFactory mJavaScriptExecutorFactory; + // See {@code ReactInstanceManagerBuilder} for description of all flags here. private @Nullable List mViewManagerNames = null; private final @Nullable JSBundleLoader mBundleLoader; private final @Nullable String mJSMainModulePath; /* path to JS bundle root on Metro */ private final List mPackages; private final DevSupportManager mDevSupportManager; private final boolean mUseDeveloperSupport; + private final boolean mRequireActivity; private @Nullable ComponentNameResolverManager mComponentNameResolverManager; private @Nullable RuntimeSchedulerManager mRuntimeSchedulerManager; private final @Nullable NotThreadSafeBridgeIdleDebugListener mBridgeIdleDebugListener; @@ -216,6 +218,7 @@ public static ReactInstanceManagerBuilder builder() { @Nullable String jsMainModulePath, List packages, boolean useDeveloperSupport, + boolean requireActivity, @Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener, LifecycleState initialLifecycleState, @Nullable UIImplementationProvider mUIImplementationProvider, @@ -233,6 +236,7 @@ public static ReactInstanceManagerBuilder builder() { DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(applicationContext); + // See {@code ReactInstanceManagerBuilder} for description of all flags here. mApplicationContext = applicationContext; mCurrentActivity = currentActivity; mDefaultBackButtonImpl = defaultHardwareBackBtnHandler; @@ -241,6 +245,7 @@ public static ReactInstanceManagerBuilder builder() { mJSMainModulePath = jsMainModulePath; mPackages = new ArrayList<>(); mUseDeveloperSupport = useDeveloperSupport; + mRequireActivity = requireActivity; Systrace.beginSection( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstanceManager.initDevSupportManager"); mDevSupportManager = @@ -558,16 +563,20 @@ public void onHostPause() { * @param activity the activity being paused */ @ThreadConfined(UI) - public void onHostPause(Activity activity) { - Assertions.assertNotNull(mCurrentActivity); - Assertions.assertCondition( - activity == mCurrentActivity, - "Pausing an activity that is not the current activity, this is incorrect! " - + "Current activity: " - + mCurrentActivity.getClass().getSimpleName() - + " " - + "Paused activity: " - + activity.getClass().getSimpleName()); + public void onHostPause(@Nullable Activity activity) { + if (mRequireActivity) { + Assertions.assertCondition(mCurrentActivity != null); + } + if (mCurrentActivity != null) { + Assertions.assertCondition( + activity == mCurrentActivity, + "Pausing an activity that is not the current activity, this is incorrect! " + + "Current activity: " + + mCurrentActivity.getClass().getSimpleName() + + " " + + "Paused activity: " + + activity.getClass().getSimpleName()); + } onHostPause(); } @@ -583,7 +592,8 @@ public void onHostPause(Activity activity) { * this instance of {@link ReactInstanceManager}. */ @ThreadConfined(UI) - public void onHostResume(Activity activity, DefaultHardwareBackBtnHandler defaultBackButtonImpl) { + public void onHostResume( + @Nullable Activity activity, DefaultHardwareBackBtnHandler defaultBackButtonImpl) { UiThreadUtil.assertOnUiThread(); mDefaultBackButtonImpl = defaultBackButtonImpl; @@ -592,7 +602,7 @@ public void onHostResume(Activity activity, DefaultHardwareBackBtnHandler defaul /** Use this method when the activity resumes. */ @ThreadConfined(UI) - public void onHostResume(Activity activity) { + public void onHostResume(@Nullable Activity activity) { UiThreadUtil.assertOnUiThread(); mCurrentActivity = activity; @@ -631,8 +641,8 @@ public void onViewDetachedFromWindow(View v) { // activity is attached to window, we can enable dev support immediately mDevSupportManager.setDevSupportEnabled(true); } - } else { - // there is no activity, we can enable dev support + } else if (!mRequireActivity) { + // there is no activity, but we can enable dev support mDevSupportManager.setDevSupportEnabled(true); } } @@ -666,7 +676,9 @@ public void onHostDestroy() { * @param activity the activity being destroyed */ @ThreadConfined(UI) - public void onHostDestroy(Activity activity) { + public void onHostDestroy(@Nullable Activity activity) { + // In some cases, Activity may (correctly) be null. + // See mRequireActivity flag. if (activity == mCurrentActivity) { onHostDestroy(); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java index c06f71b9a594..36f700e49763 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java @@ -45,6 +45,7 @@ public class ReactInstanceManagerBuilder { private @Nullable NotThreadSafeBridgeIdleDebugListener mBridgeIdleDebugListener; private @Nullable Application mApplication; private boolean mUseDeveloperSupport; + private boolean mRequireActivity; private @Nullable LifecycleState mInitialLifecycleState; private @Nullable UIImplementationProvider mUIImplementationProvider; private @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler; @@ -171,6 +172,16 @@ public ReactInstanceManagerBuilder setUseDeveloperSupport(boolean useDeveloperSu return this; } + /** + * When {@code false}, indicates that correct usage of React Native will NOT involve an Activity. + * For the vast majority of Android apps in the ecosystem, this will not need to change. Unless + * you really know what you're doing, you should probably not change this! + */ + public ReactInstanceManagerBuilder setRequireActivity(boolean requireActivity) { + mRequireActivity = requireActivity; + return this; + } + /** * Sets the initial lifecycle state of the host. For example, if the host is already resumed at * creation time, we wouldn't expect an onResume call until we get an onPause call. @@ -283,6 +294,7 @@ public ReactInstanceManager build() { mJSMainModulePath, mPackages, mUseDeveloperSupport, + mRequireActivity, mBridgeIdleDebugListener, Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"), mUIImplementationProvider, diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactNativeHost.java b/ReactAndroid/src/main/java/com/facebook/react/ReactNativeHost.java index d4c457ff87de..dc313d33bc0f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactNativeHost.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactNativeHost.java @@ -68,6 +68,7 @@ protected ReactInstanceManager createReactInstanceManager() { .setApplication(mApplication) .setJSMainModulePath(getJSMainModuleName()) .setUseDeveloperSupport(getUseDeveloperSupport()) + .setRequireActivity(getShouldRequireActivity()) .setRedBoxHandler(getRedBoxHandler()) .setJavaScriptExecutorFactory(getJavaScriptExecutorFactory()) .setUIImplementationProvider(getUIImplementationProvider()) @@ -124,6 +125,11 @@ protected UIImplementationProvider getUIImplementationProvider() { return null; } + /** Returns whether or not to treat it as normal if Activity is null. */ + public boolean getShouldRequireActivity() { + return true; + } + /** * Returns the name of the main module. Determines the URL used to fetch the JS bundle from Metro. * It is only used when dev support is enabled. This is the first file to be executed once the From ee3e71f536127295ba4ea377e618499409a2e9ba Mon Sep 17 00:00:00 2001 From: fabriziobertoglio1987 Date: Wed, 25 Aug 2021 04:55:24 -0700 Subject: [PATCH 002/986] onKeyPress event not fired with numeric keys (#29046) Summary: This issue fixes https://github.com/facebook/react-native/issues/19507 fixes https://github.com/facebook/react-native/issues/30475 onKeyPress event not fired for numeric keyboard The TextInput onKeyPress event is not fired when pressing numeric keys on Android. The method sendKeyEvent will dispatchKeyEvent only for: - ENTER_KEY_VALUE - KEYCODE_DEL (delete key) The solution proposed is trigger dispatchKeyEvent for KeyEvents with event.getUnicodeChar() value included between 47 and 58 (numeric keys 0-9) ## Changelog [Android] [Fixed] - onKeyPress event not fired with numeric keys Pull Request resolved: https://github.com/facebook/react-native/pull/29046 Test Plan: **
CLICK TO OPEN TESTS RESULTS**

| **BEFORE** | **AFTER** | |:-------------------------:|:-------------------------:| | | |

Reviewed By: hramos, cortinico Differential Revision: D30427789 Pulled By: sshic fbshipit-source-id: b4e17ab94daa59fe28de5a5141b0fdd49bab72e3 --- .../views/textinput/ReactEditTextInputConnectionWrapper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java index 55ae040054b9..aa2f9a6462e5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java @@ -131,10 +131,13 @@ public boolean deleteSurroundingText(int beforeLength, int afterLength) { @Override public boolean sendKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { + boolean isNumberKey = event.getUnicodeChar() < 58 && event.getUnicodeChar() > 47; if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) { dispatchKeyEvent(BACKSPACE_KEY_VALUE); } else if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { dispatchKeyEvent(ENTER_KEY_VALUE); + } else if (isNumberKey) { + dispatchKeyEvent(String.valueOf(event.getNumber())); } } return super.sendKeyEvent(event); From 1a42bd6e97ae44a3b38ca552865bac63a6f35da5 Mon Sep 17 00:00:00 2001 From: Jimmy Zhang Date: Wed, 25 Aug 2021 05:09:10 -0700 Subject: [PATCH 003/986] Add UIAccessibilityTraitUpdatesFrequently to progressBar role Summary: Changelog: Add UIAccessibilityTraitUpdatesFrequently when the AccessibilityRole is set to progressBar. This trait tells the accessibility system where content may change with every percentage point, but without annoying the user with constant announcements. Reviewed By: ikenwoo Differential Revision: D30510587 fbshipit-source-id: e75690a2a56ce42476dc999383cf58c0811fcbdf --- React/Views/RCTViewManager.m | 5 +++-- .../renderer/components/view/accessibilityPropsConversions.h | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index e1218914e8d6..72e195c556b9 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -51,7 +51,7 @@ @implementation RCTConvert (UIAccessibilityTraits) @"menu" : @(UIAccessibilityTraitNone), @"menubar" : @(UIAccessibilityTraitNone), @"menuitem" : @(UIAccessibilityTraitNone), - @"progressbar" : @(UIAccessibilityTraitNone), + @"progressbar" : @(UIAccessibilityTraitUpdatesFrequently), @"radio" : @(UIAccessibilityTraitNone), @"radiogroup" : @(UIAccessibilityTraitNone), @"scrollbar" : @(UIAccessibilityTraitNone), @@ -172,7 +172,8 @@ - (RCTShadowView *)shadowView const UIAccessibilityTraits AccessibilityRolesMask = UIAccessibilityTraitNone | UIAccessibilityTraitButton | UIAccessibilityTraitLink | UIAccessibilityTraitSearchField | UIAccessibilityTraitImage | UIAccessibilityTraitKeyboardKey | UIAccessibilityTraitStaticText | UIAccessibilityTraitAdjustable | - UIAccessibilityTraitHeader | UIAccessibilityTraitSummaryElement | SwitchAccessibilityTrait; + UIAccessibilityTraitHeader | UIAccessibilityTraitSummaryElement | UIAccessibilityTraitTabBar | + UIAccessibilityTraitUpdatesFrequently | SwitchAccessibilityTrait; view.reactAccessibilityElement.accessibilityTraits = view.reactAccessibilityElement.accessibilityTraits & ~AccessibilityRolesMask; UIAccessibilityTraits newTraits = json ? [RCTConvert UIAccessibilityTraits:json] : defaultView.accessibilityTraits; diff --git a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h index d06ee6546d96..92c52527cd55 100644 --- a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h +++ b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h @@ -98,6 +98,10 @@ inline void fromString(const std::string &string, AccessibilityTraits &result) { result = AccessibilityTraits::TabBar; return; } + if (string == "progressbar") { + result = AccessibilityTraits::UpdatesFrequently; + return; + } result = AccessibilityTraits::None; } From 2550948ec6fa480e4e483f997e91d691ea5f5cee Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Wed, 25 Aug 2021 12:12:45 -0700 Subject: [PATCH 004/986] Bump @react-native/polyfills version (#32074) Summary: https://github.com/facebook/react-native/commit/8a62583f794875e6dc5d1e4a24889b3b702d9f86 did some renaming inside of the react-native/polyfills project, with the jest preset updated to use the new name. The new package for polyfills has not yet been published, so the jest preset in the main branch will be looking for the new name, while the old name is provided by the currently published react-native/polyfills@1.0.0. This is not hit inside the repo, since the dependency is linked instead of using the published one. Bump react-native/polyfills to 2.0 (breaking change), in preparation for publish. ## Changelog [Internal][Fixed] - Bump react-native/polyfills version Pull Request resolved: https://github.com/facebook/react-native/pull/32074 Reviewed By: lunaleaps, cortinico Differential Revision: D30498104 Pulled By: yungsters fbshipit-source-id: 92dcb159d76bd74cd93cfa09e2155c9c1b2c0a86 --- package.json | 2 +- packages/polyfills/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bf5c11886011..773a915a7985 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,7 @@ "@react-native-community/cli-platform-ios": "^6.0.0", "@react-native/assets": "1.0.0", "@react-native/normalize-color": "1.0.0", - "@react-native/polyfills": "1.0.0", + "@react-native/polyfills": "2.0.0", "abort-controller": "^3.0.0", "anser": "^1.4.9", "base64-js": "^1.1.2", diff --git a/packages/polyfills/package.json b/packages/polyfills/package.json index 6f00c64c7fca..58a2b3a70494 100644 --- a/packages/polyfills/package.json +++ b/packages/polyfills/package.json @@ -1,6 +1,6 @@ { "name": "@react-native/polyfills", - "version": "1.0.0", + "version": "2.0.0", "description": "Polyfills for React Native.", "repository": { "type": "git", From 2bcc6fac3844f0752bc7067517c92a643679575e Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Wed, 25 Aug 2021 12:45:10 -0700 Subject: [PATCH 005/986] feat: add Android 12 BLUETOOTH_ADVERTISE to PermissionsAndroid (#32079) Summary: This PR adds BLUETOOTH_ADVERTISE, which showed up in the latest Android 12 Beta build as new `dangerous` permissions requiring approval for them. https://developer.android.com/reference/android/Manifest.permission.html#BLUETOOTH_ADVERTISE You can see the new set of `SCAN/ADVERTISE/CONNECT` added in this doc - https://developer.android.com/about/versions/12/features/bluetooth-permissions, previously SCAN/CONNECT were added in: https://github.com/facebook/react-native/pull/31488 ## Changelog [Android] [Changed] - Add BLUETOOTH_ADVERTISE to PermissionsAndroid Pull Request resolved: https://github.com/facebook/react-native/pull/32079 Test Plan: ``` PermissionsAndroid.BLUETOOTH_ADVERTISE === 'android.permission.BLUETOOTH_ADVERTISE' ``` Reviewed By: cortinico Differential Revision: D30532656 Pulled By: yungsters fbshipit-source-id: 986ad8cbfc27913df13ab24bba36f6e13104e7d9 --- Libraries/PermissionsAndroid/NativePermissionsAndroid.js | 3 ++- Libraries/PermissionsAndroid/PermissionsAndroid.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/PermissionsAndroid/NativePermissionsAndroid.js b/Libraries/PermissionsAndroid/NativePermissionsAndroid.js index 64d55e5f3342..358882c8ec48 100644 --- a/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +++ b/Libraries/PermissionsAndroid/NativePermissionsAndroid.js @@ -43,7 +43,8 @@ export type PermissionType = | 'android.permission.READ_EXTERNAL_STORAGE' | 'android.permission.WRITE_EXTERNAL_STORAGE' | 'android.permission.BLUETOOTH_CONNECT' - | 'android.permission.BLUETOOTH_SCAN'; + | 'android.permission.BLUETOOTH_SCAN' + | 'android.permission.BLUETOOTH_ADVERTISE'; */ export interface Spec extends TurboModule { diff --git a/Libraries/PermissionsAndroid/PermissionsAndroid.js b/Libraries/PermissionsAndroid/PermissionsAndroid.js index c538dfd80354..1006cd319245 100644 --- a/Libraries/PermissionsAndroid/PermissionsAndroid.js +++ b/Libraries/PermissionsAndroid/PermissionsAndroid.js @@ -61,6 +61,7 @@ const PERMISSIONS = Object.freeze({ WRITE_EXTERNAL_STORAGE: 'android.permission.WRITE_EXTERNAL_STORAGE', BLUETOOTH_CONNECT: 'android.permission.BLUETOOTH_CONNECT', BLUETOOTH_SCAN: 'android.permission.BLUETOOTH_SCAN', + BLUETOOTH_ADVERTISE: 'android.permission.BLUETOOTH_ADVERTISE', }); /** @@ -75,6 +76,7 @@ class PermissionsAndroid { ACCESS_COARSE_LOCATION: string, ACCESS_FINE_LOCATION: string, ADD_VOICEMAIL: string, + BLUETOOTH_ADVERTISE: string, BLUETOOTH_CONNECT: string, BLUETOOTH_SCAN: string, BODY_SENSORS: string, From 8c4912a42f0dcab709c1843e6e63308729295d4b Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Wed, 25 Aug 2021 13:07:31 -0700 Subject: [PATCH 006/986] Fabric should be enabled or disabled app-wide without entrypoint-specific options Summary: Add new ReactFeatureFlag to enable or disable Fabric appwide. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D30504714 fbshipit-source-id: f615d4c888a89f5401b0ff8f8305fdfbdf75fba3 --- .../java/com/facebook/react/config/ReactFeatureFlags.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java index 8513e6c0ccd4..077eb5fd7b26 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -25,6 +25,12 @@ public class ReactFeatureFlags { */ public static volatile boolean useTurboModules = false; + /** + * Should this application use the new (Fabric) Renderer? If yes, all rendering in this app will + * use Fabric instead of the legacy renderer. + */ + public static volatile boolean enableFabricRenderer = false; + /** * After TurboModules and Fabric are enabled, we need to ensure that the legacy NativeModule isn't * isn't used. So, turn this flag on to trigger warnings whenever the legacy NativeModule system From 2fb102b601a929be74eb9042745a1bb63ed7bc6a Mon Sep 17 00:00:00 2001 From: alessandro Date: Wed, 25 Aug 2021 13:07:41 -0700 Subject: [PATCH 007/986] refactor: remove DefeaultProps from the DatePickerIOS component (#32064) Summary: Closes issue https://github.com/facebook/react-native/issues/31605. This is part of a bigger issue that plans to remove defaultProps from class components in order to provide a smoother transition to functional components. ## Changelog [General] [Changed] - Remove defaultProps from the DatePickerIOS Component. [General] [Test] - Added snapshot test for the new component Pull Request resolved: https://github.com/facebook/react-native/pull/32064 Test Plan: Compiled the rn-tester folder to check if the behavior is consistent with the previous versions. Reviewed By: lunaleaps Differential Revision: D30492515 Pulled By: yungsters fbshipit-source-id: ed2c5f3211742d528ff3f8e406a53cd7ea43d7e7 --- .../DatePicker/DatePickerIOS.ios.js | 9 ++-- .../__tests__/DatePickerIOS-test.js | 14 ++++++ .../__snapshots__/DatePickerIOS-test.js.snap | 48 +++++++++++++++++++ 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/Libraries/Components/DatePicker/DatePickerIOS.ios.js b/Libraries/Components/DatePicker/DatePickerIOS.ios.js index 30cc13ad55f0..8295e3aeded2 100644 --- a/Libraries/Components/DatePicker/DatePickerIOS.ios.js +++ b/Libraries/Components/DatePicker/DatePickerIOS.ios.js @@ -117,10 +117,6 @@ type Props = $ReadOnly<{| * source of truth. */ class DatePickerIOS extends React.Component { - static DefaultProps: {|mode: $TEMPORARY$string<'datetime'>|} = { - mode: 'datetime', - }; - _picker: ?React.ElementRef = null; componentDidUpdate() { @@ -142,6 +138,7 @@ class DatePickerIOS extends React.Component { render(): React.Node { const props = this.props; + const mode = props.mode ?? 'datetime'; invariant( props.date || props.initialDate, 'A selected date or initial date should be specified.', @@ -153,7 +150,7 @@ class DatePickerIOS extends React.Component { ref={picker => { this._picker = picker; }} - style={getHeight(props.pickerStyle, props.mode)} + style={getHeight(props.pickerStyle, mode)} date={ props.date ? props.date.getTime() @@ -172,7 +169,7 @@ class DatePickerIOS extends React.Component { minimumDate={ props.minimumDate ? props.minimumDate.getTime() : undefined } - mode={props.mode} + mode={mode} minuteInterval={props.minuteInterval} timeZoneOffsetInMinutes={props.timeZoneOffsetInMinutes} onChange={this._onChange} diff --git a/Libraries/Components/DatePicker/__tests__/DatePickerIOS-test.js b/Libraries/Components/DatePicker/__tests__/DatePickerIOS-test.js index bcc029c47684..79579b82ee59 100644 --- a/Libraries/Components/DatePicker/__tests__/DatePickerIOS-test.js +++ b/Libraries/Components/DatePicker/__tests__/DatePickerIOS-test.js @@ -32,4 +32,18 @@ describe('DatePickerIOS', () => { }, ); }); + it('should render DatePicker with the datetime mode if no mode is passed inside the props', () => { + ReactNativeTestTools.expectRendersMatchingSnapshot( + 'DatePickerIOS', + () => ( + + ), + () => { + jest.dontMock('../DatePickerIOS'); + }, + ); + }); }); diff --git a/Libraries/Components/DatePicker/__tests__/__snapshots__/DatePickerIOS-test.js.snap b/Libraries/Components/DatePicker/__tests__/__snapshots__/DatePickerIOS-test.js.snap index e463f9819141..55ce6c206714 100644 --- a/Libraries/Components/DatePicker/__tests__/__snapshots__/DatePickerIOS-test.js.snap +++ b/Libraries/Components/DatePicker/__tests__/__snapshots__/DatePickerIOS-test.js.snap @@ -1,5 +1,53 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`DatePickerIOS should render DatePicker with the datetime mode if no mode is passed inside the props: should deep render when mocked (please verify output manually) 1`] = ` + + + +`; + +exports[`DatePickerIOS should render DatePicker with the datetime mode if no mode is passed inside the props: should deep render when not mocked (please verify output manually) 1`] = ` + + + +`; + +exports[`DatePickerIOS should render DatePicker with the datetime mode if no mode is passed inside the props: should shallow render as when mocked 1`] = ` + +`; + +exports[`DatePickerIOS should render DatePicker with the datetime mode if no mode is passed inside the props: should shallow render as when not mocked 1`] = ` + +`; + exports[`DatePickerIOS should render as expected: should deep render when mocked (please verify output manually) 1`] = ` Date: Wed, 25 Aug 2021 13:23:40 -0700 Subject: [PATCH 008/986] Compare strings by value instead of reference Summary: LLD, our new iOS linker, is an ongoing effort to migrate our old outdated ld64 linker. As part of our effort to rollout LLD to all apps, we are making sure LLD reaches parity with ld64. Due to Identical Code Folding (ICF), LLD and ld64 handles strings differently. LLD treats each string as a separate object in memory even if the values of the strings are the same. ld64 happens to aggregate these values across files. This behavior creates a subtle difference on our codebase when we start comparing by value or by reference. `char * ` fields from `RawPropsKey.h` are using `==` which compares by its address. Here, we cast the buffer to a string to make the comparison, while avoiding the cast if one happens to be null. Changelog: [Internal] Reviewed By: int3, JoshuaGross Differential Revision: D30444176 fbshipit-source-id: 74216926803adbece05206ddd8478cc3c8e6812e --- ReactCommon/react/renderer/core/RawPropsKey.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ReactCommon/react/renderer/core/RawPropsKey.cpp b/ReactCommon/react/renderer/core/RawPropsKey.cpp index cdaab91f7d5e..35c8283f5e24 100644 --- a/ReactCommon/react/renderer/core/RawPropsKey.cpp +++ b/ReactCommon/react/renderer/core/RawPropsKey.cpp @@ -51,10 +51,18 @@ RawPropsKey::operator std::string() const noexcept { return std::string{buffer, length}; } +static bool areFieldsEqual(char const *lhs, char const *rhs) { + if (lhs == nullptr || rhs == nullptr) { + return lhs == rhs; + } + return std::string(lhs) == std::string(rhs); +} + bool operator==(RawPropsKey const &lhs, RawPropsKey const &rhs) noexcept { // Note: We check the name first. - return lhs.name == rhs.name && lhs.prefix == rhs.prefix && - lhs.suffix == rhs.suffix; + return areFieldsEqual(lhs.name, rhs.name) && + areFieldsEqual(lhs.prefix, rhs.prefix) && + areFieldsEqual(lhs.suffix, rhs.suffix); } bool operator!=(RawPropsKey const &lhs, RawPropsKey const &rhs) noexcept { From 7a770526c626e6659a12939f8c61057a688aa623 Mon Sep 17 00:00:00 2001 From: Andres Riveros Moya Date: Wed, 25 Aug 2021 13:36:23 -0700 Subject: [PATCH 009/986] Remove DatePickerAndroid from react-native-github Summary: Changelog: [JavaScript][Removed] - Remove DatePickerAndroid from React Native Reviewed By: lunaleaps, yungsters Differential Revision: D30281952 fbshipit-source-id: 5cd0ad2ad741afeef3e6f8a39635c6baf4b79b38 --- .../DatePickerAndroid.android.js | 87 --------- .../DatePickerAndroid.ios.js | 30 --- .../DatePickerAndroidTypes.js | 30 --- .../java/com/facebook/react/tests/BUCK | 1 - .../react/tests/DatePickerDialogTestCase.java | 172 ------------------ .../js/DatePickerDialogTestModule.js | 45 ----- ReactAndroid/src/androidTest/js/TestBundle.js | 7 - .../facebook/react/modules/datepicker/BUCK | 27 --- .../datepicker/DatePickerDialogFragment.java | 137 -------------- .../datepicker/DatePickerDialogModule.java | 153 ---------------- .../modules/datepicker/DatePickerMode.java | 15 -- .../DismissableDatePickerDialog.java | 117 ------------ .../main/java/com/facebook/react/shell/BUCK | 1 - .../react/shell/MainReactPackage.java | 5 - index.js | 25 ++- 15 files changed, 15 insertions(+), 837 deletions(-) delete mode 100644 Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js delete mode 100644 Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js delete mode 100644 Libraries/Components/DatePickerAndroid/DatePickerAndroidTypes.js delete mode 100644 ReactAndroid/src/androidTest/java/com/facebook/react/tests/DatePickerDialogTestCase.java delete mode 100644 ReactAndroid/src/androidTest/js/DatePickerDialogTestModule.js delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/BUCK delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogFragment.java delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogModule.java delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerMode.java delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DismissableDatePickerDialog.java diff --git a/Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js b/Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js deleted file mode 100644 index 9f29433e1e18..000000000000 --- a/Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow strict-local - */ - -import type {Options, DatePickerOpenAction} from './DatePickerAndroidTypes'; -import NativeDatePickerAndroid from './NativeDatePickerAndroid'; - -/** - * Convert a Date to a timestamp. - */ -function _toMillis(options: Options, key: string) { - const dateVal = options[key]; - // Is it a Date object? - if (typeof dateVal === 'object' && typeof dateVal.getMonth === 'function') { - options[key] = dateVal.getTime(); - } -} - -/** - * Opens the standard Android date picker dialog. - * - * ### Example - * - * ``` - * try { - * const {action, year, month, day} = await DatePickerAndroid.open({ - * // Use `new Date()` for current date. - * // May 25 2020. Month 0 is January. - * date: new Date(2020, 4, 25) - * }); - * if (action !== DatePickerAndroid.dismissedAction) { - * // Selected year, month (0-11), day - * } - * } catch ({code, message}) { - * console.warn('Cannot open date picker', message); - * } - * ``` - */ -class DatePickerAndroid { - /** - * Opens the standard Android date picker dialog. - * - * The available keys for the `options` object are: - * - * - `date` (`Date` object or timestamp in milliseconds) - date to show by default - * - `minDate` (`Date` or timestamp in milliseconds) - minimum date that can be selected - * - `maxDate` (`Date` object or timestamp in milliseconds) - maximum date that can be selected - * - `mode` (`enum('calendar', 'spinner', 'default')`) - To set the date-picker mode to calendar/spinner/default - * - 'calendar': Show a date picker in calendar mode. - * - 'spinner': Show a date picker in spinner mode. - * - 'default': Show a default native date picker(spinner/calendar) based on android versions. - * - * Returns a Promise which will be invoked an object containing `action`, `year`, `month` (0-11), - * `day` if the user picked a date. If the user dismissed the dialog, the Promise will - * still be resolved with action being `DatePickerAndroid.dismissedAction` and all the other keys - * being undefined. **Always** check whether the `action` before reading the values. - * - * Note the native date picker dialog has some UI glitches on Android 4 and lower - * when using the `minDate` and `maxDate` options. - */ - static async open(options: ?Options): Promise { - const optionsMs = options; - if (optionsMs != null) { - _toMillis(optionsMs, 'date'); - _toMillis(optionsMs, 'minDate'); - _toMillis(optionsMs, 'maxDate'); - } - return NativeDatePickerAndroid.open(options); - } - - /** - * A date has been selected. - */ - static +dateSetAction: 'dateSetAction' = 'dateSetAction'; - /** - * The dialog has been dismissed. - */ - static +dismissedAction: 'dismissedAction' = 'dismissedAction'; -} - -module.exports = DatePickerAndroid; diff --git a/Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js b/Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js deleted file mode 100644 index d16cb2bf6105..000000000000 --- a/Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow strict-local - */ - -'use strict'; - -import type {Options, DatePickerOpenAction} from './DatePickerAndroidTypes'; - -class DatePickerAndroid { - static async open(options: ?Options): Promise { - throw new Error('DatePickerAndroid is not supported on this platform.'); - } - - /** - * A date has been selected. - */ - static +dateSetAction: 'dateSetAction' = 'dateSetAction'; - /** - * The dialog has been dismissed. - */ - static +dismissedAction: 'dismissedAction' = 'dismissedAction'; -} - -module.exports = DatePickerAndroid; diff --git a/Libraries/Components/DatePickerAndroid/DatePickerAndroidTypes.js b/Libraries/Components/DatePickerAndroid/DatePickerAndroidTypes.js deleted file mode 100644 index 096d7b5e8d9a..000000000000 --- a/Libraries/Components/DatePickerAndroid/DatePickerAndroidTypes.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow strict-local - */ - -export type Options = $ReadOnly<{| - date?: ?(Date | number), - minDate?: ?(Date | number), - maxDate?: ?(Date | number), - mode?: ?('calendar' | 'spinner' | 'default'), -|}>; - -export type DatePickerOpenAction = - | {| - action: 'dateSetAction', - year: number, - month: number, - day: number, - |} - | {| - action: 'dismissedAction', - year: void, - month: void, - day: void, - |}; diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK index 451cd7413b96..131dd4af63c3 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/BUCK @@ -25,7 +25,6 @@ rn_android_library( react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/modules/appstate:appstate"), react_native_target("java/com/facebook/react/modules/core:core"), - react_native_target("java/com/facebook/react/modules/datepicker:datepicker"), react_native_target("java/com/facebook/react/modules/deviceinfo:deviceinfo"), react_native_target("java/com/facebook/react/modules/share:share"), react_native_target("java/com/facebook/react/modules/systeminfo:systeminfo"), diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/DatePickerDialogTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/DatePickerDialogTestCase.java deleted file mode 100644 index 93d3568fa24e..000000000000 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/DatePickerDialogTestCase.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its 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.tests; - -import android.app.DatePickerDialog; -import android.content.DialogInterface; -import android.widget.DatePicker; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.Fragment; -import com.facebook.react.bridge.BaseJavaModule; -import com.facebook.react.bridge.JavaScriptModule; -import com.facebook.react.bridge.ReactMethod; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.bridge.WritableNativeMap; -import com.facebook.react.modules.datepicker.DatePickerDialogModule; -import com.facebook.react.testing.ReactAppInstrumentationTestCase; -import com.facebook.react.testing.ReactInstanceSpecForTest; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - -/** Test case for {@link DatePickerDialogModule} options and callbacks. */ -public class DatePickerDialogTestCase extends ReactAppInstrumentationTestCase { - - private static interface DatePickerDialogTestModule extends JavaScriptModule { - public void showDatePickerDialog(WritableMap options); - } - - private static class DatePickerDialogRecordingModule extends BaseJavaModule { - - private final List mDates = new ArrayList(); - private int mDismissed = 0; - private int mErrors = 0; - - @Override - public String getName() { - return "DatePickerDialogRecordingModule"; - } - - @ReactMethod - public void recordDate(int year, int month, int day) { - mDates.add(new Integer[] {year, month, day}); - } - - @ReactMethod - public void recordDismissed() { - mDismissed++; - } - - @ReactMethod - public void recordError() { - mErrors++; - } - - public List getDates() { - return new ArrayList(mDates); - } - - public int getDismissed() { - return mDismissed; - } - - public int getErrors() { - return mErrors; - } - } - - final DatePickerDialogRecordingModule mRecordingModule = new DatePickerDialogRecordingModule(); - - @Override - protected ReactInstanceSpecForTest createReactInstanceSpecForTest() { - return super.createReactInstanceSpecForTest().addNativeModule(mRecordingModule); - } - - @Override - protected String getReactApplicationKeyUnderTest() { - return "DatePickerDialogTestApp"; - } - - private static long getDateInMillis(int year, int month, int date) { - final Calendar c = Calendar.getInstance(); - c.set(Calendar.YEAR, year); - c.set(Calendar.MONTH, month); - c.set(Calendar.DATE, date); - return c.getTimeInMillis(); - } - - private DatePickerDialogTestModule getTestModule() { - return getReactContext().getCatalystInstance().getJSModule(DatePickerDialogTestModule.class); - } - - private DialogFragment showDialog(WritableMap options) { - getTestModule().showDatePickerDialog(options); - - waitForBridgeAndUIIdle(); - getInstrumentation().waitForIdleSync(); - - return (DialogFragment) - getActivity() - .getSupportFragmentManager() - .findFragmentByTag(DatePickerDialogModule.FRAGMENT_TAG); - } - - public void testShowBasicDatePicker() { - final Fragment datePickerFragment = showDialog(null); - - assertNotNull(datePickerFragment); - } - - public void testPresetDate() { - final WritableMap options = new WritableNativeMap(); - options.putDouble("date", getDateInMillis(2020, 5, 6)); - - final DialogFragment datePickerFragment = showDialog(options); - final DatePicker datePicker = - ((DatePickerDialog) datePickerFragment.getDialog()).getDatePicker(); - - assertEquals(2020, datePicker.getYear()); - assertEquals(5, datePicker.getMonth()); - assertEquals(6, datePicker.getDayOfMonth()); - } - - public void testCallback() throws Throwable { - final WritableMap options = new WritableNativeMap(); - options.putDouble("date", getDateInMillis(2020, 5, 6)); - - final DialogFragment datePickerFragment = showDialog(options); - - runTestOnUiThread( - new Runnable() { - @Override - public void run() { - ((DatePickerDialog) datePickerFragment.getDialog()) - .getButton(DialogInterface.BUTTON_POSITIVE) - .performClick(); - } - }); - - getInstrumentation().waitForIdleSync(); - waitForBridgeAndUIIdle(); - - assertEquals(0, mRecordingModule.getErrors()); - assertEquals(1, mRecordingModule.getDates().size()); - assertEquals(2020, (int) mRecordingModule.getDates().get(0)[0]); - assertEquals(5, (int) mRecordingModule.getDates().get(0)[1]); - assertEquals(6, (int) mRecordingModule.getDates().get(0)[2]); - } - - public void testDismissCallback() throws Throwable { - final DialogFragment datePickerFragment = showDialog(null); - - runTestOnUiThread( - new Runnable() { - @Override - public void run() { - datePickerFragment.getDialog().dismiss(); - } - }); - - getInstrumentation().waitForIdleSync(); - waitForBridgeAndUIIdle(); - - assertEquals(0, mRecordingModule.getErrors()); - assertEquals(0, mRecordingModule.getDates().size()); - assertEquals(1, mRecordingModule.getDismissed()); - } -} diff --git a/ReactAndroid/src/androidTest/js/DatePickerDialogTestModule.js b/ReactAndroid/src/androidTest/js/DatePickerDialogTestModule.js deleted file mode 100644 index 5c23e61a5ec5..000000000000 --- a/ReactAndroid/src/androidTest/js/DatePickerDialogTestModule.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -'use strict'; - -const React = require('react'); -const {DatePickerAndroid, NativeModules, View} = require('react-native'); -const BatchedBridge = require('react-native/Libraries/BatchedBridge/BatchedBridge'); - -const {DatePickerDialogRecordingModule: RecordingModule} = NativeModules; - -class DatePickerDialogTestApp extends React.Component { - render() { - return ; - } -} - -const DatePickerDialogTestModule = { - DatePickerDialogTestApp: DatePickerDialogTestApp, - showDatePickerDialog: function(options) { - DatePickerAndroid.open(options).then( - ({action, year, month, day}) => { - if (action === DatePickerAndroid.dateSetAction) { - RecordingModule.recordDate(year, month, day); - } else if (action === DatePickerAndroid.dismissedAction) { - RecordingModule.recordDismissed(); - } - }, - ({code, message}) => RecordingModule.recordError(), - ); - }, -}; - -BatchedBridge.registerCallableModule( - 'DatePickerDialogTestModule', - DatePickerDialogTestModule, -); - -module.exports = DatePickerDialogTestModule; diff --git a/ReactAndroid/src/androidTest/js/TestBundle.js b/ReactAndroid/src/androidTest/js/TestBundle.js index 709f469b118d..b81937503589 100644 --- a/ReactAndroid/src/androidTest/js/TestBundle.js +++ b/ReactAndroid/src/androidTest/js/TestBundle.js @@ -20,9 +20,7 @@ require('./TestJSLocaleModule'); require('./TestJSToJavaParametersModule'); require('./TestJavaToJSReturnValuesModule'); require('./UIManagerTestModule'); - require('./CatalystRootViewTestModule'); -require('./DatePickerDialogTestModule'); require('./MeasureLayoutTestModule'); require('./ScrollViewTestModule'); require('./ShareTestModule'); @@ -43,11 +41,6 @@ const apps = [ component: () => require('./CatalystRootViewTestModule').CatalystRootViewTestApp, }, - { - appKey: 'DatePickerDialogTestApp', - component: () => - require('./DatePickerDialogTestModule').DatePickerDialogTestApp, - }, { appKey: 'JSResponderTestApp', component: () => require('./JSResponderTestApp'), diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/BUCK b/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/BUCK deleted file mode 100644 index 80a1af4bb9ac..000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/BUCK +++ /dev/null @@ -1,27 +0,0 @@ -load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_root_target", "react_native_target", "rn_android_library") - -rn_android_library( - name = "datepicker", - srcs = glob(["**/*.java"]), - autoglob = False, - is_androidx = True, - labels = ["supermodule:xplat/default/public.react_native.infra"], - provided_deps = [ - react_native_dep("third-party/android/androidx:annotation"), - react_native_dep("third-party/android/androidx:core"), - react_native_dep("third-party/android/androidx:fragment"), - react_native_dep("third-party/android/androidx:legacy-support-core-ui"), - react_native_dep("third-party/android/androidx:legacy-support-core-utils"), - ], - visibility = [ - "PUBLIC", - ], - deps = [ - react_native_dep("third-party/java/infer-annotations:infer-annotations"), - react_native_dep("third-party/java/jsr-305:jsr-305"), - react_native_target("java/com/facebook/react/bridge:bridge"), - react_native_target("java/com/facebook/react/common:common"), - react_native_target("java/com/facebook/react/module/annotations:annotations"), - ], - exported_deps = [react_native_root_target(":FBReactNativeSpec")], -) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogFragment.java b/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogFragment.java deleted file mode 100644 index f3d190b4432e..000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogFragment.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its 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.modules.datepicker; - -import android.annotation.SuppressLint; -import android.app.DatePickerDialog; -import android.app.DatePickerDialog.OnDateSetListener; -import android.app.Dialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnDismissListener; -import android.graphics.drawable.ColorDrawable; -import android.os.Bundle; -import android.widget.DatePicker; -import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; -import java.util.Calendar; -import java.util.Locale; - -@SuppressLint("ValidFragment") -public class DatePickerDialogFragment extends DialogFragment { - - /** Minimum date supported by {@link DatePicker}, 01 Jan 1900 */ - private static final long DEFAULT_MIN_DATE = -2208988800001l; - - @Nullable private OnDateSetListener mOnDateSetListener; - @Nullable private OnDismissListener mOnDismissListener; - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - Bundle args = getArguments(); - return createDialog(args, getActivity(), mOnDateSetListener); - } - - /*package*/ static Dialog createDialog( - Bundle args, Context activityContext, @Nullable OnDateSetListener onDateSetListener) { - final Calendar c = Calendar.getInstance(); - if (args != null && args.containsKey(DatePickerDialogModule.ARG_DATE)) { - c.setTimeInMillis(args.getLong(DatePickerDialogModule.ARG_DATE)); - } - final int year = c.get(Calendar.YEAR); - final int month = c.get(Calendar.MONTH); - final int day = c.get(Calendar.DAY_OF_MONTH); - - DatePickerMode mode = DatePickerMode.DEFAULT; - if (args != null && args.getString(DatePickerDialogModule.ARG_MODE, null) != null) { - mode = - DatePickerMode.valueOf( - args.getString(DatePickerDialogModule.ARG_MODE).toUpperCase(Locale.US)); - } - - DatePickerDialog dialog = null; - - switch (mode) { - case CALENDAR: - dialog = - new DismissableDatePickerDialog( - activityContext, - activityContext - .getResources() - .getIdentifier( - "CalendarDatePickerDialog", "style", activityContext.getPackageName()), - onDateSetListener, - year, - month, - day); - break; - case SPINNER: - dialog = - new DismissableDatePickerDialog( - activityContext, - android.R.style.Theme_Holo_Light_Dialog, - onDateSetListener, - year, - month, - day); - dialog - .getWindow() - .setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); - break; - case DEFAULT: - dialog = - new DismissableDatePickerDialog(activityContext, onDateSetListener, year, month, day); - break; - } - - final DatePicker datePicker = dialog.getDatePicker(); - - if (args != null && args.containsKey(DatePickerDialogModule.ARG_MINDATE)) { - // Set minDate to the beginning of the day. We need this because of clowniness in datepicker - // that causes it to throw an exception if minDate is greater than the internal timestamp - // that it generates from the y/m/d passed in the constructor. - c.setTimeInMillis(args.getLong(DatePickerDialogModule.ARG_MINDATE)); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - c.set(Calendar.MILLISECOND, 0); - datePicker.setMinDate(c.getTimeInMillis()); - } else { - // This is to work around a bug in DatePickerDialog where it doesn't display a title showing - // the date under certain conditions. - datePicker.setMinDate(DEFAULT_MIN_DATE); - } - if (args != null && args.containsKey(DatePickerDialogModule.ARG_MAXDATE)) { - // Set maxDate to the end of the day, same reason as for minDate. - c.setTimeInMillis(args.getLong(DatePickerDialogModule.ARG_MAXDATE)); - c.set(Calendar.HOUR_OF_DAY, 23); - c.set(Calendar.MINUTE, 59); - c.set(Calendar.SECOND, 59); - c.set(Calendar.MILLISECOND, 999); - datePicker.setMaxDate(c.getTimeInMillis()); - } - - return dialog; - } - - @Override - public void onDismiss(DialogInterface dialog) { - super.onDismiss(dialog); - if (mOnDismissListener != null) { - mOnDismissListener.onDismiss(dialog); - } - } - - /*package*/ void setOnDateSetListener(@Nullable OnDateSetListener onDateSetListener) { - mOnDateSetListener = onDateSetListener; - } - - /*package*/ void setOnDismissListener(@Nullable OnDismissListener onDismissListener) { - mOnDismissListener = onDismissListener; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogModule.java deleted file mode 100644 index e69714648892..000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogModule.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its 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.modules.datepicker; - -import android.app.Activity; -import android.app.DatePickerDialog.OnDateSetListener; -import android.content.DialogInterface; -import android.content.DialogInterface.OnDismissListener; -import android.os.Bundle; -import android.widget.DatePicker; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.FragmentActivity; -import androidx.fragment.app.FragmentManager; -import com.facebook.fbreact.specs.NativeDatePickerAndroidSpec; -import com.facebook.react.bridge.*; -import com.facebook.react.common.annotations.VisibleForTesting; -import com.facebook.react.module.annotations.ReactModule; - -/** - * {@link NativeModule} that allows JS to show a native date picker dialog and get called back when - * the user selects a date. - */ -@ReactModule(name = DatePickerDialogModule.FRAGMENT_TAG) -public class DatePickerDialogModule extends NativeDatePickerAndroidSpec { - - @VisibleForTesting public static final String FRAGMENT_TAG = "DatePickerAndroid"; - - private static final String ERROR_NO_ACTIVITY = "E_NO_ACTIVITY"; - - /* package */ static final String ARG_DATE = "date"; - /* package */ static final String ARG_MINDATE = "minDate"; - /* package */ static final String ARG_MAXDATE = "maxDate"; - /* package */ static final String ARG_MODE = "mode"; - - /* package */ static final String ACTION_DATE_SET = "dateSetAction"; - /* package */ static final String ACTION_DISMISSED = "dismissedAction"; - - public DatePickerDialogModule(ReactApplicationContext reactContext) { - super(reactContext); - } - - public @NonNull String getName() { - return DatePickerDialogModule.FRAGMENT_TAG; - } - - private class DatePickerDialogListener implements OnDateSetListener, OnDismissListener { - - private final Promise mPromise; - private boolean mPromiseResolved = false; - - public DatePickerDialogListener(final Promise promise) { - mPromise = promise; - } - - @Override - public void onDateSet(DatePicker view, int year, int month, int day) { - if (!mPromiseResolved && getReactApplicationContext().hasActiveReactInstance()) { - WritableMap result = new WritableNativeMap(); - result.putString("action", ACTION_DATE_SET); - result.putInt("year", year); - result.putInt("month", month); - result.putInt("day", day); - mPromise.resolve(result); - mPromiseResolved = true; - } - } - - @Override - public void onDismiss(DialogInterface dialog) { - if (!mPromiseResolved && getReactApplicationContext().hasActiveReactInstance()) { - WritableMap result = new WritableNativeMap(); - result.putString("action", ACTION_DISMISSED); - mPromise.resolve(result); - mPromiseResolved = true; - } - } - } - - /** - * Show a date picker dialog. - * - * @param options a map containing options. Available keys are: - *
    - *
  • {@code date} (timestamp in milliseconds) the date to show by default - *
  • {@code minDate} (timestamp in milliseconds) the minimum date the user should be - * allowed to select - *
  • {@code maxDate} (timestamp in milliseconds) the maximum date the user should be - * allowed to select - *
  • {@code mode} To set the date picker mode to 'calendar/spinner/default' - *
- * - * @param promise This will be invoked with parameters action, year, month (0-11), day, where - * action is {@code dateSetAction} or {@code dismissedAction}, depending on what the user did. - * If the action is dismiss, year, month and date are undefined. - */ - @Override - public void open(@Nullable final ReadableMap options, final Promise promise) { - Activity raw_activity = getCurrentActivity(); - if (raw_activity == null || !(raw_activity instanceof FragmentActivity)) { - promise.reject( - ERROR_NO_ACTIVITY, - "Tried to open a DatePicker dialog while not attached to a FragmentActivity"); - return; - } - - FragmentActivity activity = (FragmentActivity) raw_activity; - - final FragmentManager fragmentManager = activity.getSupportFragmentManager(); - DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG); - if (oldFragment != null) { - oldFragment.dismiss(); - } - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - DatePickerDialogFragment fragment = new DatePickerDialogFragment(); - if (options != null) { - final Bundle args = createFragmentArguments(options); - fragment.setArguments(args); - } - final DatePickerDialogListener listener = new DatePickerDialogListener(promise); - fragment.setOnDismissListener(listener); - fragment.setOnDateSetListener(listener); - fragment.show(fragmentManager, FRAGMENT_TAG); - } - }); - } - - private Bundle createFragmentArguments(ReadableMap options) { - final Bundle args = new Bundle(); - if (options.hasKey(ARG_DATE) && !options.isNull(ARG_DATE)) { - args.putLong(ARG_DATE, (long) options.getDouble(ARG_DATE)); - } - if (options.hasKey(ARG_MINDATE) && !options.isNull(ARG_MINDATE)) { - args.putLong(ARG_MINDATE, (long) options.getDouble(ARG_MINDATE)); - } - if (options.hasKey(ARG_MAXDATE) && !options.isNull(ARG_MAXDATE)) { - args.putLong(ARG_MAXDATE, (long) options.getDouble(ARG_MAXDATE)); - } - if (options.hasKey(ARG_MODE) && !options.isNull(ARG_MODE)) { - args.putString(ARG_MODE, options.getString(ARG_MODE)); - } - return args; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerMode.java b/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerMode.java deleted file mode 100644 index 3ed6f114724c..000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerMode.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its 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.modules.datepicker; - -/** Date picker modes */ -public enum DatePickerMode { - CALENDAR, - SPINNER, - DEFAULT -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DismissableDatePickerDialog.java b/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DismissableDatePickerDialog.java deleted file mode 100644 index cfcc1fd3c774..000000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DismissableDatePickerDialog.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its 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.modules.datepicker; - -import android.app.DatePickerDialog; -import android.content.Context; -import android.content.res.TypedArray; -import android.os.Build; -import android.util.AttributeSet; -import android.widget.DatePicker; -import androidx.annotation.Nullable; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -public class DismissableDatePickerDialog extends DatePickerDialog { - - public DismissableDatePickerDialog( - Context context, - @Nullable DatePickerDialog.OnDateSetListener callback, - int year, - int monthOfYear, - int dayOfMonth) { - super(context, callback, year, monthOfYear, dayOfMonth); - fixSpinner(context, year, monthOfYear, dayOfMonth); - } - - public DismissableDatePickerDialog( - Context context, - int theme, - @Nullable DatePickerDialog.OnDateSetListener callback, - int year, - int monthOfYear, - int dayOfMonth) { - super(context, theme, callback, year, monthOfYear, dayOfMonth); - fixSpinner(context, year, monthOfYear, dayOfMonth); - } - - private void fixSpinner(Context context, int year, int month, int dayOfMonth) { - if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) { - try { - // Get the theme's android:datePickerMode - final int MODE_SPINNER = 2; - Class styleableClass = Class.forName("com.android.internal.R$styleable"); - Field datePickerStyleableField = styleableClass.getField("DatePicker"); - int[] datePickerStyleable = (int[]) datePickerStyleableField.get(null); - - final TypedArray a = - context.obtainStyledAttributes( - null, datePickerStyleable, android.R.attr.datePickerStyle, 0); - Field datePickerModeStyleableField = styleableClass.getField("DatePicker_datePickerMode"); - int datePickerModeStyleable = datePickerModeStyleableField.getInt(null); - final int mode = a.getInt(datePickerModeStyleable, MODE_SPINNER); - a.recycle(); - - if (mode == MODE_SPINNER) { - DatePicker datePicker = - (DatePicker) - findField(DatePickerDialog.class, DatePicker.class, "mDatePicker").get(this); - Class delegateClass = Class.forName("android.widget.DatePickerSpinnerDelegate"); - Field delegateField = findField(DatePicker.class, delegateClass, "mDelegate"); - Object delegate = delegateField.get(datePicker); - Class spinnerDelegateClass; - spinnerDelegateClass = Class.forName("android.widget.DatePickerSpinnerDelegate"); - - // In 7.0 Nougat for some reason the datePickerMode is ignored and the delegate is - // DatePickerClockDelegate - if (delegate.getClass() != spinnerDelegateClass) { - delegateField.set(datePicker, null); // throw out the DatePickerClockDelegate! - datePicker.removeAllViews(); // remove the DatePickerClockDelegate views - Method createSpinnerUIDelegate = - DatePicker.class.getDeclaredMethod( - "createSpinnerUIDelegate", - Context.class, - AttributeSet.class, - int.class, - int.class); - createSpinnerUIDelegate.setAccessible(true); - - // Instantiate a DatePickerSpinnerDelegate throughout createSpinnerUIDelegate method - delegate = - createSpinnerUIDelegate.invoke( - datePicker, context, null, android.R.attr.datePickerStyle, 0); - delegateField.set( - datePicker, delegate); // set the DatePicker.mDelegate to the spinner delegate - datePicker.setCalendarViewShown(false); - // Initialize the date for the DatePicker delegate again - datePicker.init(year, month, dayOfMonth, this); - } - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - - private static Field findField(Class objectClass, Class fieldClass, String expectedName) { - try { - Field field = objectClass.getDeclaredField(expectedName); - field.setAccessible(true); - return field; - } catch (NoSuchFieldException e) { - } // ignore - // search for it if it wasn't found under the expected ivar name - for (Field searchField : objectClass.getDeclaredFields()) { - if (searchField.getType() == fieldClass) { - searchField.setAccessible(true); - return searchField; - } - } - return null; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK index a5bb7403e8f6..84138c4394d9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/BUCK @@ -34,7 +34,6 @@ rn_android_library( react_native_target("java/com/facebook/react/modules/camera:camera"), react_native_target("java/com/facebook/react/modules/clipboard:clipboard"), react_native_target("java/com/facebook/react/modules/core:core"), - react_native_target("java/com/facebook/react/modules/datepicker:datepicker"), react_native_target("java/com/facebook/react/modules/debug:debug"), react_native_target("java/com/facebook/react/modules/dialog:dialog"), react_native_target("java/com/facebook/react/modules/fresco:fresco"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java index 0dd8f31c5452..34dc28005784 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java @@ -23,7 +23,6 @@ import com.facebook.react.modules.blob.FileReaderModule; import com.facebook.react.modules.camera.ImageStoreManager; import com.facebook.react.modules.clipboard.ClipboardModule; -import com.facebook.react.modules.datepicker.DatePickerDialogModule; import com.facebook.react.modules.dialog.DialogModule; import com.facebook.react.modules.fresco.FrescoModule; import com.facebook.react.modules.i18nmanager.I18nManagerModule; @@ -72,7 +71,6 @@ FileReaderModule.class, AsyncStorageModule.class, ClipboardModule.class, - DatePickerDialogModule.class, DialogModule.class, FrescoModule.class, I18nManagerModule.class, @@ -117,8 +115,6 @@ public MainReactPackage(MainPackageConfig config) { return new AsyncStorageModule(context); case ClipboardModule.NAME: return new ClipboardModule(context); - case DatePickerDialogModule.FRAGMENT_TAG: - return new DatePickerDialogModule(context); case DialogModule.NAME: return new DialogModule(context); case FrescoModule.NAME: @@ -199,7 +195,6 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() { FileReaderModule.class, AsyncStorageModule.class, ClipboardModule.class, - DatePickerDialogModule.class, DialogModule.class, FrescoModule.class, I18nManagerModule.class, diff --git a/index.js b/index.js index 545554b3b39a..7ce52d8a4603 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,6 @@ import typeof AppState from './Libraries/AppState/AppState'; import typeof AsyncStorage from './Libraries/Storage/AsyncStorage'; import typeof BackHandler from './Libraries/Utilities/BackHandler'; import typeof Clipboard from './Libraries/Components/Clipboard/Clipboard'; -import typeof DatePickerAndroid from './Libraries/Components/DatePickerAndroid/DatePickerAndroid'; import typeof DeviceInfo from './Libraries/Utilities/DeviceInfo'; import typeof DevSettings from './Libraries/Utilities/DevSettings'; import typeof Dimensions from './Libraries/Utilities/Dimensions'; @@ -297,15 +296,6 @@ module.exports = { ); return require('./Libraries/Components/Clipboard/Clipboard'); }, - get DatePickerAndroid(): DatePickerAndroid { - warnOnce( - 'DatePickerAndroid-merged', - 'DatePickerAndroid has been merged with DatePickerIOS and will be removed in a future release. ' + - "It can now be installed and imported from '@react-native-community/datetimepicker' instead of 'react-native'. " + - 'See https://github.com/react-native-datetimepicker/datetimepicker', - ); - return require('./Libraries/Components/DatePickerAndroid/DatePickerAndroid'); - }, get DeviceInfo(): DeviceInfo { return require('./Libraries/Utilities/DeviceInfo'); }, @@ -717,4 +707,19 @@ if (__DEV__) { ); }, }); + /* $FlowFixMe[prop-missing] This is intentional: Flow will error when + * attempting to access DatePickerAndroid. */ + /* $FlowFixMe[invalid-export] This is intentional: Flow will error when + * attempting to access DatePickerAndroid. */ + Object.defineProperty(module.exports, 'DatePickerAndroid', { + configurable: true, + get() { + invariant( + false, + 'DatePickerAndroid has been removed from React Native. ' + + "It can now be installed and imported from '@react-native-community/datetimepicker' instead of 'react-native'. " + + 'See https://github.com/react-native-datetimepicker/datetimepicker', + ); + }, + }); } From 369a7ab5d332be945137aaa487f0c09fc7fa8c57 Mon Sep 17 00:00:00 2001 From: Joshua Selbo Date: Wed, 25 Aug 2021 14:28:56 -0700 Subject: [PATCH 010/986] Update AndroidX test deps to 1.4.0 (#32084) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/32084 Upgrade RN AndroidX test deps after an internal upgrade. Changelog: [Internal] Update AndroidX test deps after internal upgrade Reviewed By: sturmen Differential Revision: D30546422 fbshipit-source-id: 644648c7dcf179e737fb967d996a789cc904a5ca --- .../src/main/third-party/android/androidx/BUCK | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ReactAndroid/src/main/third-party/android/androidx/BUCK b/ReactAndroid/src/main/third-party/android/androidx/BUCK index accceafa0c5c..d8398497d336 100644 --- a/ReactAndroid/src/main/third-party/android/androidx/BUCK +++ b/ReactAndroid/src/main/third-party/android/androidx/BUCK @@ -690,20 +690,20 @@ fb_native.remote_file( fb_native.remote_file( name = "test-monitor-binary-aar", - sha1 = "d2f75d117c055f35c8ebbd4f96fabc2137df9e4d", - url = "mvn:androidx.test:monitor:aar:1.2.0", + sha1 = "4f3c15d0a1e0c943b233b0dc5d8f1e690cfe7c0a", + url = "mvn:androidx.test:monitor:aar:1.4.0", ) fb_native.remote_file( name = "test-rules-binary-aar", - sha1 = "91904046e724ac82d9b7fe698e5fe92b871c726e", - url = "mvn:androidx.test:rules:aar:1.2.0", + sha1 = "0984e8b5505f08489993c783702236af7a4a18c8", + url = "mvn:androidx.test:rules:aar:1.4.0", ) fb_native.remote_file( name = "test-runner-binary-aar", - sha1 = "237b061c45b3b450f88dd8cde87375ab22b0496a", - url = "mvn:androidx.test:runner:aar:1.2.0", + sha1 = "44d79420baf7ac208e33b35df8756f0e912ced38", + url = "mvn:androidx.test:runner:aar:1.4.0", ) fb_native.remote_file( From ee868091b104f4e8744172e45ca01d9b8e60879b Mon Sep 17 00:00:00 2001 From: Xuan Huang Date: Wed, 25 Aug 2021 14:33:00 -0700 Subject: [PATCH 011/986] Add instructions to test RNTester with Hermes on Android (#32085) Summary: Title said it all. ## Changelog [Internal] Pull Request resolved: https://github.com/facebook/react-native/pull/32085 Reviewed By: TheSavior Differential Revision: D30555218 Pulled By: Huxpro fbshipit-source-id: 857ee81d4f402209bb2db2e1f4a2956d46ea3a54 --- packages/rn-tester/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/rn-tester/README.md b/packages/rn-tester/README.md index 3043578eddc1..5f5e1d7c2065 100644 --- a/packages/rn-tester/README.md +++ b/packages/rn-tester/README.md @@ -24,9 +24,12 @@ You'll need to have all the [prerequisites](https://github.com/facebook/react-na Start an Android emulator. - cd react-native - ./gradlew :packages:rn-tester:android:app:installJscDebug - ./scripts/packager.sh +```sh +cd react-native +# In order to use Hermes engine, run `installHermesDebug` instead. +./gradlew :packages:rn-tester:android:app:installJscDebug +./scripts/packager.sh +``` _Note: Building for the first time can take a while._ From 2abacace54dc72bac1a5d7f2fb795edd89374b1c Mon Sep 17 00:00:00 2001 From: Matthew Gray Date: Wed, 25 Aug 2021 16:27:58 -0700 Subject: [PATCH 012/986] Adding Accessibility Display Options Enabled to RNTester (#29231) Summary: Currently there isn't any way to test if the Accessibility Display Options or the event listeners for them were working properly within RNTester. It turns out that because of changes to the accessibility API Apple made when they added Smart Invert AccessibilityInfo.isInvertColorsEnabled() and the associated event listener are working incorrectly. You can see this if you take a look at how RNTester (with this PR incorporated) responds to toggling Invert Colors. I've submitted a bug report to Apple, but this might have been caught earlier if this had been implemented. ## Changelog [General] [Added] - Adding Accessibility Display Options Enabled to RNTester Pull Request resolved: https://github.com/facebook/react-native/pull/29231 Test Plan: 1. Build iOS app 2. Navigate to the Accessibility page 3. Switch over to settings and change any of the settings at - Settings>Accessibility>Display and Text Size>Bold Text - Settings>Accessibility>Display and Text Size>Color Filters>Grayscale - Settings>Accessibility>Display and Text Size>Smart Invert (or Classic Invert) - Settings>Accessibility>Motion>Reduce Motion - Settings>Accessibility>VoiceOver>VoiceOver 4. Switch back to the app and see the results ![Simulator Screen Shot - iPhone 11 - 2020-06-26 at 21 13 16](https://user-images.githubusercontent.com/65255457/85914380-f09c5500-b7f1-11ea-98db-b83fb4ab5305.png) ![Simulator Screen Shot - iPhone 11 - 2020-06-26 at 21 13 39](https://user-images.githubusercontent.com/65255457/85914382-f2feaf00-b7f1-11ea-8ebf-cdb2b703c731.png) Modified it a bit to only show relevant statuses for the Platform | {F656951547} | {F656951643} | Reviewed By: TheSavior Differential Revision: D29531642 Pulled By: lunaleaps fbshipit-source-id: f54fb3216ef663428c23b613f0a3b10b01d7f24d --- .../Accessibility/AccessibilityExample.js | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js index 001464fd63d9..6133080a4adf 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js @@ -1024,6 +1024,72 @@ class EnabledExample extends React.Component< } } +class DisplayOptionsStatusExample extends React.Component<{}> { + render(): React.Node { + const isAndroid = Platform.OS === 'android'; + return ( + + + + {isAndroid ? null : ( + <> + + + + + + )} + + ); + } +} + +function DisplayOptionStatusExample({optionName, optionChecker, notification}) { + const [statusEnabled, setStatusEnabled] = React.useState(false); + React.useEffect(() => { + AccessibilityInfo.addEventListener(notification, setStatusEnabled); + optionChecker().then(isEnabled => { + setStatusEnabled(isEnabled); + }); + return function cleanup() { + AccessibilityInfo.removeEventListener(notification, setStatusEnabled); + }; + }, [optionChecker, notification]); + return ( + + + {optionName} + {' is '} + {statusEnabled ? 'enabled' : 'disabled'}. + + + ); +} + exports.title = 'Accessibility'; exports.documentationURL = 'https://reactnative.dev/docs/accessibilityinfo'; exports.description = 'Examples of using Accessibility APIs.'; @@ -1058,6 +1124,12 @@ exports.examples = [ return ; }, }, + { + title: 'Check if the display options are enabled', + render(): React.Element { + return ; + }, + }, { title: 'Check if the screen reader announces', render(): React.Element { From 8da6964d80ecbdcd2baf1c10db05d67e068d9a49 Mon Sep 17 00:00:00 2001 From: Keion Anvaripour Date: Wed, 25 Aug 2021 16:40:31 -0700 Subject: [PATCH 013/986] Refactor Image to log component stacktraces for images rendering non-fb sources Summary: This diff refactors the Image component in order to log the component hierarchy stacktraces for images rendering non-fb sources Changelog: [Internal] internal Reviewed By: fkgozali Differential Revision: D30504483 fbshipit-source-id: 1e41a67d5b9643730360bce7e787ee3427d931e8 --- Libraries/Image/Image.ios.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Libraries/Image/Image.ios.js b/Libraries/Image/Image.ios.js index 5cadc1db9dcb..3dab5cc8c1f7 100644 --- a/Libraries/Image/Image.ios.js +++ b/Libraries/Image/Image.ios.js @@ -12,6 +12,7 @@ import DeprecatedImagePropType from '../DeprecatedPropTypes/DeprecatedImagePropT import * as React from 'react'; import StyleSheet from '../StyleSheet/StyleSheet'; +import ImageInjection from './ImageInjection'; import ImageAnalyticsTagContext from './ImageAnalyticsTagContext'; import flattenStyle from '../StyleSheet/flattenStyle'; import resolveAssetSource from './resolveAssetSource'; @@ -168,6 +169,11 @@ Image = React.forwardRef< ImagePropsType, React.ElementRef, >(Image); + +if (ImageInjection.unstable_createImageComponent != null) { + Image = ImageInjection.unstable_createImageComponent(Image); +} + Image.displayName = 'Image'; /** From ad9030ca9ae3861d079c16d3ce610edc1bedc54c Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Wed, 25 Aug 2021 16:48:13 -0700 Subject: [PATCH 014/986] Include Swift lib in LIBRARY_SEARCH_PATHS Summary: changelog: Fix Xcode 13 build error in RNTester Including `usr/lib/swift` fixes error: {F642876047} Reviewed By: fkgozali Differential Revision: D30559838 fbshipit-source-id: 65aad16b550d156c8670eaefcc8bedae99606329 --- packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index 334d7ae082ad..d47d63409c25 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -787,6 +787,7 @@ "$(inherited)", "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)", "$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)", + "\"$(SDKROOT)/usr/lib/swift\"", ); "LIBRARY_SEARCH_PATHS[arch=*]" = "$(inherited)"; OTHER_LDFLAGS = ( @@ -821,6 +822,7 @@ "$(inherited)", "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)", "$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)", + "\"$(SDKROOT)/usr/lib/swift\"", ); OTHER_LDFLAGS = ( "$(inherited)", From e60ad0837e16389a5c71b2189360278c2ee9364c Mon Sep 17 00:00:00 2001 From: Xuan Huang Date: Thu, 26 Aug 2021 01:05:06 -0700 Subject: [PATCH 015/986] Type more globals Summary: Changelog: [Internal] This diff add types to some of the common globals so uses of them through `global` are now typed. All the globals are marked as read-only for their intented uses. However, some of them do have write cites (mostly are in tests to deliberately set up a special test environment). Those write cites are considered as "necessary evil" and annotated as `FlowFixMe`. Reviewed By: yungsters Differential Revision: D30158145 fbshipit-source-id: 93a99063361a4b7a1e33d9fc97a661be30a4d8f9 --- Libraries/Animated/NativeAnimatedHelper.js | 2 +- Libraries/Core/ExceptionsManager.js | 4 +- Libraries/Core/setUpBatchedBridge.js | 2 +- Libraries/Core/setUpGlobals.js | 2 + Libraries/Core/setUpTimers.js | 4 +- Libraries/TurboModule/TurboModuleRegistry.js | 2 +- Libraries/Utilities/HMRClient.js | 2 +- Libraries/Utilities/deprecatedPropType.js | 2 +- flow/global.js | 41 ++++++++++++++++++++ 9 files changed, 53 insertions(+), 8 deletions(-) diff --git a/Libraries/Animated/NativeAnimatedHelper.js b/Libraries/Animated/NativeAnimatedHelper.js index 297b53c68c7b..6bac8cb1fbd8 100644 --- a/Libraries/Animated/NativeAnimatedHelper.js +++ b/Libraries/Animated/NativeAnimatedHelper.js @@ -24,7 +24,7 @@ import invariant from 'invariant'; // TODO T69437152 @petetheheat - Delete this fork when Fabric ships to 100%. const NativeAnimatedModule = - Platform.OS === 'ios' && global.RN$Bridgeless + Platform.OS === 'ios' && global.RN$Bridgeless === true ? NativeAnimatedTurboModule : NativeAnimatedNonTurboModule; diff --git a/Libraries/Core/ExceptionsManager.js b/Libraries/Core/ExceptionsManager.js index 6e64a40ad48a..d4826d4b54ab 100644 --- a/Libraries/Core/ExceptionsManager.js +++ b/Libraries/Core/ExceptionsManager.js @@ -76,7 +76,9 @@ function reportException( e.jsEngine == null ? message : `${message}, js engine: ${e.jsEngine}`; const isHandledByLogBox = - e.forceRedbox !== true && !global.RN$Bridgeless && !global.RN$Express; + e.forceRedbox !== true && + global.RN$Bridgeless !== true && + !global.RN$Express; const data = preprocessException({ message, diff --git a/Libraries/Core/setUpBatchedBridge.js b/Libraries/Core/setUpBatchedBridge.js index 49747fd7576c..0f16dd84e74c 100644 --- a/Libraries/Core/setUpBatchedBridge.js +++ b/Libraries/Core/setUpBatchedBridge.js @@ -11,7 +11,7 @@ 'use strict'; let registerModule; -if (global.RN$Bridgeless && global.RN$registerCallableModule) { +if (global.RN$Bridgeless === true && global.RN$registerCallableModule) { registerModule = global.RN$registerCallableModule; } else { const BatchedBridge = require('../BatchedBridge/BatchedBridge'); diff --git a/Libraries/Core/setUpGlobals.js b/Libraries/Core/setUpGlobals.js index ea6da8fbbbe3..a8ce63d13236 100644 --- a/Libraries/Core/setUpGlobals.js +++ b/Libraries/Core/setUpGlobals.js @@ -19,10 +19,12 @@ if (global.GLOBAL === undefined) { } if (global.window === undefined) { + // $FlowFixMe[cannot-write] global.window = global; } if (global.self === undefined) { + // $FlowFixMe[cannot-write] global.self = global; } diff --git a/Libraries/Core/setUpTimers.js b/Libraries/Core/setUpTimers.js index 9d2020f83641..7048b32c4fdf 100644 --- a/Libraries/Core/setUpTimers.js +++ b/Libraries/Core/setUpTimers.js @@ -28,7 +28,7 @@ const hasNativePromise = isNativeFunction(Promise); const hasPromiseQueuedToJSVM = hasNativePromise || hasHermesPromiseQueuedToJSVM; // In bridgeless mode, timers are host functions installed from cpp. -if (!global.RN$Bridgeless) { +if (global.RN$Bridgeless !== true) { /** * Set up timers. * You can use this module directly, or just require InitializeCore. @@ -65,7 +65,7 @@ if (hasPromiseQueuedToJSVM) { // When promise was polyfilled hence is queued to the RN microtask queue, // we polyfill the immediate APIs as aliases to the ReactNativeMicrotask APIs. // Note that in bridgeless mode, immediate APIs are installed from cpp. - if (!global.RN$Bridgeless) { + if (global.RN$Bridgeless !== true) { polyfillGlobal( 'setImmediate', () => require('./Timers/JSTimers').queueReactNativeMicrotask, diff --git a/Libraries/TurboModule/TurboModuleRegistry.js b/Libraries/TurboModule/TurboModuleRegistry.js index 90e30dd08159..9e2f762937cc 100644 --- a/Libraries/TurboModule/TurboModuleRegistry.js +++ b/Libraries/TurboModule/TurboModuleRegistry.js @@ -16,7 +16,7 @@ const turboModuleProxy = global.__turboModuleProxy; function requireModule(name: string): ?T { // Bridgeless mode requires TurboModules - if (!global.RN$Bridgeless) { + if (global.RN$Bridgeless !== true) { // Backward compatibility layer during migration. const legacyModule = NativeModules[name]; if (legacyModule != null) { diff --git a/Libraries/Utilities/HMRClient.js b/Libraries/Utilities/HMRClient.js index 15bd443fd082..e1d8f56c49ab 100644 --- a/Libraries/Utilities/HMRClient.js +++ b/Libraries/Utilities/HMRClient.js @@ -119,7 +119,7 @@ const HMRClient: HMRClientNativeInterface = { JSON.stringify({ type: 'log', level, - mode: global.RN$Bridgeless ? 'NOBRIDGE' : 'BRIDGE', + mode: global.RN$Bridgeless === true ? 'NOBRIDGE' : 'BRIDGE', data: data.map(item => typeof item === 'string' ? item diff --git a/Libraries/Utilities/deprecatedPropType.js b/Libraries/Utilities/deprecatedPropType.js index 454b9bc855e9..1801f98cb1c2 100644 --- a/Libraries/Utilities/deprecatedPropType.js +++ b/Libraries/Utilities/deprecatedPropType.js @@ -20,7 +20,7 @@ function deprecatedPropType( return function validate(props, propName, componentName, ...rest) { // Don't warn for native components. if ( - !global.RN$Bridgeless && + global.RN$Bridgeless !== true && UIManager.hasViewManagerConfig(componentName) && props[propName] !== undefined ) { diff --git a/flow/global.js b/flow/global.js index 3c32ec6796c8..850b53d3db2a 100644 --- a/flow/global.js +++ b/flow/global.js @@ -16,8 +16,49 @@ * writeability (`+`) when defining types. */ declare var global: { + // setUpGlobals + +window: typeof global; + +self: typeof global; + + // setXHR + +XMLHttpRequest: typeof XMLHttpRequest; + +FormData: typeof FormData; + +fetch: typeof fetch; + +Headers: typeof Headers; + +Request: typeof Request; + +Response: typeof Response; + +WebSocket: typeof WebSocket; + +Blob: typeof Blob; + +File: typeof File; + +FileReader: typeof FileReader; + +URL: typeof URL; + +URLSearchParams: typeof URLSearchParams; + +AbortController: typeof AbortController; + +AbortSignal: typeof AbortSignal; + + // setUpAlert + +alert: typeof alert; + + // setUpTimers + +clearInterval: typeof clearInterval, + +clearTimeout: typeof clearTimeout, + +setInterval: typeof setInterval, + +setTimeout: typeof setTimeout, + +requestAnimationFrame: typeof requestAnimationFrame, + +cancelAnimationFrame: typeof cancelAnimationFrame, + +requestIdleCallback: typeof requestIdleCallback, + +cancelIdleCallback: typeof cancelIdleCallback, + +setTimeout: typeof setTimeout, + + +console: typeof console, + + // JavaScript environments specific +HermesInternal: ?$HermesInternalType, + // Internal-specific + +__DEV__?: boolean, + +RN$Bridgeless?: boolean, + // Undeclared properties are implicitly `any`. [string | symbol]: any, }; From a8e2415a9138f9e19f41590ea772a5c27d25746a Mon Sep 17 00:00:00 2001 From: Xuan Huang Date: Thu, 26 Aug 2021 01:05:06 -0700 Subject: [PATCH 016/986] Type global queueMicrotask Summary: Changelog: [Internal] This diff - add `queueMicrotask` to eslint and metro so it's globally available. - add `queueMicrotask` to the global libdef of react native so the type is available to `global.queueMicrotask` (which is common) as well. Reviewed By: yungsters Differential Revision: D30158144 fbshipit-source-id: 00a62193b838745c91179ff1e983636200560690 --- flow/global.js | 4 ++++ packages/eslint-config-react-native-community/index.js | 1 + 2 files changed, 5 insertions(+) diff --git a/flow/global.js b/flow/global.js index 850b53d3db2a..fe06097b0f0e 100644 --- a/flow/global.js +++ b/flow/global.js @@ -49,6 +49,10 @@ declare var global: { +requestIdleCallback: typeof requestIdleCallback, +cancelIdleCallback: typeof cancelIdleCallback, +setTimeout: typeof setTimeout, + // TODO(T97509743): use `typeof` when the next Flow release is available. + +queueMicrotask: >( + jobCallback: (...args: TArguments) => mixed, + ) => void; +console: typeof console, diff --git a/packages/eslint-config-react-native-community/index.js b/packages/eslint-config-react-native-community/index.js index 320ef4daf2b1..be5396609391 100644 --- a/packages/eslint-config-react-native-community/index.js +++ b/packages/eslint-config-react-native-community/index.js @@ -114,6 +114,7 @@ module.exports = { setImmediate: true, setInterval: false, setTimeout: false, + queueMicrotask: true, URL: false, URLSearchParams: false, WebSocket: true, From 4a9621647cde0ba14e7589295c0fbb9dcb300cde Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Thu, 26 Aug 2021 06:55:31 -0700 Subject: [PATCH 017/986] TextTransform prop implemented Summary: Changelog: [iOS] [Fixed] TextTransform is applied when constructing NSAttributedString from C++ AttributedString in Fabric. Reviewed By: sammy-SC Differential Revision: D30515821 fbshipit-source-id: 8a824ff89919832f79ace693dfe3cf7ed35c3beb --- .../platform/ios/RCTAttributedTextUtils.h | 2 ++ .../platform/ios/RCTAttributedTextUtils.mm | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.h b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.h index 373e78daac32..3a8ff540741b 100644 --- a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.h +++ b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.h @@ -35,6 +35,8 @@ NSAttributedString *RCTNSAttributedStringFromAttributedStringBox( facebook::react::AttributedStringBox RCTAttributedStringBoxFromNSAttributedString( NSAttributedString *nsAttributedString); +NSString *RCTNSStringFromStringApplyingTextTransform(NSString *string, facebook::react::TextTransform textTransform); + @interface RCTWeakEventEmitterWrapper : NSObject @property (nonatomic, assign) facebook::react::SharedEventEmitter eventEmitter; @end diff --git a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm index 5df0cd9cad73..7e63b2df90b3 100644 --- a/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm +++ b/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm @@ -335,6 +335,11 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex } else { NSString *string = [NSString stringWithCString:fragment.string.c_str() encoding:NSUTF8StringEncoding]; + if (fragment.textAttributes.textTransform.hasValue()) { + auto textTransform = fragment.textAttributes.textTransform.value(); + string = RCTNSStringFromStringApplyingTextTransform(string, textTransform); + } + nsAttributedStringFragment = [[NSMutableAttributedString alloc] initWithString:string attributes:RCTNSTextAttributesFromTextAttributes(fragment.textAttributes)]; @@ -373,3 +378,17 @@ AttributedStringBox RCTAttributedStringBoxFromNSAttributedString(NSAttributedStr { return nsAttributedString.length ? AttributedStringBox{wrapManagedObject(nsAttributedString)} : AttributedStringBox{}; } + +NSString *RCTNSStringFromStringApplyingTextTransform(NSString *string, TextTransform textTransform) +{ + switch (textTransform) { + case TextTransform::Uppercase: + return [string uppercaseString]; + case TextTransform::Lowercase: + return [string lowercaseString]; + case TextTransform::Capitalize: + return [string capitalizedString]; + default: + return string; + } +} From d6c879edbad068d0f461381875b7fae6db99d18d Mon Sep 17 00:00:00 2001 From: Sota Ogo Date: Thu, 26 Aug 2021 10:04:29 -0700 Subject: [PATCH 018/986] Show RedBox for C++ errors Summary: This diff is hooking up cxx error with redbox. Before this diff, cxx errors were only shown in log and there was no visible user feedback. Changelog: [Android] [Added] - Show Redbox for C++ errors. Reviewed By: JoshuaGross Differential Revision: D30421355 fbshipit-source-id: ad473337ba301feb08ba31ee8d82ebaa771ecaeb --- .../facebook/react/ReactInstanceManager.java | 20 ++++++++++ .../react/bridge/ReactCxxErrorHandler.java | 39 +++++++++++++++++++ .../jni/react/jni/CatalystInstanceImpl.cpp | 2 + .../jni/react/jni/JReactCxxErrorHandler.cpp | 18 +++++++++ .../jni/react/jni/JReactCxxErrorHandler.h | 25 ++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/bridge/ReactCxxErrorHandler.java create mode 100644 ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.cpp create mode 100644 ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.h diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 9980ff8c1c67..d73c8f7e1eca 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -65,6 +65,7 @@ import com.facebook.react.bridge.ProxyJavaScriptExecutor; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; +import com.facebook.react.bridge.ReactCxxErrorHandler; import com.facebook.react.bridge.ReactMarker; import com.facebook.react.bridge.ReactMarkerConstants; import com.facebook.react.bridge.ReactNoCrashSoftException; @@ -107,6 +108,7 @@ import com.facebook.soloader.SoLoader; import com.facebook.systrace.Systrace; import com.facebook.systrace.SystraceMessage; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -291,6 +293,8 @@ public void invokeDefaultOnBackPressed() { if (mUseDeveloperSupport) { mDevSupportManager.startInspector(); } + + registerCxxErrorHandlerFunc(); } private ReactInstanceDevHelper createDevHelperInterface() { @@ -364,6 +368,22 @@ public List getPackages() { return new ArrayList<>(mPackages); } + public void handleCxxError(Exception e) { + mDevSupportManager.handleException(e); + } + + public void registerCxxErrorHandlerFunc() { + Class[] parameterTypes = new Class[1]; + parameterTypes[0] = Exception.class; + Method handleCxxErrorFunc = null; + try { + handleCxxErrorFunc = ReactInstanceManager.class.getMethod("handleCxxError", parameterTypes); + } catch (NoSuchMethodException e) { + FLog.e("ReactInstanceHolder", "Failed to set cxx error hanlder function", e); + } + ReactCxxErrorHandler.setHandleErrorFunc(this, handleCxxErrorFunc); + } + static void initializeSoLoaderIfNecessary(Context applicationContext) { // Call SoLoader.initialize here, this is required for apps that does not use exopackage and // does not use SoLoader for loading other native code except from the one used by React Native diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactCxxErrorHandler.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactCxxErrorHandler.java new file mode 100644 index 000000000000..f5efbf1fadf9 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactCxxErrorHandler.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) Facebook, Inc. and its 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.bridge; + +import com.facebook.common.logging.FLog; +import com.facebook.proguard.annotations.DoNotStrip; +import java.lang.reflect.Method; + +@DoNotStrip +public class ReactCxxErrorHandler { + + private static Method mHandleErrorFunc; + private static Object mObject; + + @DoNotStrip + public static void setHandleErrorFunc(Object object, Method handleErrorFunc) { + mObject = object; + mHandleErrorFunc = handleErrorFunc; + } + + @DoNotStrip + // For use from within the C++ JReactCxxErrorHandler + private static void handleError(final String message) { + if (mHandleErrorFunc != null) { + try { + Object[] parameters = new Object[1]; + parameters[0] = new Exception(message); + mHandleErrorFunc.invoke(mObject, parameters); + } catch (Exception e) { + FLog.e("ReactCxxErrorHandler", "Failed to invole error hanlder function", e); + } + } + } +} diff --git a/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp b/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp index d9e5ac34b411..6b1f09f2720f 100644 --- a/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp +++ b/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp @@ -32,6 +32,7 @@ #include "CxxModuleWrapper.h" #include "JNativeRunnable.h" +#include "JReactCxxErrorHandler.h" #include "JReactSoftExceptionLogger.h" #include "JavaScriptExecutorHolder.h" #include "JniJSModulesUnbundle.h" @@ -155,6 +156,7 @@ void log(ReactNativeLogLevel level, const char *message) { break; case ReactNativeLogLevelError: LOG(ERROR) << message; + JReactCxxErrorHandler::handleError(message); break; case ReactNativeLogLevelFatal: LOG(FATAL) << message; diff --git a/ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.cpp b/ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.cpp new file mode 100644 index 000000000000..5b3409eb1b47 --- /dev/null +++ b/ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "JReactCxxErrorHandler.h" + +using namespace facebook::react; + +void JReactCxxErrorHandler::handleError(std::string message) { + static const auto handleError = + javaClassStatic()->getStaticMethod( + "handleError"); + + return handleError(javaClassStatic(), message); +} diff --git a/ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.h b/ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.h new file mode 100644 index 000000000000..0ed379b9f139 --- /dev/null +++ b/ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +class JReactCxxErrorHandler : public jni::JavaClass { + public: + static constexpr const char *kJavaDescriptor = + "Lcom/facebook/react/bridge/ReactCxxErrorHandler;"; + + static void handleError(std::string message); +}; + +} // namespace react +} // namespace facebook From 8f7e23ae44672f8a227f387c0aa7f00065151415 Mon Sep 17 00:00:00 2001 From: Andrei Shikov Date: Thu, 26 Aug 2021 10:29:25 -0700 Subject: [PATCH 019/986] Update format to fix CircleCI failure (#32095) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/32095 Found by running `yarn run prettier` and including relevant files Changelog: [Internal] Fix formatting of `global.js` Reviewed By: cortinico Differential Revision: D30573273 fbshipit-source-id: 94854d3d3178533ad8a6323006eaca279a931fa7 --- flow/global.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/flow/global.js b/flow/global.js index fe06097b0f0e..b2e76fe8d232 100644 --- a/flow/global.js +++ b/flow/global.js @@ -17,27 +17,27 @@ */ declare var global: { // setUpGlobals - +window: typeof global; - +self: typeof global; + +window: typeof global, + +self: typeof global, // setXHR - +XMLHttpRequest: typeof XMLHttpRequest; - +FormData: typeof FormData; - +fetch: typeof fetch; - +Headers: typeof Headers; - +Request: typeof Request; - +Response: typeof Response; - +WebSocket: typeof WebSocket; - +Blob: typeof Blob; - +File: typeof File; - +FileReader: typeof FileReader; - +URL: typeof URL; - +URLSearchParams: typeof URLSearchParams; - +AbortController: typeof AbortController; - +AbortSignal: typeof AbortSignal; + +XMLHttpRequest: typeof XMLHttpRequest, + +FormData: typeof FormData, + +fetch: typeof fetch, + +Headers: typeof Headers, + +Request: typeof Request, + +Response: typeof Response, + +WebSocket: typeof WebSocket, + +Blob: typeof Blob, + +File: typeof File, + +FileReader: typeof FileReader, + +URL: typeof URL, + +URLSearchParams: typeof URLSearchParams, + +AbortController: typeof AbortController, + +AbortSignal: typeof AbortSignal, // setUpAlert - +alert: typeof alert; + +alert: typeof alert, // setUpTimers +clearInterval: typeof clearInterval, @@ -52,7 +52,7 @@ declare var global: { // TODO(T97509743): use `typeof` when the next Flow release is available. +queueMicrotask: >( jobCallback: (...args: TArguments) => mixed, - ) => void; + ) => void, +console: typeof console, From a0d30b848a07480d0fccec608a62a505c71f8cac Mon Sep 17 00:00:00 2001 From: Genki Kondo Date: Thu, 26 Aug 2021 10:38:36 -0700 Subject: [PATCH 020/986] Remove unsupported values for android_hyphenationFrequency Summary: hyphenationStrategy must be one of one of Layout#HYPHENATION_FREQUENCY_NONE, Layout#HYPHENATION_FREQUENCY_NORMAL, Layout#HYPHENATION_FREQUENCY_FULL: (https://developer.android.com/reference/android/widget/TextView#setHyphenationFrequency(int)) Thus "high" and "balanced" are not only redundant, but actually don't do what the value indicates - Layout#BREAK_STRATEGY_BALANCED (constant value: 2) and Layout#BREAK_STRATEGY_HIGH_QUALITY (constant value: 1) are only meant to be used for android:breakStrategy Changelog: [Android][Changed] - Remove `"high"` and `"balanced"` as values for `android_hyphenationFrequency` on `Text` Reviewed By: JoshuaGross Differential Revision: D30531096 fbshipit-source-id: 1a0b6e733bb21ce6b2f104a2025a79c16de3cfea --- Libraries/Text/TextProps.js | 8 +------- .../views/text/ReactTextAnchorViewManager.java | 4 ---- .../js/examples/Text/TextExample.android.js | 14 +++----------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/Libraries/Text/TextProps.js b/Libraries/Text/TextProps.js index b2a39e58df76..3942a5998cd3 100644 --- a/Libraries/Text/TextProps.js +++ b/Libraries/Text/TextProps.js @@ -66,13 +66,7 @@ export type TextProps = $ReadOnly<{| * Set hyphenation strategy on Android. * */ - android_hyphenationFrequency?: ?( - | 'normal' - | 'none' - | 'full' - | 'high' - | 'balanced' - ), + android_hyphenationFrequency?: ?('normal' | 'none' | 'full'), children?: ?Node, /** diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextAnchorViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextAnchorViewManager.java index ffc8655c0a47..6ee067cb661a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextAnchorViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextAnchorViewManager.java @@ -110,10 +110,6 @@ public void setAndroidHyphenationFrequency(ReactTextView view, @Nullable String view.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE); } else if (frequency.equals("full")) { view.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL); - } else if (frequency.equals("balanced")) { - view.setHyphenationFrequency(Layout.BREAK_STRATEGY_BALANCED); - } else if (frequency.equals("high")) { - view.setHyphenationFrequency(Layout.BREAK_STRATEGY_HIGH_QUALITY); } else if (frequency.equals("normal")) { view.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL); } else { diff --git a/packages/rn-tester/js/examples/Text/TextExample.android.js b/packages/rn-tester/js/examples/Text/TextExample.android.js index 6b3668663d82..d44aff22b429 100644 --- a/packages/rn-tester/js/examples/Text/TextExample.android.js +++ b/packages/rn-tester/js/examples/Text/TextExample.android.js @@ -216,23 +216,15 @@ class TextExample extends React.Component<{...}> { Normal: - WillHaveAnHyphenWhenBreakingForNewLine + WillHaveAHyphenWhenBreakingForNewLine None: - WillNotHaveAnHyphenWhenBreakingForNewLine + WillNotHaveAHyphenWhenBreakingForNewLine Full: - WillHaveAnHyphenWhenBreakingForNewLine - - - High: - WillHaveAnHyphenWhenBreakingForNewLine - - - Balanced: - WillHaveAnHyphenWhenBreakingForNewLine + WillHaveAHyphenWhenBreakingForNewLine From 362511dc939b6784ab25c4238c70a019faf414af Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Thu, 26 Aug 2021 12:00:48 -0700 Subject: [PATCH 021/986] chore: prefer the local react-native-codegen package (#32096) Summary: Currently, the build breaks if we move `react-native-codegen` from the template's dependencies to root. This is due to `scripts/generate-specs-cli.js` using the one installed under `node_modules` instead of the local one. ## Changelog [Internal] [Fixed] - `scripts/generate-specs-cli.js` should prefer the local `react-native-codegen` package Pull Request resolved: https://github.com/facebook/react-native/pull/32096 Test Plan: 1. Make the following changes ```diff diff --git a/package.json b/package.json index 847c726a69b..78da8232988 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "promise": "^8.0.3", "prop-types": "^15.7.2", "react-devtools-core": "^4.13.0", + "react-native-codegen": "^0.0.7", "react-refresh": "^0.4.0", "regenerator-runtime": "^0.13.2", "scheduler": "^0.20.2", diff --git a/template/package.json b/template/package.json index 715614112ac..5e0762b1b25 100644 --- a/template/package.json +++ b/template/package.json @@ -21,7 +21,6 @@ "eslint": "7.14.0", "jest": "^26.6.3", "metro-react-native-babel-preset": "^0.66.2", - "react-native-codegen": "^0.0.7", "react-test-renderer": "17.0.2" }, "jest": { ``` 2. Run `scripts/test-manual-e2e.sh` ## Expected Behavior Task `:ReactAndroid:buildReactNdkLib` succeeds. ## Actual Behavior ``` > Task :ReactAndroid:buildReactNdkLib FAILED make: Entering directory '~/Source/react-native/ReactAndroid/src/main/jni/react/jni' fcntl(): Bad file descriptor make: Leaving directory '~/Source/react-native/ReactAndroid/src/main/jni/react/jni' ~/Library/Android/sdk/ndk/21.4.7075529/build/core/build-binary.mk:651: Android NDK: Module react_codegen_rncore depends on undefined modules: react_render_components_view ~/Library/Android/sdk/ndk/21.4.7075529/build/core/build-binary.mk:664: *** Android NDK: Note that old versions of ndk-build silently ignored this error case. If your project worked on those versions, the missing libraries were not needed and you can remove those dependencies from the module to fix your build. Alternatively, set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies. . Stop. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':ReactAndroid:buildReactNdkLib'. > Process 'command '~/Library/Android/sdk/ndk/21.4.7075529/ndk-build'' finished with non-zero exit value 2 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 19s 20 actionable tasks: 20 executed Couldn't generate artifacts ``` Reviewed By: ShikaSD Differential Revision: D30581194 Pulled By: hramos fbshipit-source-id: 3f7a707b33377042502e50887856ff5641fdd52c --- scripts/generate-specs-cli.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate-specs-cli.js b/scripts/generate-specs-cli.js index 53b263faccdf..427eff561044 100644 --- a/scripts/generate-specs-cli.js +++ b/scripts/generate-specs-cli.js @@ -11,9 +11,9 @@ let RNCodegen; try { - RNCodegen = require('react-native-codegen/lib/generators/RNCodegen.js'); -} catch (e) { RNCodegen = require('../packages/react-native-codegen/lib/generators/RNCodegen.js'); +} catch (e) { + RNCodegen = require('react-native-codegen/lib/generators/RNCodegen.js'); if (!RNCodegen) { throw 'RNCodegen not found.'; } From 732ac170992ca7b94e2419603d1f1095a878bbe3 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Thu, 26 Aug 2021 14:58:39 -0700 Subject: [PATCH 022/986] Update manual testing script to also test Hermes for RNTester Summary: Changelog: [Internal] - Update test-manual-e2e.sh to test Hermes for RNTester Reviewed By: ShikaSD Differential Revision: D30569403 fbshipit-source-id: fd45c8158c4c5ad93f33bc7b80464c5fc387a737 --- scripts/test-manual-e2e.sh | 47 +++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/scripts/test-manual-e2e.sh b/scripts/test-manual-e2e.sh index 10ac45b971d1..e6a138d45c44 100755 --- a/scripts/test-manual-e2e.sh +++ b/scripts/test-manual-e2e.sh @@ -4,8 +4,6 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -JAVA_VERSION="1.7" - RED="\033[0;31m" GREEN="\033[0;32m" BLUE="\033[0;35m" @@ -49,28 +47,55 @@ lsof -i :8081 | grep LISTEN | /usr/bin/awk '{print $2}' | xargs kill info "Start the packager in another terminal by running 'npm start' from the root" info "and then press any key." info "" -read -n 1 +read -r -n 1 ./gradlew :packages:rn-tester:android:app:installJscDebug || error "Couldn't build RNTester Android" info "Press any key to run RNTester in an already running Android emulator/device" info "" -read -n 1 +read -r -n 1 adb shell am start -n com.facebook.react.uiapp/.RNTesterActivity -success "Installing CocoaPods dependencies" + +info "Once done testing, keep emulator running" +info "Press any key to run RNTester on Android with Hermes enabled" +read -r -n 1 + +./gradlew :packages:rn-tester:android:app:installHermesDebug || error "Couldn't build RNTester Android" +adb shell am start -n com.facebook.react.uiapp/.RNTesterActivity + +info "When done testing RNTester on Android," +info "Press any key to start testing RNTester in iOS" +read -r -n 1 + +success "About to test iOS JSC... " +success "Installing CocoaPods dependencies..." rm -rf packages/rn-tester/Pods (cd packages/rn-tester && pod install) info "Press any key to open the workspace in Xcode, then build and test manually." info "" -read -n 1 +read -r -n 1 + +open "packages/rn-tester/RNTesterPods.xcworkspace" + +info "When done testing iOS JSC, press any key to test iOS Hermes" +read -r -n 1 + +success "About to test iOS Hermes... " +success "Installing CocoaPods dependencies..." +rm -rf packages/rn-tester/Pods +(cd packages/rn-tester && USE_HERMES=1 pod install) + +info "Press any key to open the workspace in Xcode, then build and test manually." +info "" +read -r -n 1 open "packages/rn-tester/RNTesterPods.xcworkspace" info "When done testing RNTester app on iOS and Android press any key to continue." info "" -read -n 1 +read -r -n 1 success "Killing packager" lsof -i :8081 | grep LISTEN @@ -86,7 +111,7 @@ success "React Native version changed in the template" project_name="RNTestProject" -cd /tmp/ +cd /tmp/ || exit rm -rf "$project_name" node "$repo_root/cli.js" init "$project_name" --template "$repo_root" @@ -102,7 +127,7 @@ info " - Verify 'Reload JS' works" info "" info "Press any key to run the sample in Android emulator/device" info "" -read -n 1 +read -r -n 1 cd "/tmp/${project_name}" && npx react-native run-android info "Test the following on iOS:" @@ -115,10 +140,10 @@ info " - Disable Fast Refresh." info "" info "Press any key to open the project in Xcode" info "" -read -n 1 +read -r -n 1 open "/tmp/${project_name}/ios/${project_name}.xcworkspace" -cd "$repo_root" +cd "$repo_root" || exit info "Next steps:" info " - https://github.com/facebook/react-native/blob/HEAD/Releases.md" From ca60be8882522b707ddb710bdbda9ba673cdc22f Mon Sep 17 00:00:00 2001 From: Genki Kondo Date: Thu, 26 Aug 2021 18:51:02 -0700 Subject: [PATCH 023/986] Add android_hyphenationStrategy to ParagraphAttributes Summary: Expose android_hyphenationFrequency in Fabric as part of ParagraphAttributes Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D30583215 fbshipit-source-id: f4e9e9d6ea8efcfc10db29e1fbd651462f442837 --- .../attributedstring/ParagraphAttributes.cpp | 11 ++-- .../attributedstring/ParagraphAttributes.h | 11 +++- .../renderer/attributedstring/conversions.h | 51 +++++++++++++++++++ .../renderer/attributedstring/primitives.h | 19 ++++++- 4 files changed, 87 insertions(+), 5 deletions(-) diff --git a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp index fe64a462aa3e..cafee3113893 100644 --- a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp +++ b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp @@ -21,13 +21,15 @@ bool ParagraphAttributes::operator==(const ParagraphAttributes &rhs) const { ellipsizeMode, textBreakStrategy, adjustsFontSizeToFit, - includeFontPadding) == + includeFontPadding, + android_hyphenationFrequency) == std::tie( rhs.maximumNumberOfLines, rhs.ellipsizeMode, rhs.textBreakStrategy, rhs.adjustsFontSizeToFit, - rhs.includeFontPadding) && + rhs.includeFontPadding, + rhs.android_hyphenationFrequency) && floatEquality(minimumFontSize, rhs.minimumFontSize) && floatEquality(maximumFontSize, rhs.maximumFontSize); } @@ -47,7 +49,10 @@ SharedDebugStringConvertibleList ParagraphAttributes::getDebugProps() const { debugStringConvertibleItem("adjustsFontSizeToFit", adjustsFontSizeToFit), debugStringConvertibleItem("minimumFontSize", minimumFontSize), debugStringConvertibleItem("maximumFontSize", maximumFontSize), - debugStringConvertibleItem("includeFontPadding", includeFontPadding)}; + debugStringConvertibleItem("includeFontPadding", includeFontPadding), + debugStringConvertibleItem( + "android_hyphenationFrequency", + android_hyphenationFrequency)}; } #endif diff --git a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h index a5666035eff6..c4fa4a5944ad 100644 --- a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h +++ b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h @@ -42,6 +42,9 @@ class ParagraphAttributes : public DebugStringConvertible { */ EllipsizeMode ellipsizeMode{}; + /* + * (Android only) Break strategy for breaking paragraphs into lines. + */ TextBreakStrategy textBreakStrategy{}; /* @@ -55,6 +58,11 @@ class ParagraphAttributes : public DebugStringConvertible { */ bool includeFontPadding{true}; + /* + * (Android only) Frequency of automatic hyphenation to use when determining word breaks. + */ + HyphenationFrequency android_hyphenationFrequency{}; + /* * In case of font size adjustment enabled, defines minimum and maximum * font sizes. @@ -89,7 +97,8 @@ struct hash { attributes.adjustsFontSizeToFit, attributes.minimumFontSize, attributes.maximumFontSize, - attributes.includeFontPadding); + attributes.includeFontPadding, + attributes.android_hyphenationFrequency); } }; } // namespace std diff --git a/ReactCommon/react/renderer/attributedstring/conversions.h b/ReactCommon/react/renderer/attributedstring/conversions.h index da688767fcd7..43c449cdde2d 100644 --- a/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/ReactCommon/react/renderer/attributedstring/conversions.h @@ -712,6 +712,48 @@ inline void fromRawValue( result = AccessibilityRole::None; } +inline std::string toString(const HyphenationFrequency &hyphenationFrequency) { + switch (hyphenationFrequency) { + case HyphenationFrequency::None: + return "none"; + case HyphenationFrequency::Normal: + return "normal"; + case HyphenationFrequency::Full: + return "full"; + } + + LOG(ERROR) << "Unsupported HyphenationFrequency value"; + react_native_assert(false); + return "none"; +} + +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + HyphenationFrequency &result) { + react_native_assert(value.hasType()); + if (value.hasType()) { + auto string = (std::string)value; + if (string == "none") { + result = HyphenationFrequency::None; + } else if (string == "normal") { + result = HyphenationFrequency::Normal; + } else if (string == "full") { + result = HyphenationFrequency::Full; + } else { + // sane default + LOG(ERROR) << "Unsupported HyphenationFrequency value: " << string; + react_native_assert(false); + result = HyphenationFrequency::None; + } + return; + } + + LOG(ERROR) << "Unsupported HyphenationFrequency type"; + react_native_assert(false); + result = HyphenationFrequency::None; +} + inline ParagraphAttributes convertRawProp( const PropsParserContext &context, RawProps const &rawProps, @@ -761,6 +803,12 @@ inline ParagraphAttributes convertRawProp( "includeFontPadding", sourceParagraphAttributes.includeFontPadding, defaultParagraphAttributes.includeFontPadding); + paragraphAttributes.android_hyphenationFrequency = convertRawProp( + context, + rawProps, + "android_hyphenationFrequency", + sourceParagraphAttributes.android_hyphenationFrequency, + defaultParagraphAttributes.android_hyphenationFrequency); return paragraphAttributes; } @@ -796,6 +844,9 @@ inline folly::dynamic toDynamic( values("textBreakStrategy", toString(paragraphAttributes.textBreakStrategy)); values("adjustsFontSizeToFit", paragraphAttributes.adjustsFontSizeToFit); values("includeFontPadding", paragraphAttributes.includeFontPadding); + values( + "android_hyphenationFrequency", + toString(paragraphAttributes.android_hyphenationFrequency)); return values; } diff --git a/ReactCommon/react/renderer/attributedstring/primitives.h b/ReactCommon/react/renderer/attributedstring/primitives.h index cb080f35b83e..49c14ea0637e 100644 --- a/ReactCommon/react/renderer/attributedstring/primitives.h +++ b/ReactCommon/react/renderer/attributedstring/primitives.h @@ -53,7 +53,11 @@ enum class EllipsizeMode { Middle // Truncate middle of line: "ab...yz". }; -enum class TextBreakStrategy { Simple, Balanced, HighQuality }; +enum class TextBreakStrategy { + Simple, // Simple strategy. + Balanced, // Balances line lengths. + HighQuality // High-quality strategy, including hyphenation. +}; enum class TextAlignment { Natural, // Indicates the default alignment for script. @@ -126,6 +130,12 @@ enum class TextTransform { Unset, }; +enum class HyphenationFrequency { + None, // No hyphenation. + Normal, // Less frequent hyphenation. + Full // Standard amount of hyphenation. +}; + } // namespace react } // namespace facebook @@ -213,4 +223,11 @@ struct hash { return hash()(static_cast(v)); } }; + +template <> +struct hash { + size_t operator()(const facebook::react::HyphenationFrequency &v) const { + return hash()(static_cast(v)); + } +}; } // namespace std From 5d6484e0a87c71f89daba007a5782f824c625727 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Thu, 26 Aug 2021 18:52:44 -0700 Subject: [PATCH 024/986] Keep repo-config workspace in bump-oss-version Summary: Changelog: [Internal][Fixed] - Keep repo-config as a workspace for bumping oss release version. Fixes CI jobs not having tooling dependencies Reviewed By: yungsters Differential Revision: D30595543 fbshipit-source-id: 1dd2adc6a0363202efb5314b7e8eb44618b50327 --- repo-config/package.json | 2 +- scripts/bump-oss-version.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/repo-config/package.json b/repo-config/package.json index 9cd9c30b9a59..e092222641ef 100644 --- a/repo-config/package.json +++ b/repo-config/package.json @@ -8,7 +8,7 @@ "type": "git", "url": "git@github.com:facebook/react-native.git" }, - "dependencies": { + "devDependencies": { "@babel/core": "^7.14.0", "@babel/generator": "^7.14.0", "@babel/template": "^7.0.0", diff --git a/scripts/bump-oss-version.js b/scripts/bump-oss-version.js index d22eb2516714..ef06e4f1e7f0 100755 --- a/scripts/bump-oss-version.js +++ b/scripts/bump-oss-version.js @@ -127,8 +127,12 @@ fs.writeFileSync( ); let packageJson = JSON.parse(cat('package.json')); + packageJson.version = version; -delete packageJson.workspaces; + +// Only keep 'repo-config` workspace +packageJson.workspaces = packageJson.workspaces.filter(w => w === 'repo-config'); + delete packageJson.private; fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf-8'); From 1acf33461451834097463f43e70d90bae0f67198 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 26 Aug 2021 21:45:22 -0700 Subject: [PATCH 025/986] Fixed `alignItems: baseline` for elements on Android (#31575) Summary: This fixes https://github.com/facebook/react-native/issues/20666 and https://github.com/facebook/react-native/issues/21918. This is pretty much the same as 51b3529f6c2ca354800c0cf6ecb8eb3115eaa36e but implemented for Android. Now exposes the actual base-line offset value that allows Yoga to position it properly when `alignItems: baseline` is requested. ## Changelog [Android][Fixed] - Fixed `alignItems: baseline` for elements on Android Pull Request resolved: https://github.com/facebook/react-native/pull/31575 Test Plan: The same test case that we have for iOS. Before: Screen Shot 2021-05-22 at 7 03 18 PM After: Screen Shot 2021-05-22 at 7 01 51 PM Reviewed By: JoshuaGross Differential Revision: D28631468 Pulled By: yungsters fbshipit-source-id: 7c259e469d19d8344298319f066b8437dfdedad0 --- .../react/views/text/ReactTextShadowNode.java | 16 +++++ .../js/examples/Text/TextExample.android.js | 62 +++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java index 46bc1e9b5005..26257ebe9388 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java @@ -32,6 +32,7 @@ import com.facebook.react.uimanager.UIViewOperationQueue; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.events.RCTEventEmitter; +import com.facebook.yoga.YogaBaselineFunction; import com.facebook.yoga.YogaConstants; import com.facebook.yoga.YogaDirection; import com.facebook.yoga.YogaMeasureFunction; @@ -159,6 +160,20 @@ public long measure( } }; + private final YogaBaselineFunction mTextBaselineFunction = + new YogaBaselineFunction() { + @Override + public float baseline(YogaNode node, float width, float height) { + Spannable text = + Assertions.assertNotNull( + mPreparedSpannableText, + "Spannable element has not been prepared in onBeforeLayout"); + + Layout layout = measureSpannedText(text, width, YogaMeasureMode.EXACTLY); + return layout.getLineBaseline(layout.getLineCount() - 1); + } + }; + public ReactTextShadowNode() { this(null); } @@ -171,6 +186,7 @@ public ReactTextShadowNode(@Nullable ReactTextViewManagerCallback reactTextViewM private void initMeasureFunction() { if (!isVirtual()) { setMeasureFunction(mTextMeasureFunction); + setBaselineFunction(mTextBaselineFunction); } } diff --git a/packages/rn-tester/js/examples/Text/TextExample.android.js b/packages/rn-tester/js/examples/Text/TextExample.android.js index d44aff22b429..aacb5fa973d4 100644 --- a/packages/rn-tester/js/examples/Text/TextExample.android.js +++ b/packages/rn-tester/js/examples/Text/TextExample.android.js @@ -884,6 +884,62 @@ const styles = StyleSheet.create({ alignSelf: 'center', }, }); + +function TextBaseLineLayoutExample(props: {}): React.Node { + const texts = []; + for (let i = 9; i >= 0; i--) { + texts.push( + + {i} + , + ); + } + + const marker = ( + + ); + const subtitleStyle = {fontSize: 16, marginTop: 8, fontWeight: 'bold'}; + + return ( + + {'Nested s:'} + + {marker} + {texts} + {marker} + + + {'Array of s in :'} + + {marker} + {texts} + {marker} + + + {'Interleaving and :'} + + {marker} + + Some text. + + {marker} + Text inside View. + {marker} + + + {marker} + + + ); +} + exports.title = 'Text'; exports.documentationURL = 'https://reactnative.dev/docs/text'; exports.category = 'Basic'; @@ -895,4 +951,10 @@ exports.examples = [ return ; }, }, + { + title: "Text `alignItems: 'baseline'` style", + render: function(): React.Node { + return ; + }, + }, ]; From fe5a5dc878158a0a5fb6dff005096fa8fb8f0ab7 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Thu, 26 Aug 2021 22:39:10 -0700 Subject: [PATCH 026/986] virtualize setDisplayMode Summary: Changelog: [internal] following the recommendation in https://fb.workplace.com/groups/474291069286180/posts/6540719469309946 in order to unit test classes that use SurfaceHandler, we need to be able to mock it somehow - since the class is final we aren't able to do that. in this diff, we convert the function that we need to stub / listen to to a virtual function so we can mock it. the alternative is to keep this class final, and create another abstract interface that this will extend from. however, this class is quite large and that would have a lot more boilerplate and updation of callsites, so this simpler approach seems better. Reviewed By: sammy-SC Differential Revision: D30578928 fbshipit-source-id: 4a63396f049c44753986d15f1ac64332b2a8393a --- ReactCommon/react/renderer/scheduler/SurfaceHandler.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ReactCommon/react/renderer/scheduler/SurfaceHandler.h b/ReactCommon/react/renderer/scheduler/SurfaceHandler.h index a606167c3709..c0ae0e60bdc7 100644 --- a/ReactCommon/react/renderer/scheduler/SurfaceHandler.h +++ b/ReactCommon/react/renderer/scheduler/SurfaceHandler.h @@ -34,7 +34,7 @@ class UIManager; * ensure the logical consistency of some methods (e.g. calling `stop` for * non-running surface will crash). */ -class SurfaceHandler final { +class SurfaceHandler { public: /* * Represents a status of the `SurfaceHandler` instance. @@ -62,7 +62,7 @@ class SurfaceHandler final { * Can be constructed anytime with a `moduleName` and a `surfaceId`. */ SurfaceHandler(std::string const &moduleName, SurfaceId surfaceId) noexcept; - ~SurfaceHandler() noexcept; + virtual ~SurfaceHandler() noexcept; /* * Movable-only. @@ -95,10 +95,10 @@ class SurfaceHandler final { void stop() const noexcept; /* - * Sets (and gets) the runnnig mode. + * Sets (and gets) the running mode. * The running mode can be changed anytime (even for `Unregistered` surface). */ - void setDisplayMode(DisplayMode displayMode) const noexcept; + virtual void setDisplayMode(DisplayMode displayMode) const noexcept; DisplayMode getDisplayMode() const noexcept; #pragma mark - Accessors From ec92c85a15468fd00dc0a23b8f69f5f1624f7b45 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Thu, 26 Aug 2021 22:39:10 -0700 Subject: [PATCH 027/986] introduce MockSurfaceHandler Summary: Changelog: [ios][added] - introduce MockSurfaceHandler following the recommendation in https://fb.workplace.com/groups/474291069286180/posts/6540719469309946 in order to unit test classes that use SurfaceHandler, we need to be able to mock it somehow - since the class is final we aren't able to do that. in this diff, we add the mock class. Reviewed By: sammy-SC Differential Revision: D30578927 fbshipit-source-id: 9b39b03ad0b55cecd9b482f9cce9630d7e7d5bda --- ReactCommon/react/test_utils/BUCK | 3 +++ .../react/test_utils/MockSurfaceHandler.h | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ReactCommon/react/test_utils/MockSurfaceHandler.h diff --git a/ReactCommon/react/test_utils/BUCK b/ReactCommon/react/test_utils/BUCK index 52bae03fe6c5..8cd75144aaaa 100644 --- a/ReactCommon/react/test_utils/BUCK +++ b/ReactCommon/react/test_utils/BUCK @@ -51,4 +51,7 @@ rn_xplat_cxx_library( react_native_xplat_target("better:better"), react_native_xplat_target("react/debug:debug"), ], + exported_deps = [ + "//xplat/third-party/gmock:gmock", + ], ) diff --git a/ReactCommon/react/test_utils/MockSurfaceHandler.h b/ReactCommon/react/test_utils/MockSurfaceHandler.h new file mode 100644 index 000000000000..c6f678ce4848 --- /dev/null +++ b/ReactCommon/react/test_utils/MockSurfaceHandler.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +#include + +namespace facebook { +namespace react { + +class MockSurfaceHandler : public SurfaceHandler { + public: + MockSurfaceHandler() : SurfaceHandler("moduleName", 0){}; + + MOCK_QUALIFIED_METHOD1(setDisplayMode, const noexcept, void(DisplayMode)); +}; + +} // namespace react +} // namespace facebook From 4ac42d88ef60ae3fed7319851d47b93e98ac9afa Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Thu, 26 Aug 2021 22:40:03 -0700 Subject: [PATCH 028/986] Optimize font handling on iOS (#31764) Summary: Few issues I saw when profiling RNTester: - Repeatedly calling `-lowercaseString` during `weightOfFont` causes a TON of extra memory traffic, for no reason. - `NSCache` is thread-safe, so no need for a mutex. - Using `stringWithFormat:` for the cache key is slow. Use `NSValue` to store the data directly instead. - Calling `-fontDescriptor` in `isItalicFont` and `isCondensedFont` is overly expensive and unnecessary. - `+fontNamesForFamilyName:` is insanely expensive. Wrap it in a cache. Unscientific test on RNTester iPhone 11 Pro, memory & time. Before: Screen Shot 2021-06-23 at 7 40 06 AM Screen Shot 2021-06-23 at 7 41 30 AM After: Screen Shot 2021-06-23 at 9 02 54 AM Screen Shot 2021-06-23 at 8 59 44 AM Changelog: [iOS][Changed] - Optimized font handling Pull Request resolved: https://github.com/facebook/react-native/pull/31764 Reviewed By: appden Differential Revision: D30241725 Pulled By: yungsters fbshipit-source-id: 342e4f6e5492926acd2afc7d645e6878846369fc --- BUCK | 1 + React/Views/RCTFont.mm | 92 +++++++++++-------- .../RNTesterUnitTests/RCTFontTests.m | 2 +- 3 files changed, 56 insertions(+), 39 deletions(-) diff --git a/BUCK b/BUCK index b315295c974f..8c53560e3330 100644 --- a/BUCK +++ b/BUCK @@ -376,6 +376,7 @@ rn_xplat_cxx_library2( "$SDKROOT/System/Library/Frameworks/CFNetwork.framework", "$SDKROOT/System/Library/Frameworks/CoreGraphics.framework", "$SDKROOT/System/Library/Frameworks/CoreLocation.framework", + "$SDKROOT/System/Library/Frameworks/CoreText.framework", "$SDKROOT/System/Library/Frameworks/Foundation.framework", "$SDKROOT/System/Library/Frameworks/MapKit.framework", "$SDKROOT/System/Library/Frameworks/QuartzCore.framework", diff --git a/React/Views/RCTFont.mm b/React/Views/RCTFont.mm index 93e1a803c7ca..7a8cbbb19abe 100644 --- a/React/Views/RCTFont.mm +++ b/React/Views/RCTFont.mm @@ -11,18 +11,16 @@ #import -#import - typedef CGFloat RCTFontWeight; static RCTFontWeight weightOfFont(UIFont *font) { - static NSArray *fontNames; - static NSArray *fontWeights; + static NSArray *weightSuffixes; + static NSArray *fontWeights; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ // We use two arrays instead of one map because // the order is important for suffix matching. - fontNames = @[ + weightSuffixes = @[ @"normal", @"ultralight", @"thin", @@ -54,28 +52,29 @@ static RCTFontWeight weightOfFont(UIFont *font) ]; }); - for (NSInteger i = 0; i < 0 || i < (unsigned)fontNames.count; i++) { - if ([font.fontName.lowercaseString hasSuffix:fontNames[i]]) { - return (RCTFontWeight)[fontWeights[i] doubleValue]; + NSString *fontName = font.fontName; + NSInteger i = 0; + for (NSString *suffix in weightSuffixes) { + // CFStringFind is much faster than any variant of rangeOfString: because it does not use a locale. + auto options = kCFCompareCaseInsensitive | kCFCompareAnchored | kCFCompareBackwards; + if (CFStringFind((CFStringRef)fontName, (CFStringRef)suffix, options).location != kCFNotFound) { + return (RCTFontWeight)fontWeights[i].doubleValue; } + i++; } - NSDictionary *traits = [font.fontDescriptor objectForKey:UIFontDescriptorTraitsAttribute]; + auto traits = (__bridge_transfer NSDictionary *)CTFontCopyTraits((CTFontRef)font); return (RCTFontWeight)[traits[UIFontWeightTrait] doubleValue]; } static BOOL isItalicFont(UIFont *font) { - NSDictionary *traits = [font.fontDescriptor objectForKey:UIFontDescriptorTraitsAttribute]; - UIFontDescriptorSymbolicTraits symbolicTraits = [traits[UIFontSymbolicTrait] unsignedIntValue]; - return (symbolicTraits & UIFontDescriptorTraitItalic) != 0; + return (CTFontGetSymbolicTraits((CTFontRef)font) & kCTFontTraitItalic) != 0; } static BOOL isCondensedFont(UIFont *font) { - NSDictionary *traits = [font.fontDescriptor objectForKey:UIFontDescriptorTraitsAttribute]; - UIFontDescriptorSymbolicTraits symbolicTraits = [traits[UIFontSymbolicTrait] unsignedIntValue]; - return (symbolicTraits & UIFontDescriptorTraitCondensed) != 0; + return (CTFontGetSymbolicTraits((CTFontRef)font) & kCTFontTraitCondensed) != 0; } static RCTFontHandler defaultFontHandler; @@ -130,18 +129,16 @@ static inline BOOL CompareFontWeights(UIFontWeight firstWeight, UIFontWeight sec static UIFont *cachedSystemFont(CGFloat size, RCTFontWeight weight) { - static NSCache *fontCache; - static std::mutex *fontCacheMutex = new std::mutex; - - NSString *cacheKey = [NSString stringWithFormat:@"%.1f/%.2f", size, weight]; - UIFont *font; - { - std::lock_guard lock(*fontCacheMutex); - if (!fontCache) { - fontCache = [NSCache new]; - } - font = [fontCache objectForKey:cacheKey]; - } + static NSCache *fontCache = [NSCache new]; + + struct __attribute__((__packed__)) CacheKey { + CGFloat size; + RCTFontWeight weight; + }; + + CacheKey key{size, weight}; + NSValue *cacheKey = [[NSValue alloc] initWithBytes:&key objCType:@encode(CacheKey)]; + UIFont *font = [fontCache objectForKey:cacheKey]; if (!font) { if (defaultFontHandler) { @@ -151,15 +148,36 @@ static inline BOOL CompareFontWeights(UIFontWeight firstWeight, UIFontWeight sec font = [UIFont systemFontOfSize:size weight:weight]; } - { - std::lock_guard lock(*fontCacheMutex); - [fontCache setObject:font forKey:cacheKey]; - } + [fontCache setObject:font forKey:cacheKey]; } return font; } +// Caching wrapper around expensive +[UIFont fontNamesForFamilyName:] +static NSArray *fontNamesForFamilyName(NSString *familyName) +{ + static NSCache *> *cache; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + cache = [NSCache new]; + [NSNotificationCenter.defaultCenter + addObserverForName:(NSNotificationName)kCTFontManagerRegisteredFontsChangedNotification + object:nil + queue:nil + usingBlock:^(NSNotification *) { + [cache removeAllObjects]; + }]; + }); + + auto names = [cache objectForKey:familyName]; + if (!names) { + names = [UIFont fontNamesForFamilyName:familyName]; + [cache setObject:names forKey:familyName]; + } + return names; +} + @implementation RCTConvert (RCTFont) + (UIFont *)UIFont:(id)json @@ -315,7 +333,7 @@ + (UIFont *)updateFont:(UIFont *)font // Gracefully handle being given a font name rather than font family, for // example: "Helvetica Light Oblique" rather than just "Helvetica". - if (!didFindFont && [UIFont fontNamesForFamilyName:familyName].count == 0) { + if (!didFindFont && fontNamesForFamilyName(familyName).count == 0) { font = [UIFont fontWithName:familyName size:fontSize]; if (font) { // It's actually a font name, not a font family name, @@ -339,7 +357,8 @@ + (UIFont *)updateFont:(UIFont *)font // Get the closest font that matches the given weight for the fontFamily CGFloat closestWeight = INFINITY; - for (NSString *name in [UIFont fontNamesForFamilyName:familyName]) { + NSArray *names = fontNamesForFamilyName(familyName); + for (NSString *name in names) { UIFont *match = [UIFont fontWithName:name size:fontSize]; if (isItalic == isItalicFont(match) && isCondensed == isCondensedFont(match)) { CGFloat testWeight = weightOfFont(match); @@ -352,11 +371,8 @@ + (UIFont *)updateFont:(UIFont *)font // If we still don't have a match at least return the first font in the fontFamily // This is to support built-in font Zapfino and other custom single font families like Impact - if (!font) { - NSArray *names = [UIFont fontNamesForFamilyName:familyName]; - if (names.count > 0) { - font = [UIFont fontWithName:names[0] size:fontSize]; - } + if (!font && names.count > 0) { + font = [UIFont fontWithName:names[0] size:fontSize]; } // Apply font variants to font object diff --git a/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m b/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m index bb8f19b03835..650b14f51514 100644 --- a/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m +++ b/packages/rn-tester/RNTesterUnitTests/RCTFontTests.m @@ -20,7 +20,7 @@ @implementation RCTFontTests // will be different objects, but the same font, so this macro now explicitly // checks that fontName (which includes the style) and pointSize are equal. #define RCTAssertEqualFonts(font1, font2) { \ - XCTAssertTrue([font1.fontName isEqualToString:font2.fontName]); \ + XCTAssertEqualObjects(font1.fontName, font2.fontName); \ XCTAssertEqual(font1.pointSize,font2.pointSize); \ } From 3b2d5419899363d84aea4f5cc3a4c75253dd6406 Mon Sep 17 00:00:00 2001 From: Genki Kondo Date: Fri, 27 Aug 2021 00:16:30 -0700 Subject: [PATCH 029/986] Set textBreakStrategy default to be HighQuality Summary: Android TextView's default for breakStrategy is BREAK_STRATEGY_HIGH_QUALITY (https://developer.android.com/reference/android/widget/TextView#setBreakStrategy(int)) RN docs also states that highQuality is default. However, on Fabric, the default is 'simple'. This diff fixes the default to be 'highQuality' Changelog: [Android][Fixed] - Set textBreakStrategy default to be 'highQuality' Reviewed By: JoshuaGross Differential Revision: D30597085 fbshipit-source-id: 3bd7531afdaf980b342cc461dd449c3d3df12cb0 --- .../react/renderer/attributedstring/ParagraphAttributes.cpp | 3 +-- .../react/renderer/attributedstring/ParagraphAttributes.h | 5 +++-- ReactCommon/react/renderer/attributedstring/conversions.h | 6 +++--- ReactCommon/react/renderer/attributedstring/primitives.h | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp index cafee3113893..d5251fa907b9 100644 --- a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp +++ b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp @@ -51,8 +51,7 @@ SharedDebugStringConvertibleList ParagraphAttributes::getDebugProps() const { debugStringConvertibleItem("maximumFontSize", maximumFontSize), debugStringConvertibleItem("includeFontPadding", includeFontPadding), debugStringConvertibleItem( - "android_hyphenationFrequency", - android_hyphenationFrequency)}; + "android_hyphenationFrequency", android_hyphenationFrequency)}; } #endif diff --git a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h index c4fa4a5944ad..22f65af3ea4d 100644 --- a/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h +++ b/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h @@ -45,7 +45,7 @@ class ParagraphAttributes : public DebugStringConvertible { /* * (Android only) Break strategy for breaking paragraphs into lines. */ - TextBreakStrategy textBreakStrategy{}; + TextBreakStrategy textBreakStrategy{TextBreakStrategy::HighQuality}; /* * Enables font size adjustment to fit constrained boundaries. @@ -59,7 +59,8 @@ class ParagraphAttributes : public DebugStringConvertible { bool includeFontPadding{true}; /* - * (Android only) Frequency of automatic hyphenation to use when determining word breaks. + * (Android only) Frequency of automatic hyphenation to use when determining + * word breaks. */ HyphenationFrequency android_hyphenationFrequency{}; diff --git a/ReactCommon/react/renderer/attributedstring/conversions.h b/ReactCommon/react/renderer/attributedstring/conversions.h index 43c449cdde2d..8e3ed812eef6 100644 --- a/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/ReactCommon/react/renderer/attributedstring/conversions.h @@ -96,7 +96,7 @@ inline std::string toString(const TextBreakStrategy &textBreakStrategy) { LOG(ERROR) << "Unsupported TextBreakStrategy value"; react_native_assert(false); - return "simple"; + return "highQuality"; } inline void fromRawValue( @@ -116,14 +116,14 @@ inline void fromRawValue( // sane default LOG(ERROR) << "Unsupported TextBreakStrategy value: " << string; react_native_assert(false); - result = TextBreakStrategy::Simple; + result = TextBreakStrategy::HighQuality; } return; } LOG(ERROR) << "Unsupported TextBreakStrategy type"; react_native_assert(false); - result = TextBreakStrategy::Simple; + result = TextBreakStrategy::HighQuality; } inline void fromRawValue( diff --git a/ReactCommon/react/renderer/attributedstring/primitives.h b/ReactCommon/react/renderer/attributedstring/primitives.h index 49c14ea0637e..d4be52366132 100644 --- a/ReactCommon/react/renderer/attributedstring/primitives.h +++ b/ReactCommon/react/renderer/attributedstring/primitives.h @@ -55,8 +55,8 @@ enum class EllipsizeMode { enum class TextBreakStrategy { Simple, // Simple strategy. - Balanced, // Balances line lengths. - HighQuality // High-quality strategy, including hyphenation. + HighQuality, // High-quality strategy, including hyphenation. + Balanced // Balances line lengths. }; enum class TextAlignment { From 4c258a64190f375e503281b3ceb93bac8c43196f Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Fri, 27 Aug 2021 06:40:32 -0700 Subject: [PATCH 030/986] fix(deps): deduplicated metro deps (#31885) Summary: Following recent metro bumps, the lockfile got a bit dirty so I cleaned it Changelog: [Internal] [Fixed] - Bump metro / cleaned lockfile to 0.66.2 Pull Request resolved: https://github.com/facebook/react-native/pull/31885 Reviewed By: ShikaSD Differential Revision: D29814753 Pulled By: sshic fbshipit-source-id: 462bbcb0304b051800bb7a9a79bdb317fe3f3e87 --- repo-config/package.json | 2 +- yarn.lock | 19 ++++--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/repo-config/package.json b/repo-config/package.json index e092222641ef..164f952a2f89 100644 --- a/repo-config/package.json +++ b/repo-config/package.json @@ -40,7 +40,7 @@ "jest": "^26.6.3", "jest-junit": "^10.0.0", "jscodeshift": "^0.11.0", - "metro-transform-plugins": "^0.66.0", + "metro-transform-plugins": "^0.66.2", "mkdirp": "^0.5.1", "prettier": "1.19.1", "react": "17.0.2", diff --git a/yarn.lock b/yarn.lock index f0b97204e201..4b2c41b54f09 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14,7 +14,7 @@ resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.14.0.tgz#a901128bce2ad02565df95e6ecbf195cf9465919" integrity sha512-vu9V3uMM/1o5Hl5OekMUowo3FqXLJSw+s+66nt0fSWVWTtmosdzn45JHOB3cPtZoe6CTBDzvSw0RdOY85Q37+Q== -"@babel/core@^7.0.0", "@babel/core@^7.1.0", "@babel/core@^7.1.6", "@babel/core@^7.14.0", "@babel/core@^7.4.5", "@babel/core@^7.7.5": +"@babel/core@^7.1.0", "@babel/core@^7.1.6", "@babel/core@^7.14.0", "@babel/core@^7.4.5", "@babel/core@^7.7.5": version "7.14.0" resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.14.0.tgz#47299ff3ec8d111b493f1a9d04bf88c04e728d88" integrity sha512-8YqpRig5NmIHlMLw09zMlPTvUVMILjqCOtVgu+TVNWEBvy9b5I3RRyhqnrV4hjgEK7n8P9OqvkWJAFmEL6Wwfw== @@ -35,7 +35,7 @@ semver "^6.3.0" source-map "^0.5.0" -"@babel/generator@^7.14.0", "@babel/generator@^7.5.0": +"@babel/generator@^7.14.0": version "7.14.1" resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.14.1.tgz#1f99331babd65700183628da186f36f63d615c93" integrity sha512-TMGhsXMXCP/O1WtQmZjpEYDhCYC9vFhayWZPJSZCGkPJgUqX0rF0wwtrYvnzVxIjcF80tkUertXVk5cwqi5cAQ== @@ -703,7 +703,7 @@ "@babel/parser" "^7.12.13" "@babel/types" "^7.12.13" -"@babel/traverse@^7.0.0", "@babel/traverse@^7.1.0", "@babel/traverse@^7.13.0", "@babel/traverse@^7.14.0", "@babel/traverse@^7.7.0", "@babel/traverse@^7.7.4": +"@babel/traverse@^7.1.0", "@babel/traverse@^7.13.0", "@babel/traverse@^7.14.0", "@babel/traverse@^7.7.0", "@babel/traverse@^7.7.4": version "7.14.0" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.14.0.tgz#cea0dc8ae7e2b1dec65f512f39f3483e8cc95aef" integrity sha512-dZ/a371EE5XNhTHomvtuLTUyx6UEoJmYX+DT5zBCQN3McHemsuIaKKYqsc/fs26BEkHs/lBZy0J571LP5z9kQA== @@ -4710,7 +4710,7 @@ metro-symbolicate@0.66.2: through2 "^2.0.1" vlq "^1.0.0" -metro-transform-plugins@0.66.2: +metro-transform-plugins@0.66.2, metro-transform-plugins@^0.66.2: version "0.66.2" resolved "https://registry.yarnpkg.com/metro-transform-plugins/-/metro-transform-plugins-0.66.2.tgz#39dd044a23b1343e4f2d2ec34d08128cdf255ed4" integrity sha512-KTvqplh0ut7oDKovvDG6yzXM02R6X+9b2oVG+qYq8Zd3aCGTi51ASx4ThCNkAHyEvCuJdYg9fxXTL+j+wvhB5w== @@ -4721,17 +4721,6 @@ metro-transform-plugins@0.66.2: "@babel/traverse" "^7.14.0" nullthrows "^1.1.1" -metro-transform-plugins@^0.66.0: - version "0.66.0" - resolved "https://registry.yarnpkg.com/metro-transform-plugins/-/metro-transform-plugins-0.66.0.tgz#d40cb1a88110b0033b5a870c497ce56a38ec5b1f" - integrity sha512-0jF27jozp4IYuzliM2R7NaXqbPXleiHQWVczECkHg3UjDroCKneCkkgeSeirVZ1TkBqu7KSLMiWdL2OOT+vVxQ== - dependencies: - "@babel/core" "^7.0.0" - "@babel/generator" "^7.5.0" - "@babel/template" "^7.0.0" - "@babel/traverse" "^7.0.0" - nullthrows "^1.1.1" - metro-transform-worker@0.66.2: version "0.66.2" resolved "https://registry.yarnpkg.com/metro-transform-worker/-/metro-transform-worker-0.66.2.tgz#0a8455992132c479721accd52c9bd47deb77769e" From f3e8ea9c2910b33db17001e98b96720b07dce0b3 Mon Sep 17 00:00:00 2001 From: Genki Kondo Date: Fri, 27 Aug 2021 09:02:26 -0700 Subject: [PATCH 031/986] Use hyphenationFrequency for text measurement Summary: Implements the calculation of measurement and position of Text attachments in Android Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D30586616 fbshipit-source-id: e9ecc002f03477e3465d746855e1dff2e5f0b321 --- .../react/views/text/TextAttributeProps.java | 21 ++++++++++++- .../react/views/text/TextLayoutManager.java | 31 +++++++++++++++---- .../text/TextLayoutManagerMapBuffer.java | 30 +++++++++++++++--- .../renderer/attributedstring/conversions.h | 4 +++ 4 files changed, 74 insertions(+), 12 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java index 13311fef41bb..6c93d200e857 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java @@ -68,9 +68,10 @@ public class TextAttributeProps { private static final int DEFAULT_TEXT_SHADOW_COLOR = 0x55000000; private static final int DEFAULT_JUSTIFICATION_MODE = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) ? 0 : Layout.JUSTIFICATION_MODE_NONE; - private static final int DEFAULT_BREAK_STRATEGY = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? 0 : Layout.BREAK_STRATEGY_HIGH_QUALITY; + private static final int DEFAULT_HYPHENATION_FREQUENCY = + (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? 0 : Layout.HYPHENATION_FREQUENCY_NONE; protected float mLineHeight = Float.NaN; protected boolean mIsColorSet = false; @@ -568,4 +569,22 @@ public static int getTextBreakStrategy(@Nullable String textBreakStrategy) { } return androidTextBreakStrategy; } + + public static int getHyphenationFrequency(@Nullable String hyphenationFrequency) { + int androidHyphenationFrequency = DEFAULT_HYPHENATION_FREQUENCY; + if (hyphenationFrequency != null) { + switch (hyphenationFrequency) { + case "none": + androidHyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE; + break; + case "normal": + androidHyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NORMAL; + break; + default: + androidHyphenationFrequency = Layout.HYPHENATION_FREQUENCY_FULL; + break; + } + } + return androidHyphenationFrequency; + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index b0715e7d6be1..f31eee22e300 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -64,6 +64,7 @@ public class TextLayoutManager { private static final boolean DEFAULT_INCLUDE_FONT_PADDING = true; private static final String INCLUDE_FONT_PADDING_KEY = "includeFontPadding"; private static final String TEXT_BREAK_STRATEGY_KEY = "textBreakStrategy"; + private static final String HYPHENATION_FREQUENCY_KEY = "android_hyphenationFrequency"; private static final String MAXIMUM_NUMBER_OF_LINES_KEY = "maximumNumberOfLines"; private static final LruCache sSpannableCache = new LruCache<>(spannableCacheSize); @@ -250,7 +251,8 @@ private static Layout createLayout( float width, YogaMeasureMode widthYogaMeasureMode, boolean includeFontPadding, - int textBreakStrategy) { + int textBreakStrategy, + int hyphenationFrequency) { Layout layout; int spanLength = text.length(); boolean unconstrainedWidth = widthYogaMeasureMode == YogaMeasureMode.UNDEFINED || width < 0; @@ -281,10 +283,9 @@ private static Layout createLayout( .setLineSpacing(0.f, 1.f) .setIncludePad(includeFontPadding) .setBreakStrategy(textBreakStrategy) - .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) + .setHyphenationFrequency(hyphenationFrequency) .build(); } - } else if (boring != null && (unconstrainedWidth || boring.width <= width)) { int boringLayoutWidth = boring.width; if (boring.width < 0) { @@ -325,7 +326,7 @@ private static Layout createLayout( .setLineSpacing(0.f, 1.f) .setIncludePad(includeFontPadding) .setBreakStrategy(textBreakStrategy) - .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL); + .setHyphenationFrequency(hyphenationFrequency); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { builder.setUseLineSpacingFromFallbacks(true); @@ -378,6 +379,9 @@ public static long measureText( paragraphAttributes.hasKey(INCLUDE_FONT_PADDING_KEY) ? paragraphAttributes.getBoolean(INCLUDE_FONT_PADDING_KEY) : DEFAULT_INCLUDE_FONT_PADDING; + int hyphenationFrequency = + TextAttributeProps.getHyphenationFrequency( + paragraphAttributes.getString(HYPHENATION_FREQUENCY_KEY)); if (text == null) { throw new IllegalStateException("Spannable element has not been prepared in onBeforeLayout"); @@ -387,7 +391,13 @@ public static long measureText( Layout layout = createLayout( - text, boring, width, widthYogaMeasureMode, includeFontPadding, textBreakStrategy); + text, + boring, + width, + widthYogaMeasureMode, + includeFontPadding, + textBreakStrategy, + hyphenationFrequency); int maximumNumberOfLines = paragraphAttributes.hasKey(MAXIMUM_NUMBER_OF_LINES_KEY) @@ -539,10 +549,19 @@ public static WritableArray measureLines( paragraphAttributes.hasKey(INCLUDE_FONT_PADDING_KEY) ? paragraphAttributes.getBoolean(INCLUDE_FONT_PADDING_KEY) : DEFAULT_INCLUDE_FONT_PADDING; + int hyphenationFrequency = + TextAttributeProps.getTextBreakStrategy( + paragraphAttributes.getString(HYPHENATION_FREQUENCY_KEY)); Layout layout = createLayout( - text, boring, width, YogaMeasureMode.EXACTLY, includeFontPadding, textBreakStrategy); + text, + boring, + width, + YogaMeasureMode.EXACTLY, + includeFontPadding, + textBreakStrategy, + hyphenationFrequency); return FontMetricsUtil.getFontMetrics(text, layout, sTextPaintInstance, context); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java index 1e5287708a0c..ee86e49d97e4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java @@ -61,6 +61,7 @@ public class TextLayoutManagerMapBuffer { public static final short PA_KEY_TEXT_BREAK_STRATEGY = 2; public static final short PA_KEY_ADJUST_FONT_SIZE_TO_FIT = 3; public static final short PA_KEY_INCLUDE_FONT_PADDING = 4; + public static final short PA_KEY_HYPHENATION_FREQUENCY = 5; private static final boolean ENABLE_MEASURE_LOGGING = ReactBuildConfig.DEBUG && false; @@ -264,7 +265,8 @@ private static Layout createLayout( float width, YogaMeasureMode widthYogaMeasureMode, boolean includeFontPadding, - int textBreakStrategy) { + int textBreakStrategy, + int hyphenationFrequency) { Layout layout; int spanLength = text.length(); boolean unconstrainedWidth = widthYogaMeasureMode == YogaMeasureMode.UNDEFINED || width < 0; @@ -295,7 +297,7 @@ private static Layout createLayout( .setLineSpacing(0.f, 1.f) .setIncludePad(includeFontPadding) .setBreakStrategy(textBreakStrategy) - .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL) + .setHyphenationFrequency(hyphenationFrequency) .build(); } @@ -338,7 +340,7 @@ private static Layout createLayout( .setLineSpacing(0.f, 1.f) .setIncludePad(includeFontPadding) .setBreakStrategy(textBreakStrategy) - .setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL); + .setHyphenationFrequency(hyphenationFrequency); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { builder.setUseLineSpacingFromFallbacks(true); @@ -391,6 +393,9 @@ public static long measureText( paragraphAttributes.hasKey(PA_KEY_INCLUDE_FONT_PADDING) ? paragraphAttributes.getBoolean(PA_KEY_INCLUDE_FONT_PADDING) : DEFAULT_INCLUDE_FONT_PADDING; + int hyphenationFrequency = + TextAttributeProps.getTextBreakStrategy( + paragraphAttributes.getString(PA_KEY_HYPHENATION_FREQUENCY)); if (text == null) { throw new IllegalStateException("Spannable element has not been prepared in onBeforeLayout"); @@ -404,7 +409,13 @@ public static long measureText( Layout layout = createLayout( - text, boring, width, widthYogaMeasureMode, includeFontPadding, textBreakStrategy); + text, + boring, + width, + widthYogaMeasureMode, + includeFontPadding, + textBreakStrategy, + hyphenationFrequency); int maximumNumberOfLines = paragraphAttributes.hasKey(PA_KEY_MAX_NUMBER_OF_LINES) @@ -561,10 +572,19 @@ public static WritableArray measureLines( paragraphAttributes.hasKey(PA_KEY_INCLUDE_FONT_PADDING) ? paragraphAttributes.getBoolean(PA_KEY_INCLUDE_FONT_PADDING) : DEFAULT_INCLUDE_FONT_PADDING; + int hyphenationFrequency = + TextAttributeProps.getTextBreakStrategy( + paragraphAttributes.getString(PA_KEY_HYPHENATION_FREQUENCY)); Layout layout = createLayout( - text, boring, width, YogaMeasureMode.EXACTLY, includeFontPadding, textBreakStrategy); + text, + boring, + width, + YogaMeasureMode.EXACTLY, + includeFontPadding, + textBreakStrategy, + hyphenationFrequency); return FontMetricsUtil.getFontMetrics(text, layout, sTextPaintInstance, context); } diff --git a/ReactCommon/react/renderer/attributedstring/conversions.h b/ReactCommon/react/renderer/attributedstring/conversions.h index 8e3ed812eef6..56ab6bdef943 100644 --- a/ReactCommon/react/renderer/attributedstring/conversions.h +++ b/ReactCommon/react/renderer/attributedstring/conversions.h @@ -1044,6 +1044,7 @@ constexpr static Key PA_KEY_ELLIPSIZE_MODE = 1; constexpr static Key PA_KEY_TEXT_BREAK_STRATEGY = 2; constexpr static Key PA_KEY_ADJUST_FONT_SIZE_TO_FIT = 3; constexpr static Key PA_KEY_INCLUDE_FONT_PADDING = 4; +constexpr static Key PA_KEY_HYPHENATION_FREQUENCY = 5; inline MapBuffer toMapBuffer(const ParagraphAttributes ¶graphAttributes) { auto builder = MapBufferBuilder(); @@ -1058,6 +1059,9 @@ inline MapBuffer toMapBuffer(const ParagraphAttributes ¶graphAttributes) { PA_KEY_ADJUST_FONT_SIZE_TO_FIT, paragraphAttributes.adjustsFontSizeToFit); builder.putBool( PA_KEY_INCLUDE_FONT_PADDING, paragraphAttributes.includeFontPadding); + builder.putString( + PA_KEY_HYPHENATION_FREQUENCY, + toString(paragraphAttributes.android_hyphenationFrequency)); return builder.build(); } From 1bc885b8b856c7a050f0df68d9a09ca7581d0220 Mon Sep 17 00:00:00 2001 From: Neil Dhar Date: Fri, 27 Aug 2021 17:15:23 -0700 Subject: [PATCH 032/986] Make JSI a dynamic library Summary: Ship libjsi as a standalone dynamic library. This prevents problems with exception handling caused by duplicate typeinfo across multiple shared libs, and reduces bundle size by removing duplicate copies of JSI. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D30599215 fbshipit-source-id: abad1398342a5328daa825f3f684e0067cad7a96 --- ReactAndroid/Android-prebuilt.mk | 8 +++++++ .../hermes/instrumentation/Android.mk | 4 ++-- .../facebook/hermes/reactexecutor/Android.mk | 8 +++---- .../com/facebook/react/fabric/jni/Android.mk | 2 +- .../com/facebook/react/jscexecutor/Android.mk | 4 ++-- .../react/modules/blob/jni/Android.mk | 4 ++-- ReactCommon/hermes/executor/Android.mk | 8 +++---- ReactCommon/hermes/inspector/Android.mk | 3 +-- ReactCommon/jsi/Android.mk | 2 +- ReactCommon/jsiexecutor/Android.mk | 4 ++-- .../react/nativemodule/core/Android.mk | 4 ++-- .../samples/platform/android/Android.mk | 2 +- .../renderer/components/image/Android.mk | 2 +- .../renderer/components/scrollview/Android.mk | 2 +- .../react/renderer/components/text/Android.mk | 2 +- .../renderer/components/textinput/Android.mk | 2 +- .../components/unimplementedview/Android.mk | 2 +- .../react/renderer/components/view/Android.mk | 2 +- ReactCommon/react/renderer/core/Android.mk | 2 +- .../react/renderer/mounting/Android.mk | 2 +- .../renderer/runtimescheduler/Android.mk | 2 +- .../generators/modules/GenerateModuleJniH.js | 4 +--- .../GenerateModuleJniH-test.js.snap | 24 +++++-------------- yarn.lock | 6 ++--- 24 files changed, 49 insertions(+), 56 deletions(-) diff --git a/ReactAndroid/Android-prebuilt.mk b/ReactAndroid/Android-prebuilt.mk index fa41a5594e0b..18f8c2662045 100644 --- a/ReactAndroid/Android-prebuilt.mk +++ b/ReactAndroid/Android-prebuilt.mk @@ -156,6 +156,14 @@ LOCAL_EXPORT_C_INCLUDES := \ $(REACT_COMMON_DIR)/react/renderer/components/view include $(PREBUILT_SHARED_LIBRARY) +# jsi +include $(CLEAR_VARS) +LOCAL_MODULE := jsi +LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libjsi.so +LOCAL_EXPORT_C_INCLUDES := \ + $(REACT_COMMON_DIR)/jsi +include $(PREBUILT_SHARED_LIBRARY) + # react_codegen_rncore include $(CLEAR_VARS) LOCAL_MODULE := react_codegen_rncore diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/Android.mk b/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/Android.mk index 3548e86abd3c..651168243ef0 100644 --- a/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/Android.mk +++ b/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/Android.mk @@ -18,8 +18,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-no LOCAL_CPP_FEATURES := exceptions -LOCAL_STATIC_LIBRARIES := libjsireact libjsi -LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes +LOCAL_STATIC_LIBRARIES := libjsireact +LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes libjsi include $(BUILD_SHARED_LIBRARY) diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk index ff05e4c14824..7716394c31f7 100644 --- a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk @@ -17,8 +17,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-no LOCAL_CPP_FEATURES := exceptions -LOCAL_STATIC_LIBRARIES := libjsireact libjsi libhermes-executor-common-release -LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes +LOCAL_STATIC_LIBRARIES := libjsireact libhermes-executor-common-release +LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes libjsi include $(BUILD_SHARED_LIBRARY) @@ -34,7 +34,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-no LOCAL_CPP_FEATURES := exceptions -LOCAL_STATIC_LIBRARIES := libjsireact libjsi libhermes-executor-common-debug libhermes-inspector -LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes +LOCAL_STATIC_LIBRARIES := libjsireact libhermes-executor-common-debug libhermes-inspector +LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes libjsi include $(BUILD_SHARED_LIBRARY) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Android.mk b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Android.mk index 827112595cef..2ad53b97cc2c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Android.mk +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Android.mk @@ -11,7 +11,7 @@ LOCAL_MODULE := fabricjni LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) -LOCAL_SHARED_LIBRARIES := libreactconfig librrc_slider librrc_progressbar librrc_switch librrc_modal libyoga libglog libfb libfbjni libglog_init libfolly_json libfolly_futures libreact_render_mounting libreactnativeutilsjni libreact_utils libreact_render_debug libreact_render_graphics libreact_render_core react_render_componentregistry librrc_view librrc_unimplementedview librrc_root librrc_scrollview libbetter libreact_render_attributedstring libreact_render_uimanager libreact_render_templateprocessor libreact_render_scheduler libreact_render_animations libreact_render_imagemanager libreact_render_textlayoutmanager libreact_codegen_rncore rrc_text librrc_image librrc_textinput libreact_debug libreact_render_mapbuffer libmapbufferjni libreact_render_telemetry +LOCAL_SHARED_LIBRARIES := libjsi libreactconfig librrc_slider librrc_progressbar librrc_switch librrc_modal libyoga libglog libfb libfbjni libglog_init libfolly_json libfolly_futures libreact_render_mounting libreactnativeutilsjni libreact_utils libreact_render_debug libreact_render_graphics libreact_render_core react_render_componentregistry librrc_view librrc_unimplementedview librrc_root librrc_scrollview libbetter libreact_render_attributedstring libreact_render_uimanager libreact_render_templateprocessor libreact_render_scheduler libreact_render_animations libreact_render_imagemanager libreact_render_textlayoutmanager libreact_codegen_rncore rrc_text librrc_image librrc_textinput libreact_debug libreact_render_mapbuffer libmapbufferjni libreact_render_telemetry LOCAL_STATIC_LIBRARIES := diff --git a/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/Android.mk b/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/Android.mk index c521147677c1..19a28eee5af2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/Android.mk +++ b/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/Android.mk @@ -15,7 +15,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) LOCAL_CFLAGS += -fvisibility=hidden -fexceptions -frtti -LOCAL_STATIC_LIBRARIES := libjsi libjsireact jscruntime -LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni +LOCAL_STATIC_LIBRARIES := libjsireact jscruntime +LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libjsi include $(BUILD_SHARED_LIBRARY) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/blob/jni/Android.mk b/ReactAndroid/src/main/java/com/facebook/react/modules/blob/jni/Android.mk index 53fb0c2bf557..6c5a7224c78a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/blob/jni/Android.mk +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/blob/jni/Android.mk @@ -15,7 +15,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) LOCAL_CFLAGS += -fvisibility=hidden -fexceptions -frtti -LOCAL_STATIC_LIBRARIES := libjsi libjsireact -LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni +LOCAL_STATIC_LIBRARIES := libjsireact +LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libjsi include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/hermes/executor/Android.mk b/ReactCommon/hermes/executor/Android.mk index 491100c33a99..52b4d25085f7 100644 --- a/ReactCommon/hermes/executor/Android.mk +++ b/ReactCommon/hermes/executor/Android.mk @@ -16,8 +16,8 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-node-module,$(LOCAL_PATH),hermes-engine)/android/include LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) -LOCAL_STATIC_LIBRARIES := libjsi libjsireact -LOCAL_SHARED_LIBRARIES := libhermes +LOCAL_STATIC_LIBRARIES := libjsireact +LOCAL_SHARED_LIBRARIES := libhermes libjsi include $(BUILD_SHARED_LIBRARY) @@ -31,7 +31,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-node-module,$(LOCAL_PATH),hermes-engine)/android/include LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) -LOCAL_STATIC_LIBRARIES := libjsi libjsireact libhermes-inspector -LOCAL_SHARED_LIBRARIES := libhermes +LOCAL_STATIC_LIBRARIES := libjsireact libhermes-inspector +LOCAL_SHARED_LIBRARIES := libhermes libjsi include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/hermes/inspector/Android.mk b/ReactCommon/hermes/inspector/Android.mk index a6692943e17d..461b10aaac33 100644 --- a/ReactCommon/hermes/inspector/Android.mk +++ b/ReactCommon/hermes/inspector/Android.mk @@ -21,7 +21,6 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_ROOT) LOCAL_CPP_FEATURES := exceptions -LOCAL_STATIC_LIBRARIES := libjsi -LOCAL_SHARED_LIBRARIES := jsinspector libfb libfbjni libfolly_futures libfolly_json libhermes +LOCAL_SHARED_LIBRARIES := jsinspector libfb libfbjni libfolly_futures libfolly_json libhermes libjsi libglog include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/jsi/Android.mk b/ReactCommon/jsi/Android.mk index 6bc98f1b35fc..3fce2059e2d7 100644 --- a/ReactCommon/jsi/Android.mk +++ b/ReactCommon/jsi/Android.mk @@ -17,7 +17,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) LOCAL_CFLAGS := -fexceptions -frtti -O3 LOCAL_SHARED_LIBRARIES := libfolly_json glog -include $(BUILD_STATIC_LIBRARY) +include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) diff --git a/ReactCommon/jsiexecutor/Android.mk b/ReactCommon/jsiexecutor/Android.mk index 74ae7a65cef2..e0661538e666 100644 --- a/ReactCommon/jsiexecutor/Android.mk +++ b/ReactCommon/jsiexecutor/Android.mk @@ -16,7 +16,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES) LOCAL_CFLAGS := -fexceptions -frtti -O3 -LOCAL_STATIC_LIBRARIES := libjsi reactnative reactperflogger -LOCAL_SHARED_LIBRARIES := libfolly_json glog +LOCAL_STATIC_LIBRARIES := reactnative reactperflogger +LOCAL_SHARED_LIBRARIES := libfolly_json glog libjsi include $(BUILD_STATIC_LIBRARY) diff --git a/ReactCommon/react/nativemodule/core/Android.mk b/ReactCommon/react/nativemodule/core/Android.mk index 9fbfdb4759d5..bb2a0d79c774 100644 --- a/ReactCommon/react/nativemodule/core/Android.mk +++ b/ReactCommon/react/nativemodule/core/Android.mk @@ -15,9 +15,9 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/ReactCommon/*.cpp) $(wildcard $(LOCA LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/platform/android/ -LOCAL_SHARED_LIBRARIES := libfbjni libfolly_json libreactnativejni libreact_debug +LOCAL_SHARED_LIBRARIES := libfbjni libfolly_json libreactnativejni libreact_debug libjsi -LOCAL_STATIC_LIBRARIES := libjsi libreactperflogger +LOCAL_STATIC_LIBRARIES := libreactperflogger LOCAL_CFLAGS := \ -DLOG_TAG=\"ReactNative\" diff --git a/ReactCommon/react/nativemodule/samples/platform/android/Android.mk b/ReactCommon/react/nativemodule/samples/platform/android/Android.mk index 9694d7a07380..a000332e34c3 100644 --- a/ReactCommon/react/nativemodule/samples/platform/android/Android.mk +++ b/ReactCommon/react/nativemodule/samples/platform/android/Android.mk @@ -10,7 +10,7 @@ LOCAL_MODULE := sampleturbomodule LOCAL_C_INCLUDES := $(LOCAL_PATH) LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/ReactCommon/*.cpp) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) -LOCAL_SHARED_LIBRARIES := libfbjni libreact_nativemodule_core +LOCAL_SHARED_LIBRARIES := libfbjni libreact_nativemodule_core libjsi LOCAL_CFLAGS := \ -DLOG_TAG=\"ReactNative\" LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall diff --git a/ReactCommon/react/renderer/components/image/Android.mk b/ReactCommon/react/renderer/components/image/Android.mk index 1d7fdcc85bae..8c3fbcabda9c 100644 --- a/ReactCommon/react/renderer/components/image/Android.mk +++ b/ReactCommon/react/renderer/components/image/Android.mk @@ -21,7 +21,7 @@ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall LOCAL_STATIC_LIBRARIES := -LOCAL_SHARED_LIBRARIES := libyoga glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libreact_render_imagemanager libreact_debug libreact_render_mapbuffer +LOCAL_SHARED_LIBRARIES := libjsi libyoga glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libreact_render_imagemanager libreact_debug libreact_render_mapbuffer include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/react/renderer/components/scrollview/Android.mk b/ReactCommon/react/renderer/components/scrollview/Android.mk index a0bbbf75425d..9b02ae73f042 100644 --- a/ReactCommon/react/renderer/components/scrollview/Android.mk +++ b/ReactCommon/react/renderer/components/scrollview/Android.mk @@ -21,7 +21,7 @@ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall LOCAL_STATIC_LIBRARIES := -LOCAL_SHARED_LIBRARIES := libyoga libfolly_futures glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libreact_debug libreact_render_mapbuffer +LOCAL_SHARED_LIBRARIES := libjsi libyoga libfolly_futures glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libreact_debug libreact_render_mapbuffer include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/react/renderer/components/text/Android.mk b/ReactCommon/react/renderer/components/text/Android.mk index 4e082f6dd991..33bfdb78a963 100644 --- a/ReactCommon/react/renderer/components/text/Android.mk +++ b/ReactCommon/react/renderer/components/text/Android.mk @@ -21,7 +21,7 @@ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall LOCAL_STATIC_LIBRARIES := -LOCAL_SHARED_LIBRARIES := libyoga glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_uimanager libreact_render_textlayoutmanager libreact_render_attributedstring libreact_render_mounting librrc_view libreact_utils libreact_debug libreact_render_mapbuffer +LOCAL_SHARED_LIBRARIES := libjsi libyoga glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_uimanager libreact_render_textlayoutmanager libreact_render_attributedstring libreact_render_mounting librrc_view libreact_utils libreact_debug libreact_render_mapbuffer include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/react/renderer/components/textinput/Android.mk b/ReactCommon/react/renderer/components/textinput/Android.mk index 70e44891ddfb..c45affab7b9b 100644 --- a/ReactCommon/react/renderer/components/textinput/Android.mk +++ b/ReactCommon/react/renderer/components/textinput/Android.mk @@ -21,7 +21,7 @@ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall LOCAL_STATIC_LIBRARIES := -LOCAL_SHARED_LIBRARIES := libyoga glog libfolly_json libglog_init libreact_render_core libreact_render_mounting libreact_render_componentregistry libreact_render_debug libreact_render_graphics libreact_render_uimanager libreact_render_imagemanager libreact_render_textlayoutmanager libreact_render_attributedstring librrc_text librrc_image librrc_view libreact_utils libreact_debug libreact_render_mapbuffer +LOCAL_SHARED_LIBRARIES := libjsi libyoga glog libfolly_json libglog_init libreact_render_core libreact_render_mounting libreact_render_componentregistry libreact_render_debug libreact_render_graphics libreact_render_uimanager libreact_render_imagemanager libreact_render_textlayoutmanager libreact_render_attributedstring librrc_text librrc_image librrc_view libreact_utils libreact_debug libreact_render_mapbuffer include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/react/renderer/components/unimplementedview/Android.mk b/ReactCommon/react/renderer/components/unimplementedview/Android.mk index f533321b94d2..959500fb70d1 100644 --- a/ReactCommon/react/renderer/components/unimplementedview/Android.mk +++ b/ReactCommon/react/renderer/components/unimplementedview/Android.mk @@ -21,7 +21,7 @@ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall LOCAL_STATIC_LIBRARIES := -LOCAL_SHARED_LIBRARIES := libyoga libfolly_futures glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libreact_debug +LOCAL_SHARED_LIBRARIES := libjsi libyoga libfolly_futures glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libreact_debug include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/react/renderer/components/view/Android.mk b/ReactCommon/react/renderer/components/view/Android.mk index 877f17bd1c84..1e05d18f6b02 100644 --- a/ReactCommon/react/renderer/components/view/Android.mk +++ b/ReactCommon/react/renderer/components/view/Android.mk @@ -21,7 +21,7 @@ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall LOCAL_STATIC_LIBRARIES := -LOCAL_SHARED_LIBRARIES := libyoga glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics libreact_debug logger +LOCAL_SHARED_LIBRARIES := libyoga glog libfolly_json libglog_init libreact_render_core libreact_render_debug libreact_render_graphics libreact_debug logger libjsi include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/react/renderer/core/Android.mk b/ReactCommon/react/renderer/core/Android.mk index 9ae13e652c01..32a8ddf5efe2 100644 --- a/ReactCommon/react/renderer/core/Android.mk +++ b/ReactCommon/react/renderer/core/Android.mk @@ -15,7 +15,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../ -LOCAL_SHARED_LIBRARIES := libfolly_json libjsi libfolly_futures libreact_utils libreact_debug libreact_render_debug libreact_render_graphics +LOCAL_SHARED_LIBRARIES := libfolly_json libjsi libfolly_futures libreact_utils libreact_debug libreact_render_debug libreact_render_graphics libglog LOCAL_CFLAGS := \ -DLOG_TAG=\"Fabric\" diff --git a/ReactCommon/react/renderer/mounting/Android.mk b/ReactCommon/react/renderer/mounting/Android.mk index d8a4360c17ed..f1383e722e4e 100644 --- a/ReactCommon/react/renderer/mounting/Android.mk +++ b/ReactCommon/react/renderer/mounting/Android.mk @@ -21,7 +21,7 @@ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall LOCAL_STATIC_LIBRARIES := -LOCAL_SHARED_LIBRARIES := libbetter libyoga libfolly_futures glog libfolly_json libglog_init libreact_render_core libreact_render_debug librrc_view librrc_root libreact_utils libreact_debug libreact_render_telemetry +LOCAL_SHARED_LIBRARIES := libjsi libbetter libyoga libfolly_futures glog libfolly_json libglog_init libreact_render_core libreact_render_debug librrc_view librrc_root libreact_utils libreact_debug libreact_render_telemetry include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/react/renderer/runtimescheduler/Android.mk b/ReactCommon/react/renderer/runtimescheduler/Android.mk index 2e81b329eab5..010cced3849e 100644 --- a/ReactCommon/react/renderer/runtimescheduler/Android.mk +++ b/ReactCommon/react/renderer/runtimescheduler/Android.mk @@ -15,7 +15,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../ -LOCAL_SHARED_LIBRARIES := libruntimeexecutor libreact_render_core libreact_debug +LOCAL_SHARED_LIBRARIES := libruntimeexecutor libreact_render_core libreact_debug libjsi LOCAL_CFLAGS := \ -DLOG_TAG=\"Fabric\" diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js index 4298a8d16d37..a893fea829f1 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js @@ -80,9 +80,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(LOCAL_PATH)/reac LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/${libraryName} -LOCAL_SHARED_LIBRARIES := libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug - -LOCAL_STATIC_LIBRARIES := libjsi +LOCAL_SHARED_LIBRARIES := libjsi libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug LOCAL_CFLAGS := \\ -DLOG_TAG=\\"ReactNative\\" diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap index 6bb1b8b9a948..5f68533849b1 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap @@ -52,9 +52,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(LOCAL_PATH)/reac LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/complex_objects -LOCAL_SHARED_LIBRARIES := libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug - -LOCAL_STATIC_LIBRARIES := libjsi +LOCAL_SHARED_LIBRARIES := libjsi libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -118,9 +116,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(LOCAL_PATH)/reac LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/empty_native_modules -LOCAL_SHARED_LIBRARIES := libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug - -LOCAL_STATIC_LIBRARIES := libjsi +LOCAL_SHARED_LIBRARIES := libjsi libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -184,9 +180,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(LOCAL_PATH)/reac LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/native_modules_with_type_aliases -LOCAL_SHARED_LIBRARIES := libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug - -LOCAL_STATIC_LIBRARIES := libjsi +LOCAL_SHARED_LIBRARIES := libjsi libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -258,9 +252,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(LOCAL_PATH)/reac LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/real_module_example -LOCAL_SHARED_LIBRARIES := libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug - -LOCAL_STATIC_LIBRARIES := libjsi +LOCAL_SHARED_LIBRARIES := libjsi libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -324,9 +316,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(LOCAL_PATH)/reac LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/simple_native_modules -LOCAL_SHARED_LIBRARIES := libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug - -LOCAL_STATIC_LIBRARIES := libjsi +LOCAL_SHARED_LIBRARIES := libjsi libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -398,9 +388,7 @@ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(LOCAL_PATH)/reac LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/two_modules_different_files -LOCAL_SHARED_LIBRARIES := libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug - -LOCAL_STATIC_LIBRARIES := libjsi +LOCAL_SHARED_LIBRARIES := libjsi libglog libfolly_json libyoga libreact_nativemodule_core librrc_view libreact_render_core libreact_render_graphics libreact_debug libreact_render_debug LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" diff --git a/yarn.lock b/yarn.lock index 4b2c41b54f09..c19efec0b0be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3298,9 +3298,9 @@ has@^1.0.3: function-bind "^1.1.1" hermes-engine@~0.8.0: - version "0.8.0" - resolved "https://registry.yarnpkg.com/hermes-engine/-/hermes-engine-0.8.0.tgz#d8e507fbfda66f6bd604f79503b45fded1163296" - integrity sha512-bFxAnIjE8M3cco1uh4HlHME8qmOsPcVS75bQoo/fM3wUzMYxZBL0s1IfePUO+R9IUKoO+pfIpjV2I9ay8w7mqw== + version "0.8.1" + resolved "https://registry.yarnpkg.com/hermes-engine/-/hermes-engine-0.8.1.tgz#b6d0d70508ac5add2d198304502fb968cdecb8b2" + integrity sha512-as9Iccj/qrqqtDmfYUHbOIjt5xsQbUB6pjNIW3i1+RVr+pCAdz5S8/Jry778mz3rJWplYzHWdR1u1xQSYfBRYw== hermes-parser@0.4.7: version "0.4.7" From 7dc22116b077fcc4dc0eb1bdb4e6376c47a16d85 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Sat, 28 Aug 2021 06:58:06 -0700 Subject: [PATCH 033/986] Remove RTTI from LayoutAnimations Summary: changelog: [internal] Remote use of dynamic_cast from LayoutAnimations. Reviewed By: JoshuaGross, cortinico Differential Revision: D30602864 fbshipit-source-id: ce23f9b4a8b4e28d17d2297d64d8e460a1e03472 --- .../LayoutAnimationKeyFrameManager.cpp | 48 ++++++++----------- .../renderer/components/view/ViewShadowNode.h | 2 +- ReactCommon/react/utils/ContextContainer.h | 27 ----------- 3 files changed, 21 insertions(+), 56 deletions(-) diff --git a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp index 928cd1ced077..2467b5fa7f77 100644 --- a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp +++ b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp @@ -1093,13 +1093,11 @@ LayoutAnimationKeyFrameManager::pullTransaction( getComponentDescriptorForShadowView(baselineShadowView) .cloneProps(propsParserContext, viewStart.props, {}); - // Dynamic cast, because - we don't know the type of this - // ShadowNode, it could be Image or Text or something else with - // different base props. - const auto viewProps = - dynamic_cast(props.get()); - if (viewProps != nullptr) { - const_cast(viewProps)->opacity = 0; + if (baselineShadowView.traits.check( + ShadowNodeTraits::Trait::ViewKind)) { + auto const &viewProps = + *std::static_pointer_cast(props); + const_cast(viewProps).opacity = 0; } react_native_assert(props != nullptr); @@ -1118,13 +1116,11 @@ LayoutAnimationKeyFrameManager::pullTransaction( getComponentDescriptorForShadowView(baselineShadowView) .cloneProps(propsParserContext, viewStart.props, {}); - // Dynamic cast, because - we don't know the type of this - // ShadowNode, it could be Image or Text or something else with - // different base props. - const auto viewProps = - dynamic_cast(props.get()); - if (viewProps != nullptr) { - const_cast(viewProps)->transform = + if (baselineShadowView.traits.check( + ShadowNodeTraits::Trait::ViewKind)) { + auto const &viewProps = + *std::static_pointer_cast(props); + const_cast(viewProps).transform = Transform::Scale(isScaleX ? 0 : 1, isScaleY ? 0 : 1, 1); } @@ -1221,13 +1217,11 @@ LayoutAnimationKeyFrameManager::pullTransaction( getComponentDescriptorForShadowView(baselineShadowView) .cloneProps(propsParserContext, viewFinal.props, {}); - // Dynamic cast, because - we don't know the type of this - // ShadowNode, it could be Image or Text or something else with - // different base props. - const auto viewProps = - dynamic_cast(props.get()); - if (viewProps != nullptr) { - const_cast(viewProps)->opacity = 0; + if (baselineShadowView.traits.check( + ShadowNodeTraits::Trait::ViewKind)) { + auto const &viewProps = + *std::static_pointer_cast(props); + const_cast(viewProps).opacity = 0; } react_native_assert(props != nullptr); @@ -1248,13 +1242,11 @@ LayoutAnimationKeyFrameManager::pullTransaction( getComponentDescriptorForShadowView(baselineShadowView) .cloneProps(propsParserContext, viewFinal.props, {}); - // Dynamic cast, because - we don't know the type of this - // ShadowNode, it could be Image or Text or something else with - // different base props. - const auto viewProps = - dynamic_cast(props.get()); - if (viewProps != nullptr) { - const_cast(viewProps)->transform = + if (baselineShadowView.traits.check( + ShadowNodeTraits::Trait::ViewKind)) { + auto const &viewProps = + *std::static_pointer_cast(props); + const_cast(viewProps).transform = Transform::Scale(isScaleX ? 0 : 1, isScaleY ? 0 : 1, 1); } diff --git a/ReactCommon/react/renderer/components/view/ViewShadowNode.h b/ReactCommon/react/renderer/components/view/ViewShadowNode.h index 0ccf2116e447..20ccc04d5f45 100644 --- a/ReactCommon/react/renderer/components/view/ViewShadowNode.h +++ b/ReactCommon/react/renderer/components/view/ViewShadowNode.h @@ -24,7 +24,7 @@ class ViewShadowNode final : public ConcreteViewShadowNode< ViewEventEmitter> { public: static ShadowNodeTraits BaseTraits() { - auto traits = BaseShadowNode::BaseTraits(); + auto traits = ConcreteViewShadowNode::BaseTraits(); traits.set(ShadowNodeTraits::Trait::View); return traits; } diff --git a/ReactCommon/react/utils/ContextContainer.h b/ReactCommon/react/utils/ContextContainer.h index f0e2613fdb99..1431fe1af831 100644 --- a/ReactCommon/react/utils/ContextContainer.h +++ b/ReactCommon/react/utils/ContextContainer.h @@ -45,10 +45,6 @@ class ContextContainer final { std::unique_lock lock(mutex_); instances_.insert({key, std::make_shared(instance)}); - -#ifdef REACT_NATIVE_DEBUG - typeNames_.insert({key, typeid(T).name()}); -#endif } /* @@ -59,10 +55,6 @@ class ContextContainer final { std::unique_lock lock(mutex_); instances_.erase(key); - -#ifdef REACT_NATIVE_DEBUG - typeNames_.erase(key); -#endif } /* @@ -76,11 +68,6 @@ class ContextContainer final { for (auto const &pair : contextContainer.instances_) { instances_.erase(pair.first); instances_.insert(pair); -#ifdef REACT_NATIVE_DEBUG - typeNames_.erase(pair.first); - typeNames_.insert( - {pair.first, contextContainer.typeNames_.at(pair.first)}); -#endif } } @@ -96,11 +83,6 @@ class ContextContainer final { react_native_assert( instances_.find(key) != instances_.end() && "ContextContainer doesn't have an instance for given key."); -#ifdef REACT_NATIVE_DEBUG - react_native_assert( - typeNames_.at(key) == typeid(T).name() && - "ContextContainer stores an instance of different type for given key."); -#endif return *std::static_pointer_cast(instances_.at(key)); } @@ -118,12 +100,6 @@ class ContextContainer final { return {}; } -#ifdef REACT_NATIVE_DEBUG - react_native_assert( - typeNames_.at(key) == typeid(T).name() && - "ContextContainer stores an instance of different type for given key."); -#endif - return *std::static_pointer_cast(iterator->second); } @@ -131,9 +107,6 @@ class ContextContainer final { mutable better::shared_mutex mutex_; // Protected by mutex_`. mutable better::map> instances_; -#ifdef REACT_NATIVE_DEBUG - mutable better::map typeNames_; -#endif }; } // namespace react From b51a99c73cc4fbcbb03c97f92b7f7f166493538f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= Date: Sat, 28 Aug 2021 11:30:25 -0700 Subject: [PATCH 034/986] rn-demo-app: Implement getModuleInstanceFromClass: Summary: While not strictly necessary for rn-demo-app at this point, we do need to provide the `getModuleInstanceFromClass:` implementation to simplify the TurboModule migration process later on. Also, removed some issues in the Xcode project that must have been introduced during a recent rebase (duplicate Embed Pods build phases). Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D30618992 fbshipit-source-id: a9b496cfa0cd34fca6389ddf829613aa13ea409d --- packages/rn-tester/RNTester/AppDelegate.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm index dc5d65c1cfad..74a8c35dd831 100644 --- a/packages/rn-tester/RNTester/AppDelegate.mm +++ b/packages/rn-tester/RNTester/AppDelegate.mm @@ -206,6 +206,7 @@ - (Class)getModuleClassFromName:(const char *)name - (id)getModuleInstanceFromClass:(Class)moduleClass { + // Set up the default RCTImageLoader and RCTNetworking modules. if (moduleClass == RCTImageLoader.class) { return [[moduleClass alloc] initWithRedirectDelegate:nil loadersProvider:^NSArray> *(RCTModuleRegistry * moduleRegistry) { From 53c6494615fcc19e555adf7900cd443b88ce562a Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Sun, 29 Aug 2021 09:30:50 -0700 Subject: [PATCH 035/986] Remount children in scrollView if layout changes Summary: changelog: [internal] Reviewed By: hramos Differential Revision: D30603617 fbshipit-source-id: bc189d4a0a997202e6b2cd5314b997395bcdf7b2 --- .../ScrollView/RCTScrollViewComponentView.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index 885e8636f180..37468a85b11e 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -133,6 +133,15 @@ - (void)dealloc [self.scrollViewDelegateSplitter removeAllDelegates]; } +- (void)layoutSubviews +{ + [super layoutSubviews]; + + if (_subviewClippingEnabled) { + [self _remountChildren]; + } +} + - (RCTGenericDelegateSplitter> *)scrollViewDelegateSplitter { return ((RCTEnhancedScrollView *)_scrollView).delegateSplitter; From 19f8d2f7da13f4524f31acf7aa10cc0aa91b5da4 Mon Sep 17 00:00:00 2001 From: luism3861 Date: Mon, 30 Aug 2021 10:16:34 -0700 Subject: [PATCH 036/986] docs: add new version convenant contribuitor guide link (#32107) Summary: ## Summary this PR update available link version in Contributor Covenant.! cc: yungsters Changelog: [General][Changed] Updated to Contributor Covenant v2.1 Pull Request resolved: https://github.com/facebook/react-native/pull/32107 Reviewed By: lunaleaps Differential Revision: D30616702 Pulled By: yungsters fbshipit-source-id: b79b07cfa14154fbe948e7bb4d6698925be2cdd4 --- CODE_OF_CONDUCT.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index d1abc700d28d..3a44dc2513d1 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -67,8 +67,8 @@ members of the project's leadership. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, +available at https://www.contributor-covenant.org/version/2/1/code_of_conduct/ [homepage]: https://www.contributor-covenant.org From de1a72acaeea45f5ea9c717b64b193879b4bc628 Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Mon, 30 Aug 2021 16:31:04 -0700 Subject: [PATCH 037/986] move prettier to peerDeps in eslint-config-react-native-community (#28637) Summary: In monorepo environment, prettier-plugin in some editor load from nearest `node_modules`. Older version of eslint-config-react-native-community includes prettier v1 in their dependencies. It cause conflict of code style inside the monorepo. ## Changelog [Internal] [Fixed] - move prettier to peerDependencies in eslint-config-react-native-community Pull Request resolved: https://github.com/facebook/react-native/pull/28637 Test Plan: I think it would be good with no plan to test. Reviewed By: yungsters Differential Revision: D30648134 Pulled By: charlesbdudley fbshipit-source-id: 6c01226d6e4cc37ddbc86be260563deb093758d0 --- packages/eslint-config-react-native-community/package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/eslint-config-react-native-community/package.json b/packages/eslint-config-react-native-community/package.json index ef00ef62dff9..5c59f9ead21b 100644 --- a/packages/eslint-config-react-native-community/package.json +++ b/packages/eslint-config-react-native-community/package.json @@ -26,9 +26,11 @@ "prettier": "^2.0.2" }, "peerDependencies": { - "eslint": ">=7" + "eslint": ">=7", + "prettier": ">=2" }, "devDependencies": { - "eslint": "7.12.0" + "eslint": "7.12.0", + "prettier": "^2.3.2" } } From 49b3b31d8e706338dac4ced1b372424d7d1d133f Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Mon, 30 Aug 2021 18:02:02 -0700 Subject: [PATCH 038/986] Native component check in deprecatedPropType was inverted (#31164) Summary: While investigating an issue hit on a recent sync of [react-native-windows](https://github.com/microsoft/react-native-windows) I noticed that https://github.com/facebook/react-native/commit/e68cf7cee9d36271a1d3899fecff817304bb8bdc appears to have accidently inverted the logic to avoid checking native components. `!UIManager.getViewManagerConfig(componentName)` become `UIManager.hasViewManagerConfig(componentName)` losing the ! Also adding a check in PaperUIManager's getViewManagerConfig to avoid trying to call a sync method when using Chrome Debugging. ## Changelog [Internal] [Fixed] - Restored the previous logic of deprecatedPropType Pull Request resolved: https://github.com/facebook/react-native/pull/31164 Test Plan: Change tested and being submitted in react-native-windows: https://github.com/microsoft/react-native-windows/pull/7397 Reviewed By: hramos Differential Revision: D30624302 Pulled By: fkgozali fbshipit-source-id: 0f26e750283a1fa5eb5f44ecd2cf90617b6d931f --- Libraries/ReactNative/PaperUIManager.js | 1 + Libraries/Utilities/deprecatedPropType.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/ReactNative/PaperUIManager.js b/Libraries/ReactNative/PaperUIManager.js index c468958e5663..87cc101db310 100644 --- a/Libraries/ReactNative/PaperUIManager.js +++ b/Libraries/ReactNative/PaperUIManager.js @@ -34,6 +34,7 @@ function getConstants(): Object { function getViewManagerConfig(viewManagerName: string): any { if ( viewManagerConfigs[viewManagerName] === undefined && + global.nativeCallSyncHook && // If we're in the Chrome Debugger, let's not even try calling the sync method NativeUIManager.getConstantsForViewManager ) { try { diff --git a/Libraries/Utilities/deprecatedPropType.js b/Libraries/Utilities/deprecatedPropType.js index 1801f98cb1c2..0a0fc69aab2a 100644 --- a/Libraries/Utilities/deprecatedPropType.js +++ b/Libraries/Utilities/deprecatedPropType.js @@ -21,7 +21,7 @@ function deprecatedPropType( // Don't warn for native components. if ( global.RN$Bridgeless !== true && - UIManager.hasViewManagerConfig(componentName) && + !UIManager.hasViewManagerConfig(componentName) && props[propName] !== undefined ) { console.warn( From cbe0e6bf27c0dddfdba627f66c4b8db69c534743 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Mon, 30 Aug 2021 20:02:00 -0700 Subject: [PATCH 039/986] Pass nativeTimestamp into PressabilityPerformanceEvent Summary: Pass nativeTimestamp into PressabilityPerformanceEvent as a way to uniquely identify events. Changelog: [Internal] Differential Revision: D30648544 fbshipit-source-id: 7cb0146f6ff1655f1312e5094535e59268fb2a22 --- Libraries/Pressability/Pressability.js | 1 + Libraries/Pressability/PressabilityPerformanceEventEmitter.js | 1 + 2 files changed, 2 insertions(+) diff --git a/Libraries/Pressability/Pressability.js b/Libraries/Pressability/Pressability.js index 9ffab69aa01c..2c43fe6cd1fa 100644 --- a/Libraries/Pressability/Pressability.js +++ b/Libraries/Pressability/Pressability.js @@ -631,6 +631,7 @@ export default class Pressability { PressabilityPerformanceEventEmitter.emitEvent(() => { return { signal, + nativeTimestamp: event.nativeEvent.timestamp, touchDelayMs: Date.now() - event.nativeEvent.timestamp, }; }); diff --git a/Libraries/Pressability/PressabilityPerformanceEventEmitter.js b/Libraries/Pressability/PressabilityPerformanceEventEmitter.js index 832b1ee270e7..302baf5e8744 100644 --- a/Libraries/Pressability/PressabilityPerformanceEventEmitter.js +++ b/Libraries/Pressability/PressabilityPerformanceEventEmitter.js @@ -12,6 +12,7 @@ import {type PressabilityTouchSignal as TouchSignal} from './PressabilityTypes.j export type PressabilityPerformanceEvent = $ReadOnly<{| signal: TouchSignal, + nativeTimestamp: number, touchDelayMs: number, |}>; export type PressabilityPerformanceEventListener = PressabilityPerformanceEvent => void; From 2e8893fb5be0c877e0818d04264d75fa92ae0f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= Date: Tue, 31 Aug 2021 05:22:01 -0700 Subject: [PATCH 040/986] Replace envvars with required params in codegen script and add Fabric output overrides Summary: The codegen script now takes parameters for any necessary configuration. Now, there are three *required* parameters: JS_SRCS_DIR, LIBRARY_NAME, and OUTPUT_DIR. By default, all modules and components output will be copied to the OUTPUT_DIR under a single LIBRARY_NAME. If a fourth argument is provided, this COMPONENT_LIBRARY_NAME will be used for the component library name. If a fifth argument is provided, this COMPONENT_OUTPUT_DIR will be used as the output directory for the component library. These last two arguments are used to build the core FBReactNativeSpec modules and rncore components libraries. Eventually, all module and component output will be part of a single library, but for the time being we need to keep these apart for the core modules and components. The script will output usage instructions if no argument is provided: ``` ./scripts/generate-specs.sh NAME ./scripts/generate-specs.sh -- generate specs SYNOPSIS ./scripts/generate-specs.sh javascript_sources_directory specs_library_name output_directory ./scripts/generate-specs.sh javascript_sources_directory specs_library_name output_directory component_library_name [component_output_directory] DESCRIPTION In the first synopsis form, this script collects native module and native component JavaScript spec definitions in javascript_sources_directory, then uses react-native-codegen to generate the native interface code into a library named specs_library_name, which is copied to the destination output_directory. In the second synopsis form, the component_library_name will be used as the name of the component native interface code library. If provided, the component output will be copied to the component_output_directory, otherwise it will be copied to the output_directory. ``` With these changes, `codegen.js` became redundant and has been removed. Changelog: [Internal] - Codegen script interface changes. Reviewed By: fkgozali Differential Revision: D30626294 fbshipit-source-id: 475c29242497db5f93213aa64ca9b7c480140d55 --- .../FBReactNativeSpec.podspec | 14 ++- scripts/codegen.js | 54 ----------- scripts/generate-specs.sh | 91 +++++++++++++------ scripts/react_native_pods.rb | 58 ++++++------ 4 files changed, 103 insertions(+), 114 deletions(-) delete mode 100644 scripts/codegen.js diff --git a/React/FBReactNativeSpec/FBReactNativeSpec.podspec b/React/FBReactNativeSpec/FBReactNativeSpec.podspec index 32a4bf8cb419..bdbf1023319e 100644 --- a/React/FBReactNativeSpec/FBReactNativeSpec.podspec +++ b/React/FBReactNativeSpec/FBReactNativeSpec.podspec @@ -4,7 +4,9 @@ # LICENSE file in the root directory of this source tree. require "json" -require_relative "../../scripts/react_native_pods.rb" + +react_native_path = "../.." +require_relative "#{react_native_path}/scripts/react_native_pods.rb" package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json"))) version = package['version'] @@ -46,5 +48,13 @@ Pod::Spec.new do |s| s.dependency "React-jsi", version s.dependency "ReactCommon/turbomodule/core", version - use_react_native_codegen! (s) + use_react_native_codegen!(s, { + :react_native_path => react_native_path, + :js_srcs_dir => "#{react_native_path}/Libraries", + :library_name => "FBReactNativeSpec", + :output_dir => "#{react_native_path}/React/FBReactNativeSpec", + :component_library_name => "rncore", + # TODO: component_output_dir should be programmatically specified, and may change with use_frameworks! support. + :component_output_dir => "#{react_native_path}/ReactCommon/react/renderer/components/" + }) end diff --git a/scripts/codegen.js b/scripts/codegen.js deleted file mode 100644 index 12ff0917dd66..000000000000 --- a/scripts/codegen.js +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env node -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -'use strict'; - -require('shelljs/global'); -const yargs = require('yargs'); -const execSync = require('child_process').execSync; - -let argv = yargs.option('srcs', { - alias: 'srcs_dir', - type: 'string', - description: 'Path to JavaScript sources', -}).option('modules_library_name', { - type: 'string', - description: 'Native modules interfaces library name', -}).option('modules_output_dir', { - type: 'string', - description: 'Native modules interfaces output dir', -}).option('components_library_name', { - type: 'string', - description: 'Native components interfaces library name', -}).option('components_output_dir', { - type: 'string', - description: 'Native components interfaces output dir', -}).argv; - -let env_vars = []; -const { srcs_dir, modules_library_name, modules_output_dir, components_library_name, components_output_dir } = argv; - -if (srcs_dir) { - env_vars.push(`SRCS_DIR=${srcs_dir}`); -} -if (modules_library_name) { - env_vars.push(`MODULES_LIBRARY_NAME=${modules_library_name}`); -} -if (modules_output_dir) { - env_vars.push(`MODULES_OUTPUT_DIR=${modules_output_dir}`); -} -if (components_library_name) { - env_vars.push(`COMPONENTS_LIBRARY_NAME=${components_library_name}`); -} -if (components_output_dir) { - env_vars.push(`COMPONENTS_OUTPUT_DIR=${components_output_dir}`); -} - -execSync(`${env_vars.join(' ')} ./generate-specs.sh`); diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index 4456557dfbb6..d3ea448e1759 100755 --- a/scripts/generate-specs.sh +++ b/scripts/generate-specs.sh @@ -4,20 +4,12 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -# This script collects the JavaScript spec definitions for core +# This script collects the JavaScript spec definitions for # native modules and components, then uses react-native-codegen # to generate native code. # -# Optionally, set these envvars to override defaults: -# - SRCS_DIR: Path to JavaScript sources -# - MODULES_LIBRARY_NAME: Defaults to FBReactNativeSpec -# - MODULES_OUTPUT_DIR: Defaults to React/$MODULES_LIBRARY_NAME/$MODULES_LIBRARY_NAME -# - COMPONENTS_LIBRARY_NAME: Defaults to rncore -# - COMPONENTS_OUTPUT_DIR: Defaults to ReactCommon/react/renderer/components/$COMPONENTS_LIBRARY_NAME -# # Usage: # ./scripts/generate-specs.sh -# SRCS_DIR=myapp/js MODULES_LIBRARY_NAME=MySpecs MODULES_OUTPUT_DIR=myapp/MySpecs ./scripts/generate-specs.sh # # shellcheck disable=SC2038 @@ -44,27 +36,45 @@ describe () { printf "\\n\\n>>>>> %s\\n\\n\\n" "$1" >&2 } +print_usage () { + printf "\\nNAME\\n\\t%s -- generate specs\\n" "$1" >&2 + printf "\\nSYNOPSIS\\n" >&2 + printf "\\t%s javascript_sources_directory specs_library_name output_directory\\n" "$1" >&2 + printf "\\t%s javascript_sources_directory specs_library_name output_directory component_library_name [component_output_directory]\\n" "$1" >&2 + printf "\\n\\nDESCRIPTION\\n\\tIn the first synopsis form, this script collects native module and native component JavaScript spec definitions in javascript_sources_directory, then uses react-native-codegen to generate the native interface code into a library named specs_library_name, which is copied to the destination output_directory.\\n" >&2 + printf "\\n\\tIn the second synopsis form, the component_library_name will be used as the name of the component native interface code library. If provided, the component output will be copied to the component_output_directory, otherwise it will be copied to the output_directory.\\n" >&2 +} + main() { - SRCS_DIR=${SRCS_DIR:-$(cd "$RN_DIR/Libraries" && pwd)} - MODULES_LIBRARY_NAME=${MODULES_LIBRARY_NAME:-FBReactNativeSpec} + MIN_ARG_NUM=3 + if [ "$#" -eq 0 ]; then + print_usage "$0" + exit 1 + fi + + if [ -z "$NODE_BINARY" ]; then + echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2 + exit 1 + fi + + if [ "$#" -lt "$MIN_ARG_NUM" ]; then + echo "Error: Expected $MIN_ARG_NUM arguments, got $# instead. Run $0 with no arguments to learn more." 1>&2 + exit 1 + fi - COMPONENTS_LIBRARY_NAME=${COMPONENTS_LIBRARY_NAME:-rncore} - MODULES_OUTPUT_DIR=${MODULES_OUTPUT_DIR:-"$RN_DIR/React/$MODULES_LIBRARY_NAME/$MODULES_LIBRARY_NAME"} - # TODO: $COMPONENTS_PATH should be programmatically specified, and may change with use_frameworks! support. - COMPONENTS_PATH="ReactCommon/react/renderer/components" - COMPONENTS_OUTPUT_DIR=${COMPONENTS_OUTPUT_DIR:-"$RN_DIR/$COMPONENTS_PATH/$COMPONENTS_LIBRARY_NAME"} + SRCS_DIR=$1 + LIBRARY_NAME=$2 + OUTPUT_DIR=$3 + COMPONENT_LIBRARY_NAME_OVERRIDE=$4 + COMPONENT_OUTPUT_DIR_OVERRIDE=$5 + PLATFORM="ios" TEMP_OUTPUT_DIR="$TEMP_DIR/out" SCHEMA_FILE="$TEMP_DIR/schema.json" CODEGEN_REPO_PATH="$RN_DIR/packages/react-native-codegen" CODEGEN_NPM_PATH="$RN_DIR/../react-native-codegen" - if [ -z "$NODE_BINARY" ]; then - echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2 - exit 1 - fi - if [ -d "$CODEGEN_REPO_PATH" ]; then CODEGEN_PATH=$(cd "$CODEGEN_REPO_PATH" && pwd) elif [ -d "$CODEGEN_NPM_PATH" ]; then @@ -82,15 +92,38 @@ main() { describe "Generating schema from Flow types" "$NODE_BINARY" "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR" - describe "Generating native code from schema (iOS)" - pushd "$RN_DIR" >/dev/null || exit 1 - "$NODE_BINARY" scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$MODULES_LIBRARY_NAME" - popd >/dev/null || exit 1 + describe "Generating native code from schema ($PLATFORM)" + pushd "$RN_DIR" >/dev/null + "$NODE_BINARY" scripts/generate-specs-cli.js "$PLATFORM" "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$LIBRARY_NAME" + popd >/dev/null + + + mkdir -p "$OUTPUT_DIR" - mkdir -p "$COMPONENTS_OUTPUT_DIR" "$MODULES_OUTPUT_DIR" - cp -R "$TEMP_OUTPUT_DIR/$MODULES_LIBRARY_NAME.h" "$TEMP_OUTPUT_DIR/$MODULES_LIBRARY_NAME-generated.mm" "$MODULES_OUTPUT_DIR" || exit 1 - find "$TEMP_OUTPUT_DIR" -type f | xargs sed -i.bak "s/$MODULES_LIBRARY_NAME/$COMPONENTS_LIBRARY_NAME/g" || exit 1 - find "$TEMP_OUTPUT_DIR" -type f -not -iname "$MODULES_LIBRARY_NAME*" -exec cp '{}' "$COMPONENTS_OUTPUT_DIR/" ';' || exit 1 + if [ -z "$COMPONENT_LIBRARY_NAME_OVERRIDE" ]; then + # Copy all output to output_dir + cp -R "$TEMP_OUTPUT_DIR/" "$OUTPUT_DIR" + echo >&2 "$LIBRARY_NAME output has been written to $OUTPUT_DIR:" + ls -1 "$OUTPUT_DIR" 2>&1 + else + # Copy modules output to output_dir + cp "$TEMP_OUTPUT_DIR/$LIBRARY_NAME.h" "$TEMP_OUTPUT_DIR/$LIBRARY_NAME-generated.mm" "$OUTPUT_DIR" + echo >&2 "$LIBRARY_NAME output has been written to $OUTPUT_DIR:" + ls -1 "$OUTPUT_DIR" 2>&1 + + # Rename library name used in components output files + find "$TEMP_OUTPUT_DIR" -type f | xargs sed -i.bak "s/$LIBRARY_NAME/$COMPONENT_LIBRARY_NAME_OVERRIDE/g" + + if [ -n "$COMPONENT_OUTPUT_DIR_OVERRIDE" ]; then + # Components codegen output to be moved to separate directory + mkdir -p "$COMPONENT_OUTPUT_DIR_OVERRIDE" + OUTPUT_DIR="$COMPONENT_OUTPUT_DIR_OVERRIDE" + fi + + find "$TEMP_OUTPUT_DIR" -type f -not -iname "$LIBRARY_NAME.h" -not -iname "$LIBRARY_NAME-generated.mm" -not -iname "*.bak" -exec cp '{}' "$OUTPUT_DIR/" ';' + echo >&2 "$COMPONENT_LIBRARY_NAME_OVERRIDE output has been written to $OUTPUT_DIR:" + ls -1 "$OUTPUT_DIR" 2>&1 + fi echo >&2 'Done.' } diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index a4131f3ec299..02b04e1e4f75 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -161,38 +161,38 @@ def use_react_native_codegen!(spec, options={}) js_srcs = options[:js_srcs_dir] ||= "#{prefix}/Libraries" # Library name (e.g. FBReactNativeSpec) - modules_library_name = options[:library_name] ||= spec.name + library_name = options[:library_name] ||= "#{spec.name}Spec" # Output dir, relative to podspec that invoked this method - modules_output_dir = options[:modules_output_dir] ||= "#{prefix}/React/#{modules_library_name}/#{modules_library_name}" + output_dir = options[:output_dir] ||= "#{prefix}/React/#{library_name}" - generated_dirs = [ modules_output_dir ] - generated_filenames = [ "#{modules_library_name}.h", "#{modules_library_name}-generated.mm" ] - generated_files = generated_filenames.map { |filename| "#{modules_output_dir}/#{filename}" } + generated_dirs = [ "#{output_dir}/#{library_name}" ] + generated_filenames = [ "#{library_name}.h", "#{library_name}-generated.mm" ] + generated_files = generated_filenames.map { |filename| "#{output_dir}/#{library_name}/#{filename}" } # Run the codegen as part of the Xcode build pipeline. - env_vars = "SRCS_DIR='${PODS_TARGET_SRCROOT}/#{js_srcs}'" - env_vars += " MODULES_OUTPUT_DIR='${PODS_TARGET_SRCROOT}/#{modules_output_dir}'" - env_vars += " MODULES_LIBRARY_NAME='#{modules_library_name}'" - - if ENV['USE_FABRIC'] == '1' - # We use a different library name for components, as well as an additional set of files. - # Eventually, we want these to be part of the same library as #{modules_library_name} above. - components_output_dir = options[:components_output_dir] ||= "#{prefix}/ReactCommon/react/renderer/components/rncore/" - generated_dirs.push components_output_dir - env_vars += " COMPONENTS_OUTPUT_DIR='${PODS_TARGET_SRCROOT}/#{components_output_dir}'" - components_generated_filenames = [ - "ComponentDescriptors.h", - "EventEmitters.cpp", - "EventEmitters.h", - "Props.cpp", - "Props.h", - "RCTComponentViewHelpers.h", - "ShadowNodes.cpp", - "ShadowNodes.h" - ] - generated_files = generated_files.concat(components_generated_filenames.map { |filename| "#{components_output_dir}/#{filename}" }) - end + codegen_script_args = [ "'${PODS_TARGET_SRCROOT}/#{js_srcs}'" ] + codegen_script_args.push "'#{library_name}'" + codegen_script_args.push "'${PODS_TARGET_SRCROOT}/#{output_dir}/#{library_name}'" + + # We use a different library name for components, as well as an additional set of files. + # Eventually, we want these to be part of the same library as #{library_name} above. + component_library_name = options[:component_library_name] ||= library_name + component_output_dir = options[:component_output_dir] ||= output_dir + generated_dirs.push "#{component_output_dir}/#{component_library_name}" + codegen_script_args.push "'#{component_library_name}'" + codegen_script_args.push "'${PODS_TARGET_SRCROOT}/#{component_output_dir}/#{component_library_name}'" + components_generated_filenames = [ + "ComponentDescriptors.h", + "EventEmitters.cpp", + "EventEmitters.h", + "Props.cpp", + "Props.h", + "RCTComponentViewHelpers.h", + "ShadowNodes.cpp", + "ShadowNodes.h" + ] + generated_files = generated_files.concat(components_generated_filenames.map { |filename| "#{component_output_dir}/#{component_library_name}/#{filename}" }) # Prepare filesystem by creating empty files that will be picked up as references by CocoaPods. prepare_command = "mkdir -p #{generated_dirs.join(" ")} && touch -a #{generated_files.join(" ")}" @@ -202,11 +202,11 @@ def use_react_native_codegen!(spec, options={}) spec.script_phase = { :name => 'Generate Specs', :input_files => [ "${PODS_TARGET_SRCROOT}/#{js_srcs}" ], # This also needs to be relative to Xcode - :output_files => ["${DERIVED_FILE_DIR}/codegen-#{modules_library_name}.log"].concat(generated_files.map { |filename| " ${PODS_TARGET_SRCROOT}/#{filename}"} ), + :output_files => ["${DERIVED_FILE_DIR}/codegen-#{library_name}.log"].concat(generated_files.map { |filename| " ${PODS_TARGET_SRCROOT}/#{filename}"} ), # The final generated files will be created when this script is invoked at Xcode build time. :script => %{set -o pipefail -bash -l -c '#{env_vars} $\{PODS_TARGET_SRCROOT\}/#{prefix}/scripts/generate-specs.sh' 2>&1 | tee "${SCRIPT_OUTPUT_FILE_0}" +bash -l -c '$\{PODS_TARGET_SRCROOT\}/#{prefix}/scripts/generate-specs.sh #{codegen_script_args.join(" ")}' 2>&1 | tee "${SCRIPT_OUTPUT_FILE_0}" }, :execution_position => :before_compile, :show_env_vars_in_log => true From 24a9ef7384b776ff0ab75be043e934591bb8d319 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 31 Aug 2021 09:51:58 -0700 Subject: [PATCH 041/986] Suppressing bad file descriptor errors on native builds Summary: When running native builds, we experience a lot of bad file descriptor warnings. This diff is suppressing the issue on local builds (on Mac). Changelog: [Internal] [Changed] - Suppressed bad file descriptor on native builds Reviewed By: ShikaSD Differential Revision: D30487098 fbshipit-source-id: 8199fb8f2f18d19543d2861f1f2f852fff6ae73b --- ReactAndroid/build.gradle | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index edadad219f3b..8db3196c6bca 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -362,7 +362,8 @@ def buildReactNdkLib = tasks.register("buildReactNdkLib", Exec) { inputs.dir("src/main/java/com/facebook/react/turbomodule/core/jni") inputs.dir("src/main/java/com/facebook/react/modules/blob") outputs.dir("$buildDir/react-ndk/all") - commandLine(getNdkBuildFullPath(), + def commandLineArgs = [ + getNdkBuildFullPath(), "APP_ABI=${reactNativeArchitectures()}", "NDK_DEBUG=" + (nativeBuildType.equalsIgnoreCase("debug") ? "1" : "0"), "NDK_PROJECT_PATH=null", @@ -375,7 +376,12 @@ def buildReactNdkLib = tasks.register("buildReactNdkLib", Exec) { "REACT_SRC_DIR=$projectDir/src/main/java/com/facebook/react", "-C", file("src/main/jni/react/jni").absolutePath, "--jobs", project.findProperty("jobs") ?: Runtime.runtime.availableProcessors() - ) + ] + if (Os.isFamily(Os.FAMILY_MAC)) { + // This flag will suppress "fcntl(): Bad file descriptor" warnings on local builds. + commandLineArgs.add("--output-sync=none") + } + commandLine(commandLineArgs) } def cleanReactNdkLib = tasks.register("cleanReactNdkLib", Exec) { From 85249cafe8870ab8f47c38569b106555ce2f8527 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 31 Aug 2021 12:48:55 -0700 Subject: [PATCH 042/986] Update project to build on Gradle 7.0.2 (#32073) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/32073 This Diff bumps the version of Gradle used to build the project to 7.0.2. Ideally we could bump to 7.2.x directly, but I'll do one minor version at a time to exclude potential build problems. This diff is addressing all the extra build warnings that got raised by the new version. Changelog: [Android][Changed] - Bumped Gradle project version to 7.0.2 Reviewed By: ShikaSD Differential Revision: D30486612 fbshipit-source-id: 70e0f7d18e547013ca7b1d12f8dd64a633df5870 --- ReactAndroid/build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew.bat | 178 +++++++++--------- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../react-native-codegen/android/gradlew.bat | 178 +++++++++--------- .../react/tasks/BundleJsAndAssetsTask.kt | 7 +- .../facebook/react/tasks/HermesBinaryTask.kt | 6 +- packages/rn-tester/android/app/build.gradle | 1 + 8 files changed, 191 insertions(+), 185 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 8db3196c6bca..7d2e903790e3 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -56,7 +56,6 @@ task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) { task prepareBoost(dependsOn: boostPath ? [] : [downloadBoost], type: Copy) { from(boostPath ?: tarTree(resources.gzip(downloadBoost.dest))) - from("src/main/jni/third-party/boost/Android.mk") from("src/main/jni/third-party/boost") include("Android.mk", "boost_${BOOST_VERSION}/boost/**/*.hpp", "boost/boost/**/*.hpp", "asm/**/*.S") includeEmptyDirs = false @@ -171,6 +170,7 @@ task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) { // Prepare glog sources to be compiled, this task will perform steps that normally should've been // executed by automake. This way we can avoid dependencies on make/automake task prepareGlog(dependsOn: dependenciesPath ? [] : [downloadGlog], type: Copy) { + duplicatesStrategy("warn") from(dependenciesPath ?: tarTree(downloadGlog.dest)) from("src/main/jni/third-party/glog/") include("glog-${GLOG_VERSION}/src/**/*", "Android.mk", "config.h") diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7665b0fa93ae..29e413457635 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew.bat b/gradlew.bat index 107acd32c4e6..ac1b06f93825 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,89 +1,89 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/packages/react-native-codegen/android/gradle/wrapper/gradle-wrapper.properties b/packages/react-native-codegen/android/gradle/wrapper/gradle-wrapper.properties index 7665b0fa93ae..29e413457635 100644 --- a/packages/react-native-codegen/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/react-native-codegen/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/packages/react-native-codegen/android/gradlew.bat b/packages/react-native-codegen/android/gradlew.bat index 107acd32c4e6..ac1b06f93825 100644 --- a/packages/react-native-codegen/android/gradlew.bat +++ b/packages/react-native-codegen/android/gradlew.bat @@ -1,89 +1,89 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleJsAndAssetsTask.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleJsAndAssetsTask.kt index 086f2515f98d..300774a48a0c 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleJsAndAssetsTask.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleJsAndAssetsTask.kt @@ -11,13 +11,16 @@ import java.io.File import org.gradle.api.DefaultTask import org.gradle.api.file.FileTree import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction open class BundleJsAndAssetsTask : DefaultTask() { - internal lateinit var reactRoot: File + + @get:Internal internal lateinit var reactRoot: File @get:InputFiles @Suppress("UNUSED") // used to invalidate caches @@ -25,7 +28,7 @@ open class BundleJsAndAssetsTask : DefaultTask() { @get:Input internal lateinit var execCommand: List @get:Input internal lateinit var bundleCommand: String @get:Input internal var devEnabled: Boolean = true - @get:Input internal lateinit var entryFile: File + @get:InputFile internal lateinit var entryFile: File @get:Input internal var extraArgs: List = emptyList() @get:OutputDirectory internal lateinit var jsBundleDir: File diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/HermesBinaryTask.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/HermesBinaryTask.kt index 0e641dea7ad8..af3ae0fe5ebd 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/HermesBinaryTask.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/HermesBinaryTask.kt @@ -11,18 +11,20 @@ import java.io.File import org.gradle.api.DefaultTask import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction open class HermesBinaryTask : DefaultTask() { - internal lateinit var reactRoot: File + + @get:Internal internal lateinit var reactRoot: File @get:Input internal lateinit var hermesCommand: String @get:Input internal var hermesFlags: List = emptyList() @get:InputFile internal lateinit var jsBundleFile: File @get:Input internal lateinit var composeSourceMapsCommand: List - @get:Input internal lateinit var jsPackagerSourceMapFile: File + @get:InputFile internal lateinit var jsPackagerSourceMapFile: File @get:OutputFile internal lateinit var jsCompilerSourceMapFile: File @get:OutputFile internal lateinit var jsOutputSourceMapFile: File diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 7f04213604bf..503ada4fd87e 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -288,6 +288,7 @@ if (enableCodegen) { def packageReactNdkLibs = tasks.register("packageReactNdkLibs", Copy) { // TODO: handle extracting .so from prebuilt :ReactAndroid. dependsOn(":ReactAndroid:packageReactNdkLibs") + dependsOn("generateCodegenSchemaFromJavaScript") from("$reactAndroidBuildDir/react-ndk/exported") into("$buildDir/react-ndk/exported") } From 13107fa3d0bcb41d1e91d676f2886c575c599bc2 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 31 Aug 2021 12:48:55 -0700 Subject: [PATCH 043/986] Import template/android/ as part of the top level build (#32124) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/32124 This Diff adds `template/android/` as part of the top level build as an included build. This means that the Android template will be loaded inside Android studio and it will be easier to invoke tasks directly there. I'm also bumping Gradle to 7.0.2 for the template. Please note that the template relies on the `template/node_modules` folder to work correctly, as the Gradle build is loading a file from there. Therefore I've added a check to verify that we import the build only if `node_modules` is available. Changelog: [Internal] [Changed] - Load template/android/ inside the build. Reviewed By: ShikaSD Differential Revision: D30672845 fbshipit-source-id: 7253296b54e1fde7448e0e170d59b244ed9ec8fb --- .gitignore | 2 + settings.gradle.kts | 7 + .../gradle/wrapper/gradle-wrapper.properties | 2 +- template/android/gradlew.bat | 178 +++++++++--------- 4 files changed, 99 insertions(+), 90 deletions(-) diff --git a/.gitignore b/.gitignore index de6bcc3d45d9..ecfa96ceaa29 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,8 @@ project.xcworkspace /ReactAndroid/gradle/ /ReactAndroid/gradlew /ReactAndroid/gradlew.bat +/template/android/app/build/ +/template/android/build/ # Buck .buckd diff --git a/settings.gradle.kts b/settings.gradle.kts index 1d838685e259..f804e186f975 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,3 +22,10 @@ include( // Include this to enable codegen Gradle plugin. includeBuild("packages/react-native-codegen/android") includeBuild("packages/react-native-gradle-plugin/") + +// Include this to build the Android template as well and make sure is not broken. +if (File("template/node_modules/").exists()) { + includeBuild("template/android/") { + name = "template-android" + } +} diff --git a/template/android/gradle/wrapper/gradle-wrapper.properties b/template/android/gradle/wrapper/gradle-wrapper.properties index 7665b0fa93ae..29e413457635 100644 --- a/template/android/gradle/wrapper/gradle-wrapper.properties +++ b/template/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/template/android/gradlew.bat b/template/android/gradlew.bat index 107acd32c4e6..ac1b06f93825 100644 --- a/template/android/gradlew.bat +++ b/template/android/gradlew.bat @@ -1,89 +1,89 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega From ed20a851522ba88d0f7108bb8516f62cad383839 Mon Sep 17 00:00:00 2001 From: Matt Oakes Date: Tue, 31 Aug 2021 15:52:20 -0700 Subject: [PATCH 044/986] Bump the version of @react-native-community/eslint-config (#32117) Summary: The version of this package needs to be bumped for me to release the changes from https://github.com/facebook/react-native/issues/28637 to NPM. ## Changelog [Internal] [Added] - Bump react-native-community/eslint-config version Pull Request resolved: https://github.com/facebook/react-native/pull/32117 Test Plan: N/A Reviewed By: cortinico Differential Revision: D30663708 Pulled By: yungsters fbshipit-source-id: f433c324f12663d76e55c9395630cd642955b25e --- packages/eslint-config-react-native-community/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-react-native-community/package.json b/packages/eslint-config-react-native-community/package.json index 5c59f9ead21b..bf80d296770f 100644 --- a/packages/eslint-config-react-native-community/package.json +++ b/packages/eslint-config-react-native-community/package.json @@ -1,6 +1,6 @@ { "name": "@react-native-community/eslint-config", - "version": "3.0.0", + "version": "3.0.1", "description": "ESLint config for React Native", "main": "index.js", "license": "MIT", From 6651d8c34680a0104c31abe65223d55cce237f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= Date: Tue, 31 Aug 2021 16:18:41 -0700 Subject: [PATCH 045/986] Enable codegen in RNTester's NativeModuleExample Summary: Create a ScreenshotManager.podspec (codegen recipe included) and add ScreenshotManager Pod to the Podfile. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D30623054 fbshipit-source-id: be20880a53ba8a08f8b42b8d81c868c8a21960e1 --- .gitignore | 1 + .../ScreenshotManager.podspec | 39 +++++++++++++++++++ packages/rn-tester/Podfile | 3 ++ packages/rn-tester/Podfile.lock | 9 ++++- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 packages/rn-tester/NativeModuleExample/ScreenshotManager.podspec diff --git a/.gitignore b/.gitignore index ecfa96ceaa29..747bb762be95 100644 --- a/.gitignore +++ b/.gitignore @@ -105,6 +105,7 @@ package-lock.json /React/FBReactNativeSpec/FBReactNativeSpec /packages/react-native-codegen/lib /ReactCommon/react/renderer/components/rncore/ +/packages/rn-tester/NativeModuleExample/ScreenshotManagerSpec # Visual studio .vscode diff --git a/packages/rn-tester/NativeModuleExample/ScreenshotManager.podspec b/packages/rn-tester/NativeModuleExample/ScreenshotManager.podspec new file mode 100644 index 000000000000..bfa423f63e04 --- /dev/null +++ b/packages/rn-tester/NativeModuleExample/ScreenshotManager.podspec @@ -0,0 +1,39 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +require "json" + +package = JSON.parse(File.read(File.join(__dir__, "../package.json"))) + +folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' +folly_version = '2021.06.28.00' + +Pod::Spec.new do |s| + s.name = "ScreenshotManager" + s.version = package["version"] + s.summary = package["description"] + s.description = "ScreenshotManager" + s.homepage = "https://github.com/facebook/react-native.git" + s.license = "MIT" + s.platforms = { :ios => "11.0", :tvos => "11.0" } + s.compiler_flags = folly_compiler_flags + ' -Wno-nullability-completeness' + s.author = "Facebook, Inc. and its affiliates" + s.source = { :git => "https://github.com/facebook/react-native.git", :tag => "#{s.version}" } + + s.source_files = "**/*.{h,m,mm,swift}" + s.requires_arc = true + + s.dependency "React" + s.dependency "RCT-Folly", folly_version + + # s.dependency "..." + + # Enable codegen for this library + use_react_native_codegen!(s, { + :react_native_path => "../../..", + :js_srcs_dir => "./", + :output_dir => "./" + }) +end diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index ae885b014548..dcc05865ac59 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -37,6 +37,9 @@ def pods() pod 'React-RCTPushNotification', :path => "#{prefix_path}/Libraries/PushNotificationIOS" pod 'Yoga', :path => "#{prefix_path}/ReactCommon/yoga", :modular_headers => true # Additional Pods which are classed as unstable + + # RNTester native modules and components + pod 'ScreenshotManager', :path => "NativeModuleExample" end target 'RNTester' do diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 52b05d0344bb..9fb2a10be87c 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -704,6 +704,9 @@ PODS: - React-logger (= 1000.0.0) - React-perflogger (= 1000.0.0) - ReactCommon/turbomodule/core (= 1000.0.0) + - ScreenshotManager (0.0.1): + - RCT-Folly (= 2021.06.28.00) + - React - Yoga (1.14.0) - YogaKit (1.18.1): - Yoga (~> 1.14) @@ -769,6 +772,7 @@ DEPENDENCIES: - React-runtimeexecutor (from `../../ReactCommon/runtimeexecutor`) - ReactCommon/turbomodule/core (from `../../ReactCommon`) - ReactCommon/turbomodule/samples (from `../../ReactCommon`) + - ScreenshotManager (from `NativeModuleExample`) - Yoga (from `../../ReactCommon/yoga`) SPEC REPOS: @@ -857,6 +861,8 @@ EXTERNAL SOURCES: :path: "../../ReactCommon/runtimeexecutor" ReactCommon: :path: "../../ReactCommon" + ScreenshotManager: + :path: NativeModuleExample Yoga: :path: "../../ReactCommon/yoga" @@ -908,9 +914,10 @@ SPEC CHECKSUMS: React-RCTVibration: 1a58f6ab1ae5fad004119979b676cb5e912f2e44 React-runtimeexecutor: 4b0c6eb341c7d3ceb5e2385cb0fdb9bf701024f3 ReactCommon: 632474905edd9a20ec4f4084142ff4b4a4f3fd8b + ScreenshotManager: a23f618c2a205e3087f29b05154a7c3d6e515d8a Yoga: c0d06f5380d34e939f55420669a60fe08b79bd75 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a -PODFILE CHECKSUM: 6e910a576b7db9347c60dfc58f7852f692200116 +PODFILE CHECKSUM: ae3037f2256663bd77e3b1cffcac23908027fdb1 COCOAPODS: 1.10.1 From 945c5f714d9b3a75f0be02b3a408f865c9021aa7 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Wed, 1 Sep 2021 00:15:04 -0700 Subject: [PATCH 046/986] OSS: Fix $ENTRY_FILE check for non-Debug Xcode builds Summary: The original $ENTRY_FILE check was added in https://github.com/facebook/react-native/pull/29012 to help catch misconfiguration for the entry JS file. That turned out breaking some RNTester builds/tests, so https://github.com/facebook/react-native/pull/29263 was added to accommodate the fact that RNTester .xcodeproj file has its own directory hierarchy. The 2nd PR had multiple issues: * It is incorrect to assume that the $ENTRY_FILE always exists in the parent dir of the .xcodeproj location. This caused an issue in RC 0.66: https://github.com/react-native-community/releases/issues/249#issue-983474535 * RNTester has since moved to packages/rn-tester/ (from RNTester/), hence breaking that assumption It turns out RNTester .xcodeproj has incorrectly misconfigured this JS bundling step (not sure since when). The original script invocation passed in the correct path for `RNTesterApp.ios.js`, but as an arg to the `react-native-xcode.sh` instead of by setting `ENTRY_FILE` env var. So this diff does 2 things: * Undid https://github.com/facebook/react-native/pull/29263 * Fix RNTester JS bundling invocation to set the ENTRY_FILE correctly {F659123377} Changelog: [iOS][Fixed] Unbreak $ENTRY_FILE handling for JS bundling Reviewed By: lunaleaps Differential Revision: D30690900 fbshipit-source-id: 7c5802b3eac56c0456edcd4b7478bfa4af48fc27 --- packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj | 3 +-- scripts/react-native-xcode.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index d47d63409c25..d526edbc7d63 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -321,7 +321,6 @@ C38CB0C2095A8FFDE13321E5 /* Pods-RNTesterUnitTests.debug.xcconfig */, 8735BC063632C9712E25C7D9 /* Pods-RNTesterUnitTests.release.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -610,7 +609,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "set -e\n\nexport NODE_BINARY=node\nexport PROJECT_ROOT=\"$SRCROOT/../../\"\nexport SOURCEMAP_FILE=../sourcemap.ios.map\n# export FORCE_BUNDLING=true\n\"$SRCROOT/../../scripts/react-native-xcode.sh\" $SRCROOT/../../packages/rn-tester/js/RNTesterApp.ios.js\n"; + shellScript = "set -e\n\nexport NODE_BINARY=node\nexport PROJECT_ROOT=\"$SRCROOT/../../\"\nexport ENTRY_FILE=\"$SRCROOT/js/RNTesterApp.ios.js\"\nexport SOURCEMAP_FILE=../sourcemap.ios.map\n# export FORCE_BUNDLING=true\n\"$SRCROOT/../../scripts/react-native-xcode.sh\"\n"; }; A2FBDDDD0C26B4EFA3726B6C /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; diff --git a/scripts/react-native-xcode.sh b/scripts/react-native-xcode.sh index dab1d5cb05b5..b5f7544d3e83 100755 --- a/scripts/react-native-xcode.sh +++ b/scripts/react-native-xcode.sh @@ -74,7 +74,7 @@ else ENTRY_FILE=${1:-index.js} fi -if [[ $DEV != true && ! -f "../$ENTRY_FILE" ]]; then +if [[ $DEV != true && ! -f "$ENTRY_FILE" ]]; then echo "error: Entry file $ENTRY_FILE does not exist. If you use another file as your entry point, pass ENTRY_FILE=myindex.js" >&2 exit 2 fi From ac4ddec542febda744de218dae3a3d34edc7da84 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Wed, 1 Sep 2021 00:15:04 -0700 Subject: [PATCH 047/986] OSS: add Xcode 12.5 + M1 machines CocoaPods post_install workaround Summary: Context: there are multiple issues currently exposed by Xcode 12.5 and/or M1 machine + Flipper. To unblock the new 0.66 release, let's add this workaround in the official react_native_pods.rb recipe and make RNTester and new app Podfile's call it directly. Changelog: [iOS][Fixed] Added workaround for Xcode 12.5 / M1 machines build issues Reviewed By: lunaleaps Differential Revision: D30691291 fbshipit-source-id: 8b24cc60da3d620dbc90f95c77f2345e18c28212 --- packages/rn-tester/Podfile | 1 + scripts/react_native_pods.rb | 35 +++++++++++++++++++++++++++++++++++ template/ios/Podfile | 1 + 3 files changed, 37 insertions(+) diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index dcc05865ac59..b7492364d720 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -61,4 +61,5 @@ end post_install do |installer| react_native_post_install(installer) + __apply_Xcode_12_5_M1_post_install_workaround(installer) end diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 02b04e1e4f75..2325ad33c574 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -212,3 +212,38 @@ def use_react_native_codegen!(spec, options={}) :show_env_vars_in_log => true } end + +# This provides a post_install workaround for build issues related Xcode 12.5 and Apple Silicon (M1) machines. +# Call this in the app's main Podfile's post_install hook. +# See https://github.com/facebook/react-native/issues/31480#issuecomment-902912841 for more context. +# Actual fix was authored by https://github.com/mikehardy. +# New app template will call this for now until the underlying issue is resolved. +def __apply_Xcode_12_5_M1_post_install_workaround(installer) + # Apple Silicon builds require a library path tweak for Swift library discovery to resolve Swift-related "symbol not found". + # Note: this was fixed via https://github.com/facebook/react-native/commit/eb938863063f5535735af2be4e706f70647e5b90 + # Keeping this logic here but commented out for future reference. + # + # installer.aggregate_targets.each do |aggregate_target| + # aggregate_target.user_project.native_targets.each do |target| + # target.build_configurations.each do |config| + # config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(inherited)'] + # end + # end + # aggregate_target.user_project.save + # end + + # Flipper podspecs are still targeting an older iOS deployment target, and may cause an error like: + # "error: thread-local storage is not supported for the current target" + # The most reliable known workaround is to bump iOS deployment target to match react-native (iOS 11 now). + installer.pods_project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' + end + end + + # But... doing so caused another issue in Flipper: + # "Time.h:52:17: error: typedef redefinition with different types" + # We need to make a patch to RCT-Folly - set `__IPHONE_10_0` to our iOS target + 1. + # See https://github.com/facebook/flipper/issues/834 for more details. + `sed -i -e $'s/__IPHONE_10_0/__IPHONE_12_0/' Pods/RCT-Folly/folly/portability/Time.h` +end diff --git a/template/ios/Podfile b/template/ios/Podfile index 65d5ffcbfcf4..9409747f9178 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -25,5 +25,6 @@ target 'HelloWorld' do post_install do |installer| react_native_post_install(installer) + __apply_Xcode_12_5_M1_post_install_workaround(installer) end end From b26f2772624c863c91fa1ff627b481c92d7562fb Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Wed, 1 Sep 2021 00:18:08 -0700 Subject: [PATCH 048/986] Add Linking examples in rn-tester (#30547) Summary: Added examples to RNTester for the Linking API. ## Changelog [General] [Added] - Added example for openSettings() for Linking API. [General] [Added] - Added [LSApplicationQueriesSchemes](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW14) in info.plist with entries tel, telprompt, http, fb, geo Pull Request resolved: https://github.com/facebook/react-native/pull/30547 Test Plan: ![Screen Recording 2020-12-07 at 11 19 13 PM (1)](https://user-images.githubusercontent.com/16796008/102250807-05001580-3f2a-11eb-9ce0-58de4d6fca54.gif) Reviewed By: yungsters Differential Revision: D30559457 Pulled By: lunaleaps fbshipit-source-id: dba2721a9905ddb9ddd2b14141e5553bdf8880da --- packages/rn-tester/RNTester/Info.plist | 8 +++++++ .../js/examples/Linking/LinkingExample.js | 23 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/rn-tester/RNTester/Info.plist b/packages/rn-tester/RNTester/Info.plist index 13573d49b866..788e4d6193c8 100644 --- a/packages/rn-tester/RNTester/Info.plist +++ b/packages/rn-tester/RNTester/Info.plist @@ -2,6 +2,14 @@ + LSApplicationQueriesSchemes + + tel + telprompt + http + fb + geo + UIStatusBarStyle UIStatusBarStyleBlackTranslucent CFBundleDevelopmentRegion diff --git a/packages/rn-tester/js/examples/Linking/LinkingExample.js b/packages/rn-tester/js/examples/Linking/LinkingExample.js index 02f883a644db..cd0c9eabf8eb 100644 --- a/packages/rn-tester/js/examples/Linking/LinkingExample.js +++ b/packages/rn-tester/js/examples/Linking/LinkingExample.js @@ -11,6 +11,7 @@ const React = require('react'); const { + Button, Linking, Platform, StyleSheet, @@ -48,6 +49,16 @@ class OpenURLButton extends React.Component { } } +class OpenSettingsExample extends React.Component { + openSettings() { + Linking.openSettings(); + } + + render() { + return