Commit Graph

261 Commits

Author SHA1 Message Date
Tim Yung 7884fc519b RN: 5s Delay in ReactAppInstrumentationTestCase
Summary:
Tests like `CatalystSubviewsClippingTestCase` are intermittently failing due to registered callable modules not yet being registered.

Increasing the timeout to wait for the bundle execution to mitigate these intermittent failures.

Changelog:
[Internal]

Reviewed By: mdvacca

Differential Revision: D29835227

fbshipit-source-id: c9fe03202ad4028d3785216d50c6c173a56c6d84
2021-07-21 17:11:30 -07:00
Luna Wei 77366cd869 Remove Picker from OSS
Summary: Changelog: [General][Removed] - Remove Picker code from Android

Reviewed By: ShikaSD

Differential Revision: D29123164

fbshipit-source-id: 4471ea5f52885735ead07a656452ed5ef2bff65b
2021-06-21 23:00:42 -07:00
Luna Wei 625d9e5090 Remove PickerAndroidTestModule
Summary: Changelog: [Internal] - Delete PickerAndroidTestModule in prep for deprecating Picker from OSS

Reviewed By: kacieb

Differential Revision: D29082826

fbshipit-source-id: eb7219f1a1e77205eeb8532ac3e17f8956f23c03
2021-06-16 12:29:17 -07:00
Nadiia D 46ffe84453 Make RootTag an opaque type
Summary:
Changelog:
[General][Changed] Make the RootTag an opaque type

Reviewed By: yungsters

Differential Revision: D27992320

fbshipit-source-id: 2901f0e59f573106295b986fe04db227134235da
2021-04-26 22:57:55 -07:00
Araz Abishov 8207e97f91 Android: upgrading to OkHttp from v3 to v4 (#31084)
Summary:
Extends https://github.com/facebook/react-native/pull/30694 to fix tests.

OkHttp v4 was released almost a year ago. Even though v3 is still receiving security and bug fixes, most of the new improvements and features are landing in v4. This PR bumps OkHttp from v3 to v4 and addresses backward-incompatible changes.

Side effects of this upgrade:
 - OkHttp v4 depends on Kotlin's standard library, so react-native will have a transitive dependency on it.
 - The dex method count of test apk has exceeded the maximum, so multidexing had to be enabled for android tests.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Changed] - Bumping OkHttp from v3 to v4.

Pull Request resolved: https://github.com/facebook/react-native/pull/31084

Test Plan: Automated (relying on the test suite) and manual testing.

Reviewed By: fkgozali

Differential Revision: D27597430

Pulled By: ShikaSD

fbshipit-source-id: 967379b41c2bcd7cfd4083f65059f5da467b8a91
2021-04-08 10:45:53 -07:00
Lulu Wu dfa8eb0558 Rename "hasActiveCatalystInstance" to "hasActiveReactInstance" for clarification
Summary:
Sometimes ```hasActiveCatalystInstance()``` is used to check if it's safe to access the CatalystInstance, which will still crash in Venice.

Previously we mitigate this by changing ```reactContext.hasActiveCatalystInstance()``` to ```reactContext.hasActiveCatalystInstance() || reactContext.isBridgeless()```.

To solve this for all and good the plan is:
1, Rename ```hasActiveCatalystInstance()``` to ```hasActiveReactInstance()``` so it won't sounds like CatalystInstance-only.
2, Implement hasActiveReactInstance() for Venice. D27343867
3, Remove previous mitigation. D27343952

This diff is the first step, by xbgs there are **58** non-generated callsites of  ```hasActiveCatalystInstance()``` in code base which are all renamed in this diff.

Changelog:
[Android][Changed] - Rename "hasActiveCatalystInstance" to "hasActiveReactInstance"

Reviewed By: mdvacca

Differential Revision: D27335055

fbshipit-source-id: 5b8ff5e09b79a492e910bb8f197e70fa1360bcef
2021-03-31 06:33:23 -07:00
David Vacca 5348a98207 Migrate lookup of EventDispatcher to not depend on UIManagerModule
Summary:
This diff migrates all the lookups of EventDispatcher to not depend on UIManagerModule anymore.
This refactor is necessary because:
- Users running in Fabric / Venice should not load on the UIManagerModule class
- D25858934 will introduce a change that will break all of these callsites

