react-native-macos/scripts
Ramanpreet Nara 9b94a541d8 Get CallInvokers from the bridge
Summary:
## Context
For now, assume TurboModules doesn't exist.

**What happens when we call an async NativeModule method?**
Everytime JS calls an async NativeModule method, we don't immediately execute it. The legacy infra pushes the call into some queue managed by `MessageQueue.js`. This queue is "flushed" or "emptied" by the following events:
- **Flushed:** A C++ -> JS call. NativeModule async methods can called with an `onSuccess` and/or `onFail` callback(s). Calling `NativeToJsBridge::invokeCallback` to invoke one of these callbacks is one way for ObjC++/C++/Java to call into JS. Another way is via JSModule method calls, which are initiated by `NativeToJsBridge::callFunction`.
- **Flushed:** When `JSIExecutor::flush` is called. Since TurboModules don't exist, this only happens when we call `JSIExecutor::loadApplicationScript`.
- **Emptied:** When more than 5 ms have passed, and the queue hasn't been flushed/emptied, on the next async NativeModule method call, we add to the queue. Afterwards, we empty it, and invoke all the NativeModule method calls.

**So, what's the difference between flushed and emptied?**
> Note: These are two terms I just made up, but the distinction is important.

If the queue was "flushed", and it contained at least one NativeModule method call, `JsToNativeBridge` dispatches the `onBatchComplete` event. On Android, the UIManager module is the only module that listens to this event. This `onBatchComplete` event doesn't fire if the queue was "emptied".

**Why does any of this matter?**
1. TurboModules exist.
2. We need the TurboModules infra to have `JsToNativeBridge` dispatch `onBatchComplete`, which depends on:
   - **Problem 1:** The queue being flushed on calls into JS from Java/C++/ObjC++.
   - **Problem 2:** There being queued up NativeModule async method calls when the queue is flushed.

In D14656466, fkgozali fixed Problem 1 by making every C++/Java/Obj -> JS call from TurboModules also execute `JSIExecutor::flush()`. This means that, with TurboModules, we flush the NativeModule async method call queue as often as we do without TurboModules. So far, so good. However, we still have one big problem: As we convert more NativeModules to TurboModules, the average size of the queue of NativeModule method calls will become smaller and smaller, because more NativeModule method calls will be TurboModule method calls. This queue will more often be empty than not. Therefore, we'll end up dispatching the `onBatchComplete` event less often with TurboModules enabled. So, somehow, when we're about to flush the NativeModule method call queue, we need `JsToNativeBridge` to understand that we've executed TurboModule method calls in the batch. These calls would have normally been queued, which would have led the queue size to be non-zero. So if, during a batch, some TurboModule async method calls were executed, `JsToNativeBridge` should dispatch `onBatchComplete`.

**So, what does this diff do?**
1. Make `Instance` responsible for creating the JS `CallInvoker`.
2. Make `NativeToJsBridge` responsible for creating the native `CallInvoker`. `Instance` calls into `NativeToJsBridge` to get  the native `CallInvoker`.
3. Hook up `CatalystInstanceImpl`, the Android bridge, with the new JS `CallInvoker`, and the new native `CallInvoker`. This fixes `onBatchComplete` on Android. iOS work is pending.

Changelog:
[Android][Fixed] - Ensure `onBatchComplete` is dispatched correctly with TurboModules

Reviewed By: mdvacca

Differential Revision: D20717931

fbshipit-source-id: bc3ccbd6c135b7f084edbc6ddb4d1e3c0c7e0875
2020-04-01 11:39:18 -07:00
..
circleci Add diffing to app bundle size reports (#28284) 2020-03-20 07:15:11 -07:00
versiontemplates Stamp React Native Version Into C++ Code (#28036) 2020-02-27 06:42:14 -08:00
.packager.env Move YGStyle to seperate file and add constructors 2018-02-20 05:55:36 -08:00
.tests.env Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
android-e2e-test.js Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
android-setup.sh Move non-license comments out of license header 2019-10-15 20:12:12 -07:00
bump-oss-version.js fbshipit-source-id: da15f69185e724eaf7d4bc78dbc61fcdcb3074d5 2020-03-13 21:46:45 -07:00
compose-source-maps.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
generate-api-docs.js Generate doc info for RN components 2019-09-19 18:36:25 -07:00
generate-rncore.sh Move non-license comments out of license header 2019-10-15 20:12:12 -07:00
ios-configure-glog.sh Upgrade folly to v2018.10.22.00 for iOS (#21976) 2018-10-29 12:13:11 -07:00
launchPackager.bat Metro Bundler -> Metro 2019-08-16 10:37:10 -07:00
launchPackager.command Metro Bundler -> Metro 2019-08-16 10:37:10 -07:00
node-binary.sh Fix: use NODE_BINARY when starting packager (#24156) 2019-04-10 07:39:23 -07:00
objc-test.sh Use Xcode 11.3.0 and iOS 13.3 in tests (#27783) 2020-01-17 16:42:56 -08:00
packager.sh Use CocoaPods-based RNTesterPods for iOS tests (#25416) 2019-06-28 19:18:10 -07:00
process-podspecs.sh Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
publish-npm.js Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
react-native-xcode.sh feat: improve monorepo support by removing redundant PROJECT_ROOT (#28354) 2020-03-20 11:36:46 -07:00
react_native_pods.rb Get CallInvokers from the bridge 2020-04-01 11:39:18 -07:00
run-android-ci-instrumentation-tests.js Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
run-android-emulator.sh Move non-license comments out of license header 2019-10-15 20:12:12 -07:00
run-android-local-integration-tests.sh Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
run-android-local-unit-tests.sh Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
run-ci-e2e-tests.js Green CI: Fix JavaScript e2e tests, disable failing Android e2e test (#28392) 2020-03-26 06:52:43 -07:00
run-ci-javascript-tests.js Add react-native-oss-e2e job to Sandcastle, running JavaScript e2e tests from open source 2019-04-15 11:07:54 -07:00
run-instrumentation-tests-via-adb-shell.sh Move non-license comments out of license header 2019-10-15 20:12:12 -07:00
set-rn-template-version.js Adjust test manual e2e script to work with new init (#24583) 2019-04-25 02:03:10 -07:00
sync-css-layout.sh Clean up instances of scripts/signedsource.py 2019-03-14 13:42:27 -07:00
test-manual-e2e.sh Re-sync with internal repository 2019-12-19 13:42:21 -08:00
try-n-times.js Fix linting issues (#22062) 2018-11-01 14:29:16 -07:00
validate-android-device-env.sh Update Broken Link #devcjog25 (#27025) 2019-10-28 12:11:45 -07:00
validate-android-sdk.sh Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
validate-android-test-env.sh Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
validate-ios-test-env.sh Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00