In the migration I'm relying on the method UIManagerHelper.getEventDispatcherFromReactTag() that returns the correct EventDispatcher for a reactTag.

I'm planning to land this change early in the week (to catch potential errors in alpha / beta versions)

As a followup we need to deprecate and prevent developers to continue using getNativeModule(UIManagerModule.class) moving forward. That will be part of another diff

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D25858933

fbshipit-source-id: e26c99759307517b5bef483274fe0e0d71bb4c6c
2021-01-11 15:43:58 -08:00
Ron Edelstein 933cef6d9a More explicit marking of autoglob as False
Summary:
In preparation for flipping the default, marking autoglob as False in places where it isn't explicitly specified.

Changelog: [Internal]

Reviewed By: strulovich

Differential Revision: D25497305

fbshipit-source-id: 142e5caca2d67efcb3c25067a36934f7f6dd4b21
2020-12-11 16:45:55 -08:00
Mike Vitousek 8f5f3d159b Add Flow annotations to escaped generics in xplat
Summary:
Flow will soon stop allowing generic types to "escape" out of the scope in which they were defined. The fix will be to add annotations to currently-unannotated variables, parameters, and function returns, so that generics don't become inputs to type inference for those positions. This diff adds new type annotations to xplat where possible to minimize the impact of this change.

This diff was generated by running
```
buck run //flow/src/facebook/komodo/binaries:annotate_escaped_generics -- --write ../../xplat/js
```
from within the flow directory, and then reverting changes that led to new errors. Most changes were reverted by running:
```
facebook/flowd check --json --json-version=2 ../../xplat/js &> post-json
jq -f j.jq < post-json | xargs hg revert
```
where `j.jq` is
```
def locs: [.primaryLoc.source, (select(.rootLoc.source != null) | .rootLoc.source), .referenceLocs[].source ] | unique;
[.errors[] | locs[]] | unique | .[]
```

Changelog: [Internal]

Reviewed By: panagosg7

Differential Revision: D24006427

fbshipit-source-id: 0cd6ec8a9611d8b1e9b14c54f9fffd2d7de2fd9e
2020-10-01 06:19:39 -07:00
Emily Janzer f0e80ae229 Set selection to end of text input on accessibility click
Summary:
When we render a text input that already has a text value (<TextInput value="123" />), its selection (cursor) is automatically set to the end of the text. However, when you swipe to focus the text input with TalkBack, Android decides it needs to clear the selection, which moves the cursor back to the beginning of the text input. This is probably not what you want if you're editing some text that's already there. Ideally we would just keep the selection at the end, but I don't know how to prevent this from happening - it seems to be part of how TextView handles the accessibility focus event? So instead I'm just explicitly setting the selection to the end of the text in our handler for accessibility click.

Changelog: [Android][Fixed] Move selection to the end of the text input on accessibility click

Reviewed By: mdvacca

Differential Revision: D23441077

fbshipit-source-id: 16964f5b106637e55a98c6b0ef0f0041e8e6215d
2020-09-02 16:17:02 -07:00
Joshua Selbo 7c7f09ea60 Upgrade instrumentation tests to Mockito2
Summary: Changelog: [Internal]

Reviewed By: strulovich

Differential Revision: D22673812

fbshipit-source-id: 31cb5a71da58e778e503a47fc92538127e76ce41
2020-07-27 12:04:30 -07:00
Emily Janzer eddf90f756 Clean up RuntimeExecutor experiment and remove jsContext param
Summary:
Cleaning up the test for switching to the shared RuntimeExecutor, and removing the jsContext arg from Fabric's Android APIs entirely.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D22026752

fbshipit-source-id: df70faa70eaa2a04717ae89e8ad3216dfd486a35
2020-07-24 16:48:36 -07:00
Jacek Burys c8fed9e385 Move TimePickerAndroid to FB internal
Summary:
Moving TimePickerAndroid to FB internal.

Changelog:
[Android][Changed] - Moved TimePickerAndroid to FB internal.

Reviewed By: cpojer

Differential Revision: D21504128

fbshipit-source-id: 400c6ee7cff96a0d6b4205f7806ef8951b611b8c
2020-05-27 03:40:35 -07:00
Kevin Gozali f24b815fe6 use xplat BUCK attribution
Summary:
Internal code attribution update.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D21603406

fbshipit-source-id: c3da1823e26beb0092d97e66d731618c0433a2f7
2020-05-15 21:55:52 -07:00
Kevin Gozali 164d47f30a label react-native-github targets
Summary:
For internal code attribution.

Changelog: [Internal]

Reviewed By: zlern2k

Differential Revision: D21468924

fbshipit-source-id: 59cd2a52e0ae46bedbf54816820a5f40b684da8b
2020-05-08 00:36:17 -07:00
Ramanpreet Nara 9263eb5d38 Part 2: Make CatalystInstanceImpl.getNativeModule Nullable
Summary:
This is the codemod portion of the parent diff.

I modified all call-sites to `ReactContext.getNativeModule` to do a null check on the returned NativeModule.

Changelog:
[Android][Fixed] - Check if NativeModules returned from CatalystInstanceImpl.getNativeModule are null before using them.

Reviewed By: JoshuaGross

Differential Revision: D21272028

fbshipit-source-id: 6bd16c6bf30605f2dfdf4c481352063712965342
2020-04-28 12:18:17 -07:00
Rick Hanlon 7cedccdb8d Add "Open Debugger" and "Open React DevTools" to Android dev menu
Summary:
This diff introduces a new "Open Debugger" menu item for VMs that support on device debugging and for opening the React DevTools in Flipper.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20784279

fbshipit-source-id: caecdace00007224692d994a75c106842c8b2acb
2020-04-16 08:41:20 -07:00
Joshua Gross 5c4425a456 Fix Fabric SSTs, so they actually run in Fabric instead of Paper, convert ServerSnapshotTestsAppImpl to functional component
Summary:
Update instrumentation test infra for Fabric tests.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D19961919

fbshipit-source-id: 17264b6308712dddece730effd57832817e148cf
2020-04-03 14:04:51 -07:00
Michael Bolin 0b9ea60b4f Back out "Upgrade Prettier from 1.17 to 2.0.2."
Differential Revision: D20639755

fbshipit-source-id: 5028563f9cf0527a30b4259daac50cdc03934bfd
2020-03-24 21:47:35 -07:00
Michael Bolin cf44650b3f Upgrade Prettier from 1.17 to 2.0.2.
Summary:
This gets us on the latest Prettier 2.x:
https://prettier.io/blog/2020/03/21/2.0.0.html

Notably, this adds support for TypeScript 3.8,
which introduces new syntax, such as `import type`.

Reviewed By: zertosh

Differential Revision: D20636268

fbshipit-source-id: fca5833d003804333a05ba16325bbbe0e06d6c8a
2020-03-24 20:24:47 -07:00
Joshua Selbo 25ea35632e Migrate usages of 3.1.0 espresso libs to androidx:test-espresso 3.2.0 libs
Differential Revision: D19943694

fbshipit-source-id: bfbcf5148afa9639848c6b1c9b7398f75f5157d3
2020-02-23 18:34:55 -08:00
Emily Janzer d4a498aba2 Allow focusing TextInput when already focused
Summary:
Right now, `requestFocus()` is a no-op if the EditText view thinks it's already focused. In certain cases, though, we still want to focus the view even if it's already focused - for example, if TalkBack is enabled and you dismiss the keyboard, you want to be able to tap on the TextInput again to bring back the keyboard, even though the View never thinks it lost focus.

What I'm doing instead is basically disregarding the View's current focus state if we *would* focus the TextInput, which is in 3 circumstances:

- When the view is attached to a window, if autofocus is true
- When the focus is being requested by JS
- When the focus is being requested by an accessibility action from the OS

Changelog: [Android][Fixed] Change how TextInput responds to requestFocus to fix a11y focus issue

Reviewed By: mdvacca

Differential Revision: D19750312

fbshipit-source-id: 30b9fab40af4a083fa98f57aba7e586540238bea
2020-02-18 12:14:17 -08:00
Rick Hanlon af710ab177 Switch from YellowBox.ignoreWarnings to LogBox.ignoreLogs
Summary:
Migrates internal calls from ignoreWarnings to ignoreLogs so we can remove YellowBox.

Changelog: [Internal]

Reviewed By: TheSavior

Differential Revision: D19813781

fbshipit-source-id: 16c7b3f2cd38cba1901eccb4d5b9a2396a37ba1b
2020-02-18 06:19:46 -08:00
Rick Hanlon 3c4c2f27aa Migrate console.disableYellowBox to LogBox.ignoreAllLogs()
Summary:
Migrates internal usages of console.disableYellowBox to LogBox.ignoreAllLogs()

Changelog: [Internal]

Reviewed By: TheSavior

Differential Revision: D19813776

fbshipit-source-id: 8c78e64596b4ba2fe94ab838881cbff6cee43e5b
2020-02-18 06:19:45 -08:00
Emily Janzer 8c493804f3 Fix TextInputTestCase
Summary:
https://github.com/facebook/react-native/pull/22166 removed inline styles from TextInputTestModule but applied the incorrect style to some of the TextInputs - instead of setting the text color, it set the margin. This caused the test to fail because no color was applied.

Changelog: [Android] [Fixed] Fixed style in TextInputTestCase

Reviewed By: zackargyle

Differential Revision: D19912362

fbshipit-source-id: d5068114b726ee7583842e5f6f323862b0c28e44
2020-02-14 15:03:58 -08:00
Andres Suarez ff22722e47 Daily arc lint --take GOOGLEJAVAFORMAT
Summary:
Changelog:
[Internal]

Differential Revision: D19875191

fbshipit-source-id: 3a1e22a4342d523f556c847a9fa780a898a96771
2020-02-13 05:50:42 -08:00
Christoph Nakazawa 316b470b7f Use Hermes for RN instrumentation tests
Summary:
make ReactTestHelper always return a test object set to use
Hermes.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D19566604

fbshipit-source-id: 3c8fc680afbae000adb96bfcd079104d86cf06bd
2020-01-27 02:08:58 -08:00
Eli White e362470305 Convert easy files to flow strict-local
Summary:
This diff was generated by this script used by WWW
https://our.intern.facebook.com/intern/diffusion/WWW/browse/master/scripts/flow/upgrade_to_flow_strict_local.sh?lines=0

Changelog:
[Internal] Upgrade flow to flow strict-local

Reviewed By: zackargyle, rickhanlonii

Differential Revision: D18833630

fbshipit-source-id: e64d4e9a49a0db5e6bf70a0c489567862b578d7f
2019-12-05 16:06:46 -08:00
George Zahariev 8553e1acc4 Exact-by-default codemod for react-native-github
Summary:
We are rolling out exact-by-default syntax to xplat/js.

I had to manually move around some comments to preserve proper placement.

Changelog: [Internal]

Reviewed By: jbrown215

Differential Revision: D18633611

fbshipit-source-id: 48f7468dcc55b1d00985419d035a61c6820b3abe
2019-11-21 09:42:57 -08:00
David Vacca 3408dc0b3e Customize ExceptionHandler in ReactAppTestActivity
Summary:
This diff extends the ReactAppTestActivity to allow customization of the RN ExceptionHandler

Changelog:
This diff extends the ReactAppTestActivity to allow customization of the RN ExceptionHandler

Reviewed By: JoshuaGross

Differential Revision: D17993132

fbshipit-source-id: 7320d35a4d88d56a7356f2863829c88758c08341
2019-10-18 09:09:30 -07:00
Andres Suarez aee88b6843 Tidy up license headers [3/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952693

fbshipit-source-id: 8fcb8e58a2e04e7a3169f4d525bffc00835768e6
2019-10-16 10:06:34 -07:00
Andres Suarez 3b31e69e28 Tidy up license headers [2/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952694

fbshipit-source-id: 17c87de7ebb271fa2ac8d00af72a4d1addef8bd0
2019-10-16 10:06:34 -07:00
David Vacca 3b51499fc2 Ensure tests are running on the correct thread
Summary: This diff re-enables commented code during the AndroidX migration

Reviewed By: PeteTheHeat

Differential Revision: D15758382

fbshipit-source-id: 95106cc2e3faccbd632d773ee58091c7bf8ea063
2019-10-07 18:56:06 -07:00
Joshua Gross 6166645560 Fix ReactIdleDetection from Android X migration
Summary:
The implementation for this class was commented out in D14200097.

ServerSnapshotTests rely on this class to decide when test app setup is finished [here](diffusion/FBS/browse/master/fbandroid/instrumentation_tests/com/facebook/react/screenshots/shared/ReactNativeScreenshotTestCase.java;676aecf86a816bba8eb8571bc327e77c8f2e149b$164).

The only change I made is to use InstrumentationRegistry from Androidx instead of support.

Reviewed By: rickhanlonii, mdvacca

Differential Revision: D15068069

fbshipit-source-id: c69c7d46a1068836f9a9303de11e9a7a36b4e6d9
2019-10-05 01:55:04 -07:00
Petter Hesselberg 4b9350061f Petterh/support parcelable array args (#26379)
Summary:
`ReactRootView.startReactApplication` takes a `Bundle` argument called `initialProperties`. This is translated to a `ReadableMap` via `Arguments.fromBundle`. If the bundle contains an array of bundles, this gets translated by `Arguments.fromArray`.

If the bundle was passed from one activity to another via intent extras, however, there is a problem. After the bundle has been marshaled and unmarshaled, the array of `Bundle`s come out the other end as an arrap of `Parcelable`s, although each array element remains a `Bundle`. This results in an "Unknown array type" exception.

This PR fixes this by adding support for `Parcelable` arrays &ndash; provided they contain only members of type `Bundle`.

## Changelog

[Android] [Fixed] - Don't throw "Unknown array type" exception when passing serialized bundle arrays in ReactRootView.startReactApplication's initialProperties parameter
Pull Request resolved: https://github.com/facebook/react-native/pull/26379

Test Plan: Added test class `ArgumentsTest`. The test method `testFromMarshaledBundle` fails when used on the old version of `Arguments`.

Differential Revision: D17661203

Pulled By: cpojer

fbshipit-source-id: 63612d78f49bdf9cc53f6f21ae883dba6cebce84
2019-09-29 19:22:22 -07:00
Emily Janzer e9b50fa4ee Renaming Timing to TimingModule
Summary: Most of our other native modules end in 'module', so let's update Timing to match.

Reviewed By: RSNara

Differential Revision: D17260848

fbshipit-source-id: 808b4d370a7036a247724fda5ab7210ac985476b
2019-09-19 11:47:17 -07:00
Janic Duplessis cc068b0551 Export the DevSettings module, add addMenuItem method (#25848)
Summary:
I wanted to configure the RN dev menu without having to write native code. This is pretty useful in a greenfield app since it avoids having to write a custom native module for both platforms (and might enable the feature for expo too).

This ended up a bit more involved than planned since callbacks can only be called once. I needed to convert the `DevSettings` module to a `NativeEventEmitter` and use events when buttons are clicked. This means creating a JS wrapper for it. Currently it does not export all methods, they can be added in follow ups as needed.

## Changelog

[General] [Added] - Export the DevSettings module, add `addMenuItem` method
Pull Request resolved: https://github.com/facebook/react-native/pull/25848

Test Plan:
Tested in an app using the following code.

```js
if (__DEV__) {
 DevSettings.addMenuItem('Show Dev Screen', () => {
    dispatchNavigationAction(
      NavigationActions.navigate({
        routeName: 'dev',
      }),
    );
  });
}
```

Added an example in RN tester

![devmenu](https://user-images.githubusercontent.com/2677334/62000297-71624680-b0a1-11e9-8403-bc95c4747f0c.gif)

Differential Revision: D17394916

Pulled By: cpojer

fbshipit-source-id: f9d2c548b09821c594189d1436a27b97cf5a5737
2019-09-17 06:38:10 -07:00
Christoph Nakazawa dbf070c51e Remove TimePickerAndroid from React Native
Summary: Lean Core

Reviewed By: rubennorte

Differential Revision: D17344045

fbshipit-source-id: a5a7ab41075da93f8a1929059abe183838b00c82
2019-09-13 07:47:58 -07:00
glevi@fb.com 97b42bb142 Deploy v0.106.0 to xplat/js
Reviewed By: mroch

Differential Revision: D16979246

fbshipit-source-id: 995fbd391823eaf0c9e3a673cf8fbe061ce0545a
2019-08-23 08:06:44 -07:00
Logan Daniels 91f139b941 xplat/js/react-native-github
Reviewed By: panagosg7

Differential Revision: D16657770

fbshipit-source-id: 4e260842c838a35317515044c54ccf55a083da33
2019-08-09 10:11:15 -07:00
Ram N bc2b52d22c Enable Starting Sampling profile at App Startup
Summary: In Dev Settings, we used to have an `Start Sampling Profiler on init` option, which was defunct. This diff re-enables that option. We can now start the Sampling Profiler on app start

Reviewed By: yinghuitan

Differential Revision: D7022382

fbshipit-source-id: 1db85d8a324e401c71187ba5871a91abcc18acf9
2019-07-31 13:54:23 -07:00
David Vacca aa5edca0e2 Migrate Nullable and NonNull annotations to AndroidX
Summary:
This diff migrates the usages Nullable and NonNull annotations to AndroidX instead of javax.

The purpose of this change is to bring consistency in the annotations used by the core of RN

Reviewed By: makovkastar

Differential Revision: D16054504

fbshipit-source-id: 21d888854da088d2a14615a90d4dc058e5286b91
2019-07-11 16:23:29 -07:00
Oleksandr Melnykov cd05a85fe5 Fix Javadocs broken by google-java-format
Summary: After we ran google-java-format D16071725, some Javadocs which weren't properly written broke. This includes putting unordered and ordered lists not using <ul> and <ol>, putting code blocks and pseudo-graphics not using <pre>. I ran through all the changed classes and tried to fix the broken Javadocs.

Reviewed By: cpojer

Differential Revision: D16090087

fbshipit-source-id: f31971cbc0e367a04814ff90bbfb2192751d5e16
2019-07-02 09:39:21 -07:00
Oleksandr Melnykov 6c0f73b322 Format Java code in xplat/js/react-native-github
Summary:
This diff formats the Java class files inside xplat/js/react-native-github. Since google-java-format was enabled in D16071401 we want to codemode the existing code so that users don't have to deal with formatter lint noise at diff-time.

```arc f --paths-cmd 'hg files -I "**/*.java"'```

drop-conflicts

Reviewed By: cpojer

Differential Revision: D16071725

fbshipit-source-id: fc6e3852e45742c109f0c5ac4065d64201c74204
2019-07-02 04:16:46 -07:00
Kevin Gozali 2df90738d5 Android: Use enum type for looking up JSIModule's
Summary:
To avoid unnecessary class loads, and better modularity, let's use string keys (enum) to access JSIModule's. For now all JSIModule's are all known inside the core infra (only FabricUIManager and TurboModuleManager right now), so let's keep it simple and explicitly list them out.

The only problem here is we lose some form of type safety...

Reviewed By: JoshuaGross

Differential Revision: D15872777

fbshipit-source-id: 9c2de7ef1e88ef3a6dff5888d644f9d8963af2a3
2019-06-18 16:22:17 -07:00
Jerry.Luo fb550e9e84 Check if mCurrentActivity is set according to LifecycleState (#23336)
Summary:
Issues: Related to  #13439
react-native-website:Related to PR [#792](https://github.com/facebook/react-native-website/pull/792)
solution: https://github.com/facebook/react-native/issues/13439#issuecomment-400256114

When we integration with Existing  Android Apps.and set LifecycleState  is `LifecycleState.RESUMED`.
It's lead to `mCurrentActivity`  is null .

At this time , the behave of set `mCurrentActivity ` which  is unexpectedly.

## Changelog
[Android] [Fixed] - Check if mCurrentActivity is set according to LifecycleState
Pull Request resolved: https://github.com/facebook/react-native/pull/23336

Differential Revision: D14298654

Pulled By: cpojer

fbshipit-source-id: 5cc17539a51154faeb838349b068d92511946f79
2019-06-12 05:11:43 -07:00
Ramanpreet Nara 9c76e14b07 Turn FBMainReactPackage into a TurboReactPackage
Summary: `ReactTurboModuleManagerDelegate` only understands `TurboReactPackage`s. So, we need to convert `FBMainReactPackage` and all its dependent packages into `TurboReactPackage`.

Reviewed By: fkgozali

Differential Revision: D15711546

fbshipit-source-id: df626d542a6477b116c867299219156423c6364a
2019-06-09 15:24:09 -07:00
Joshua Ong ac7ec4602f Allow headless JS tasks to retry (#23231)
Summary:
`setTimeout` inside a headless JS task does not always works; the function does not get invoked until the user starts an `Activity`.

This was attempted to be used in the context of widgets. When the widget update or user interaction causes the process and React context to be created, the headless JS task may run before other app-specific JS initialisation logic has completed. If it's not possible to change the behaviour of the pre-requisites to be synchronous, then the headless JS task blocks such asynchronous JS work that it may depend on. A primitive solution is the use of `setTimeout` in order to wait for the pre-conditions to be met before continuing with the rest of the headless JS task. But as the function passed to `setTimeout` is not always called, the task will not run to completion.

This PR solves this scenario by allowing the task to be retried again with a delay. If the task returns a promise that resolves to a `{'timeout': number}` object, `AppRegistry.js` will not notify that the task has finished as per master, instead it will tell `HeadlessJsContext` to `startTask` again (cleaning up any posted `Runnable`s beforehand) via a `Handler` within the `HeadlessJsContext`.

Documentation also updated here: https://github.com/facebook/react-native-website/pull/771

### AppRegistry.js
If the task provider does not return any data, or if the data it returns does not contain `timeout` as a number, then it behaves as `master`; notifies that the task has finished. If the response does contain `{timeout: number}`, then it will attempt to queue a retry. If that fails, then it will behaves as if the task provider returned no response i.e. behaves as `master` again. If the retry was successfully queued, then there is nothing to do as we do not want the `Service` to stop itself.

### HeadlessJsTaskSupportModule.java
Similar to notify start/finished, we simply check if the context is running, and if so, pass the request onto `HeadlessJsTaskContext`. The only difference here is that we return a `Promise`, so that `AppRegistry`, as above, knows whether the enqueuing failed and thus needs to perform the usual task clean-up.

### HeadlessJsTaskContext.java
Before retrying, we need to clean-up any timeout `Runnable`'s posted for the first attempt. Then we need to copy the task config so that if this retry (second attempt) also fails, then on the third attempt (second retry) we do not run into a consumed exception. This is also why in `startTask` we copy the config before putting it in the `Map`, so that the initial attempt does leave the config's in the map as consumed. Then we post a `Runnable` to call `startTask` on the main thread's `Handler`. We use the same `taskId` because the `Service` is keeping track of active task IDs in order to calculate whether it needs to `stopSelf`. This negates the need to inform the `Service` of a new task id and us having to remove the old one.

## Changelog
[Android][added] - Allow headless JS tasks to return a promise that will cause the task to be retried again with the specified delay
Pull Request resolved: https://github.com/facebook/react-native/pull/23231

Differential Revision: D15646870

fbshipit-source-id: 4440f4b4392f1fa5c69aab7908b51b7007ba2c40
2019-06-06 11:57:49 -07:00
James Ide 33ee6f8b99 Add a lint rule to disallow Haste imports (#25058)
Summary:
This is an ESLint plugin that infers whether an import looks like a Haste module name. To keep the linter fast and simple, it does not look in the Haste map. Instead, it looks for uppercase characters in single-name import paths, since npm has disallowed uppercase letters in package names for a long time. There are some false negatives (e.g. "merge" is a Haste module and this linter rule would not pick it up) but those are about 1.1% of the module names in the RN repo, and unit tests and integration tests will fail anyway once Haste is turned off.

You can disable the lint rule on varying granular levels with ESLint's normal disabling/enabling mechanisms.

Also rewrote more Haste imports so that the linter passes (i.e. fixed lint errors as part of this PR).

## Changelog

[General] [Changed] - Add a lint rule to disallow Haste imports
Pull Request resolved: https://github.com/facebook/react-native/pull/25058

Differential Revision: D15515826

Pulled By: cpojer

fbshipit-source-id: d58a3c30dfe0887f8a530e3393af4af5a1ec1cac
2019-05-30 07:45:16 -07:00
James Ide cd9adda651 Migrate "androidTest" JS from Haste to path-based requires (#24813)
Summary:
The files in `ReactAndroid/src/androidTest/js` use Haste names; this commit migrates them to use path-based imports. This helps us move RN towards standard path-based requires. All the requires in `androidTest` have been rewritten to use relative requires.

[General] [Changed] - Migrate "androidTest" JS from Haste to path-based requires
Pull Request resolved: https://github.com/facebook/react-native/pull/24813

Differential Revision: D15318108

Pulled By: cpojer

fbshipit-source-id: dddc68f992b8dea48afb01fd4481bd5b846231ca
2019-05-14 03:21:24 -07:00