Граф коммитов

191 Коммитов

Автор SHA1 Сообщение Дата
Peter Argany c9600a310f Connect to RCTInspectorDevServerHelper in bridgeless mode
Summary: Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D26623985

fbshipit-source-id: 98aff018adc0e9aca517d8faebd20fe98e9b708b
2021-02-26 17:41:46 -08:00
Peter Argany 995e962af4 Fix fast refresh settings in RN Dev Menu
Summary:
Changelog: [Internal]

This moves enabling/disabling fast refresh off of `bridge.enqueueJSCall` in bridgeless mode.

Reviewed By: sammy-SC

Differential Revision: D26290378

fbshipit-source-id: ed8a3389b9812cedf7181971656dacd98ff7ecfd
2021-02-19 13:47:26 -08:00
Peter Argany 2548d424ce Make RCTDevSettings conform to RCTBundleHolderModule
Summary:
Changelog: [Internal]

This diff allows `RCTDevSettings` to access bundleURL directly instead of relying on the bridge.

Reviewed By: RSNara

Differential Revision: D26289592

fbshipit-source-id: e22e583e51323bfe66f6e424d9f47edf71b1ed9f
2021-02-19 13:47:26 -08:00
Peter Argany f0faa7843c Remove iOS10/tvOS10 support from remaining podfiles
Summary: Changelog: [iOS] Remove iOS10/tvOS10 support from remaining podfiles

Reviewed By: shergin

Differential Revision: D26410811

fbshipit-source-id: 9050346def5070338e709ff102a284a828821586
2021-02-19 13:47:25 -08:00
Peter Argany 6774358a1a Basic bridgeless support for RCTDevMenu
Summary:
Changelog: [Internal]

This removes a couple dependencies on bridge in dev menu native module. So far reloading works, will get inspector and other options working in follow ups.

Reviewed By: sammy-SC

Differential Revision: D26240391

fbshipit-source-id: 7c9d585f4efa6cc9db995ef8a33865831bc8d526
2021-02-04 12:34:48 -08:00
Peter Argany ac63d57e5e Cleanup - remove isLiveReloadAvailable
Summary:
Live reload was removed as a user facing feature in 2019 in favour of fast refresh. The native code was left in case "automation" relied on it. I'm quite sure no automation is using this dev feature. Remember, the dev feature made it so that hitting save in a text editor auto reloaded in metro.

Cleanup the native implementation.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D26239628

fbshipit-source-id: 7f61c7204727bb2d739600a459f69c72842265c5
2021-02-04 12:34:48 -08:00
Peter Argany 5d4c3b8556 Cleanup - remove isDebuggingRemotely failsafe
Summary:
IIUC `isDebuggingRemotely` will never be set when `isDeviceDebuggingAvailable` is true. This was just a failsafe so that noone was trapped in an intermediate state.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D26239570

fbshipit-source-id: 8db6b022a0ea581216a1fa97b9d41f5ab6160562
2021-02-04 12:34:48 -08:00
Peter Argany 001dbf2068 Refactor notification subscriptions in RCTDevLoadingView
Summary:
In bridegless mode, `setBridge` is never called on native modules. This diff refactors out some setup logic into the module's init method.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D26211620

fbshipit-source-id: 7a9910198852dea5ac679762aa93dfea6fc47d70
2021-02-03 11:53:57 -08:00
Peter Argany 7186c4de4f Only show DevMenu on shake if RCTView is visible
Summary: Changelog: [iOS] Only show Dev Menu on shake if RN view is visible

Reviewed By: fkgozali

Differential Revision: D26138659

fbshipit-source-id: e2db287728675c7ead5fcbf569ed591638e2187e
2021-01-28 19:11:12 -08:00
Andres Suarez 0f4f917663 Apply clang-format update fixes
Reviewed By: igorsugak

Differential Revision: D25861683

fbshipit-source-id: 616afca13ae64c76421053ce49286035e0687e36
2021-01-09 22:11:00 -08:00
Ramanpreet Nara fb34fba01c Use native_module_spec_name to name codegen targets
Summary:
## Description
Suppose this was the codegen declaration before:

```
rn_library(
  name = "FooModule",
  native_module_spec_name = "FBReactNativeSpec",
  codegen_modules = True,
  # ...
)
```

Previously, this would generate the following BUCK targets:
- generated_objcpp_modules-FooModuleApple
- generated_java_modules-FooModuleAndroid
- generated_java_modules-FooModule-jniAndroid

## Changes
We will now generate:
- FBReactNativeSpecApple
- FBReactNativeSpecAndroid
- FBReactNativeSpec-jniAndroid

This matches the naming scheme of the old codegen.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25680224

fbshipit-source-id: 617ac18fd915f3277f6bd98072d147f20fb193e5
2020-12-24 00:50:01 -08:00
Ramanpreet Nara bccbf4d00a Round 3: Remove @synthesize bridge = _bridge from NativeModules
Reviewed By: fkgozali, ejanzer, mdvacca

Differential Revision: D25649765

fbshipit-source-id: 3ba6d977abce145039f6bdc581283c19445a1032
2020-12-19 06:01:48 -08:00
Ramanpreet Nara a26f20dc9a Codemod away from RCTBridge uiManager viewForReactTag
Summary: Changelog: [Internal]

Reviewed By: fkgozali, mdvacca

Differential Revision: D25648595

fbshipit-source-id: 7b338500e7d13ff12c9969663768408ede8e0ee3
2020-12-19 06:01:48 -08:00
Ramanpreet Nara df0bfec201 Round 2: Remove synthesize bridge = _bridge
Summary:
All NativeModules that used to use the bridge to require other NativeModules now require other NativeModules via the Venice-compatible RCTModuleRegistry abstraction. Therefore, we can safely get rid of synthesize bridge = _bridge from them.

## How did I generate this diff?
1. Search for all NativeModules that have `synthesize bridge =`
2. Remove the `synthesize bridge = _bridge` from each NativeModule, and if it doesn't contain `_bridge`, `setBridge:`, or `elf.bridge`, add it to this codemod.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25551295

fbshipit-source-id: 585d50ad55cb9ab083e430b07e1cf30e31f0d3c5
2020-12-17 10:13:32 -08:00
Ramanpreet Nara ff980050c9 Manual: Migrate from bridge.accessibilityManager to RCTModuleRegistry
Summary:
Ran `xbgs .accibilityManager`, and found all the NativeModules that used the bridge to access AccessibilityManager. Then, I migrated them to use RCTModuleRegistry.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25504726

fbshipit-source-id: fcfb1fffbeedc136ee160d043949d9859300b1e3
2020-12-12 19:02:04 -08:00
Ramanpreet Nara 938bfed96d Manual: Migrate from bridge.redBox to RCTModuleRegistry
Summary:
Ran `xbgs .redBox`, and found all the NativeModules that used the bridge to access RedBox. Then, I migrated them to use RCTModuleRegistry.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D25507829

fbshipit-source-id: 91033ca4c57d5be5e8e6fa904b636960ec12c584
2020-12-12 19:02:03 -08:00
Ramanpreet Nara 60641c543d Manual: Migrate from bridge.devSettings to RCTModuleRegistry
Summary:
Ran `xbgs .devSettings`, and found all the NativeModules that used the bridge to access DevSettings. Then, I migrated them to use RCTModuleRegistry.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25503402

fbshipit-source-id: 26afc45cd1bc63d5de99ea331e7b2949b66be7ce
2020-12-12 19:02:03 -08:00
Ramanpreet Nara 41929eb9c5 Codemod: Migrate from bridge.devSettings to RCTModuleRegistry
Summary:
All NativeModules that access the _bridge from self to require the DevSettings NativeModule now instead get the DevSettings NativeModule from the _moduleRegistry.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25503289

fbshipit-source-id: ebd1fd45d40aca37c0ead83bbaab59fa99d45044
2020-12-12 19:02:03 -08:00
Ramanpreet Nara e1fea9d152 Manual: Migrate from bridge.devMenu to RCTModuleRegistry
Summary:
Ran xbgs `.devMenu`, and found all the NativeModules that used the bridge to access DevMenu. Then, I migrated them to use RCTModuleRegistry.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25499960

fbshipit-source-id: 70478616d44808f3788dd0b194da155db0877db9
2020-12-12 19:02:03 -08:00
Ramanpreet Nara 1f883192ec Manual: Migrate from bridge.eventDispatcher to RCTModuleRegistry
Summary:
This is an extension of D25449795. I searched for all usages of .eventDispatcher within NativeModules, and migrated them all to the Venice-compatible RCTModuleRegistry API.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25473844

fbshipit-source-id: 2b8deec236e019f3adfb59fadd745c249ff822f4
2020-12-11 10:42:28 -08:00
Ramanpreet Nara 74fd6fb1da Codemod: Migrate from bridge.eventDispatcher to RCTModuleRegistry
Summary:
All NativeModules that use the bridge to require the eventDispatcher are now instead using the RCTModuleRegistry I introduced in D25412847 (0ed81b28d3).

## What does this codemod do?
For all ObjC files that contain `synthesize bridge = _bridge`, migrate calls that access the React Native bridge from `self`, and use it to load the event dispatcher.

**Thoughts on Codemod Safety:** If we can access the bridge from self, then that means that if we synthesize the module registry, we can access the module registry from self. Therefore, this codemod is safe.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25449795

fbshipit-source-id: 2f7235d14659e73d673ae08763dc2cccdde55a19
2020-12-11 10:42:28 -08:00
Aditya Kumar e1d7dd3105 sed OBJC_ARC_PREPROCESSOR_FLAGS/get_preprocessor_flags_for_build_mode
Summary: This diff doesn't change any functionality.

Reviewed By: adamjernst

Differential Revision: D25466557

fbshipit-source-id: 813f9631b92e8145b932955cad64a0c4582281e8
2020-12-11 10:18:33 -08:00
Peter Argany 471f6ad358 Fix isIPhoneX check for >=iPhone12
Summary:
Grabbed sizes from https://ios-resolution.com/

Some alternative ways we could do this:
https://stackoverflow.com/questions/52402477/ios-detect-if-the-device-is-iphone-x-family-frameless
https://stackoverflow.com/questions/11197509/how-to-get-device-make-and-model-on-ios

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25408465

fbshipit-source-id: 597f185fecfd7f146036dabfaf9a802328307cab
2020-12-09 08:30:13 -08:00
Peter Argany dee937c7c1 Fix retain cycle in RCTAlertController
Summary:
`RCTAlertController` creates a new window, and presents itself in that window.

RCTAlertController strongly retains the window, and the window strongly retains RCTAlertController when presenting it.

This adds a new method to break that cycle once alert is dismissed.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D25312413

fbshipit-source-id: e4048922aa697eb42c4c149827bac61bc7bc5528
2020-12-04 18:12:23 -08:00
generatedunixname89002005325676 a023ff0bd4 Daily `arc lint --take CLANGFORMAT`
Reviewed By: zertosh

Differential Revision: D25117167

fbshipit-source-id: 1eb415aa139a9be92676202ffdc1a901043122b9
2020-11-20 06:44:11 -08:00
Luke Walczak a7c1c5aff2 Add possibility to disable buttons in action sheet ios (#28979)
Summary:
_**Fixed**_ version of [the previous PR](https://github.com/facebook/react-native/pull/28792) after reverting [changes](c8d678abcf (commitcomment-39299254))

----

I've noticed that currently there is no option to disable button within the `ActionSheetIOS`. It can be really useful and decided to extend the API to support that functionality.

I added a new option called `disabledButtonsIndices` to `ActionSheetIOS` which is an array of button indices which should be disabled.

`ActionSheetIOS` documentation - PR https://github.com/facebook/react-native-website/pull/1898

## Changelog

[iOS] [Added] - Add disableButtonsIndices option to ActionSheetIOS component

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

Test Plan:
1. Run the `RNTester`
2. Choose `ActionSheetIOS`
3. Check the fourth example `Show Action Sheet with disabled buttons`
4. `Option 1` and `Option 2` should be disabled

screenshot | gif
 --- | ---
<img width="493" alt="Screenshot 2020-04-30 at 15 16 22" src="https://user-images.githubusercontent.com/22746080/80739025-1ec52780-8b16-11ea-8b1c-30bb40ad8c99.png"> | <img src="https://user-images.githubusercontent.com/22746080/80739043-24227200-8b16-11ea-8bcb-af25eb57baac.gif" width="493" />

Reviewed By: sammy-SC

Differential Revision: D21727497

Pulled By: PeteTheHeat

fbshipit-source-id: 749b6c623eb8a44fe2bd96829ce89be5310e2368
2020-11-18 21:11:48 -08:00
Peter Argany ab21d7320e Fix crash in RCTEventEmitter
Summary:
According to the crash, RCTEventEmitter is being asked to emit events before RN is set up {emoji:1f928}. Neither the bridge, nor bridgeless mode is ready to send events.

In this scenario, drop the events on the floor instead of crashing.
Changelog: [Internal]

Reviewed By: naftaly

Differential Revision: D24634701

fbshipit-source-id: 933e5dfd15e5ee7c2215489305c71de46e78a9e5
2020-10-29 22:07:09 -07:00
Kevin Gozali e9116519c8 Codegen iOS: use the codegen target from Libraries just like for Android
Summary:
To unify with Android, this uses the target off the same BUCK file.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24522269

fbshipit-source-id: 5aa0c08962890b884081faeb1ec801aebec9c2dd
2020-10-26 22:02:05 -07:00
Héctor Ramos 9218e0c2e6 iOS: Generate FBReactNativeSpec ObjC++ files at build time
Summary:
Removes the generated FBReactNativeSpec files from source control.

## Generating FBReactNativeSpec files

The files will be generated automatically by CocoaPods when the `RNTesterPods` Xcode workspace is generated:

```
cd packages/rn-tester
pod install
```

The spec files can be re-generated by invoking the script directly:
```
./scripts/generate-native-modules-specs.sh
```

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24261167

fbshipit-source-id: acb7ac856e5e519932e4f587f79e24f49cd84a91
2020-10-21 20:47:09 -07:00
Ramanpreet Nara 5a57a538c9 Split NativeAsyncStorage into NativeAsyncLocalStorage and NativeAsyncSQLiteDBStorage
Summary:
Although the interface for both NativeModules is the same, we'd like to enforce 1 `TurboModuleRegistry.get` call per NativeModule spec file. Therefore this diff splits the one spec into two.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24325260

fbshipit-source-id: f18718e4235b7b8ccbfc44a7e48571ecf483a36c
2020-10-15 08:49:28 -07:00
Lulu Wu ea93151f21 Make RCTEventDispatcher TurboModule-compatible
Summary:
This diff ended up being a bit more complicated than I anticipated, since the source files in `ReactInternal` were depending on `RCTEventDispatcher`. I made the following changes:
1. Make `RCTEventDispatcher` a `protocol`, keep it in `ReactInternal`.
2. Rename the `RCTEventDispatcher` NativeModule to `RCTEventDispatcherModule`, make it conform to the `RCTEventEmitter` `protocol`, and move it to `CoreModules`.
3. Where necessary, replace categories of `RCTEventDispatcher` with functions.

Changelog:
[iOS][Added] - Make RCTEventDispatcher TurboModule-comaptible

Reviewed By: fkgozali

Differential Revision: D18439488

fbshipit-source-id: b3da15c29459fddf884519f33b0c3b8c036b5539
2020-10-14 02:40:10 -07:00
Peter Argany 760c10a5aa Fix new RCTDeviceInfo assert to work in bridgeless mode
Summary:
shergin added a new assert to dimensions calculations in D24038911 (e853722981). This crashes in bridgeless mode b/c no bridge.

 This diff uses `turboModuleRegistry` as a bridge workaround.  The registry is a [weak property](https://www.fburl.com/diffusion/sunv3bx9) so retain cycles shouldn't be an issue here, let me know if that's incorrect.

As a nice bonus, this fixes dynamic font sizing in bridgeless mode. It was broken before since it relied on the bridge.

Changelog: [Internal]

Reviewed By: ejanzer

Differential Revision: D24256338

fbshipit-source-id: 141d36239ac6a6e9e87ca96eea7aeec56729095d
2020-10-12 12:49:29 -07:00
Mark Sinkovics 748aa13747 fix: crash when insert nil value into a dictionary (#30066)
Summary:
This PR attempts to fix issue https://github.com/facebook/react-native/issues/28278 and https://github.com/facebook/react-native/issues/29525

On Crashlytics, the following error occurs in file `RCTWebSocketModule.m` at method `-[RCTWebSocketModule webSocket:didFailWithError:]` when a nil value is inserted into a dictionary as a value.

```
Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
```

This PR is following the suggestion of this: https://github.com/facebook/react-native/issues/28278#issuecomment-597461650 and it replaces the values of any property if it is nil. In detail:
- it converts `error` to empty NSString if the original value is nil
- it converts `socketID` to a NSNumber object, which stores `-1` if the original value is nil

## Changelog

[iOS] [Fixed] - A crash in WebSocket module

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

Test Plan: We were not able to reproduce the crash, but the report itself provided enough information to find a solution for this issue.

Reviewed By: shergin

Differential Revision: D24241147

Pulled By: sammy-SC

fbshipit-source-id: d5d632b49ca77b5d8be8b9c32358bef68f17d30a
2020-10-12 01:47:49 -07:00
Dustin Shahidehpour 1511bfa028 Do another passthrough of labeling.
Summary:
At this point, I think we are ready to enable validation

Changelog: [INTERNAL]

Differential Revision: D24062829

fbshipit-source-id: c82dcd2c376e5cdeb164451e16b6fb3a666106f4
2020-10-02 08:49:06 -07:00
Valentin Shergin e853722981 A couple of checks for corner cases in RCTGetDimensions and RCTExportedDimensions
Summary: We need this checks to make the results of those function more reliable.

Reviewed By: sammy-SC

Differential Revision: D24038911

fbshipit-source-id: 3b54fe3056c9508cde84ea157beebea57e7e49b6
2020-10-01 13:19:52 -07:00
simek 2160377574 remove most of tvOS remnants from the code (#29407)
Summary:
Refs: [0.62 release](https://reactnative.dev/blog/#moving-apple-tv-to-react-native-tvos), https://github.com/facebook/react-native/issues/28706, https://github.com/facebook/react-native/issues/28743, https://github.com/facebook/react-native/issues/29018

This PR removes most of the tvOS remnants in the code. Most of the changes are related to the tvOS platform removal from `.podspec` files, tvOS specific conditionals removal (Obj-C + JS) or tvOS CI/testing pipeline related code.

In addition to the changes listed above I have removed the deprecated `Platform.isTVOS` method. I'm not sure how `Platform.isTV` method is correlated with Android TV devices support which is technically not deprecated in the core so I left this method untouched for now.

## Changelog

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

* **[Internal] [Removed]** - remove most of tvOS remnants from the code:
  * `TVEventHandler`, `TVTouchable`, `RCTTVView`, `RCTTVRemoteHandler` and `RCTTVNavigationEventEmitter`
* **[Internal] [Removed]** - remove `TARGET_TV_OS` flag and all the usages
* **[iOS] [Removed]** - remove deprecated `Platform.isTVOS` method
* **[iOS] [Removed]** - remove deprecated and TV related props from View:
  * `isTVSelectable`, `hasTVPreferredFocus` and `tvParallaxProperties`
* **[iOS] [Removed]** - remove `BackHandler` utility implementation

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

Test Plan: Local tests (and iOS CI run) do not yield any errors, but I'm not sure how the CI pipeline would react to those changes. That is the reason why this PR is being posted as Draft. Some tweaks and code adjustment could be required.

Reviewed By: PeteTheHeat

Differential Revision: D22619441

Pulled By: shergin

fbshipit-source-id: 9aaf3840c5e8bd469c2cfcfa7c5b441ef71b30b6
2020-09-28 21:26:41 -07:00
Scott Kyle 23717e48af Call stopObserving on correct queue
Summary:
Since `dealloc` can be called from any thread, this would result `stopObserving` being called on a different thread/queue than the specified `methodQueue`. We specifically encountered this issue with a module needing the main queue having its `stopObserving` called on a background queue.

Changelog:
[iOS][Fixed] - Call [RCTEventEmitter stopObserving] on specified method queue

Reviewed By: RSNara

Differential Revision: D23821741

fbshipit-source-id: 693c3be6876f863da6dd214a829af2cc13a09c3f
2020-09-21 17:30:34 -07:00
Ullrich Schäfer 845e9eaafb Fix for loading state of Fast Refresh from user defaults (#29880)
Summary:
Disabling Fast Refresh won't be persisted when restarting the app.

I believe this regressed with 824e171117. In this commit `HMRClient.setup` will always be called with `enabled` being set true. This PR loads the _enabled_ state from the user defaults (as it was done before).

## Changelog

[iOS] [Fixed] - Enable Fast Refresh gets persisted across app launches

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

Test Plan:
Without this change Fast Refresh is enabled on every app restart.

Tested with this change:
- Disabling Fast Refresh
- Restarting App -> Fast Refresh still disabled
- Enabled Fast Refresh again
- Restarting App -> Fast Refresh still enabled again

Reviewed By: sammy-SC

Differential Revision: D23686435

Pulled By: PeteTheHeat

fbshipit-source-id: 42c31b22060d3dc4b1d4cb8f41792b303fc7fce8
2020-09-14 17:45:53 -07:00
Eloy Durán 941bc0ec19 Upstream RN macOS Hermes integration bits (#29748)
Summary:
Microsoft’s RN for macOS fork supports the Hermes engine nowadays https://github.com/microsoft/react-native-macos/pull/473. As a longer term work item, we’ve started moving bits that are not invasive for iOS but _are_ a maintenance burden on us—mostly when merging—upstream. Seeing as this one is a recent addition, it seemed like a good candidate to start with.

As to the actual changes, these include:

* Sharing Android’s Hermes executor with the objc side of the codebase.
* Adding a CocoaPods subspec to build the Hermes inspector source and its dependencies (`Folly/Futures`, `libevent`).
* Adding the bits to the Xcode build phase script that creates the JS bundle for release builds to compile Hermes bytecode and source-maps…
* …coincidentally it turns out that the Xcode build phase script did _not_ by default output source-maps for iOS, which is now fixed too.

All of the Hermes bits are automatically enabled, on macOS, when providing the `hermes-engine-darwin` [npm package](https://www.npmjs.com/package/hermes-engine-darwin) and enabling the Hermes pods.

## Changelog

[General] [Added] - Upstream RN macOS Hermes integration bits

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

Test Plan:
Building RNTester for iOS and Android still works as before.

To test the actual changes themselves, you’ll have to use the macOS target in RNTester in the macOS fork, or create a new application from `master`:

<img width="812" alt="Screenshot 2020-08-18 at 16 55 06" src="https://user-images.githubusercontent.com/2320/90547606-160f6480-e18c-11ea-9a98-edbbaa755800.png">

Reviewed By: TheSavior

Differential Revision: D23304618

Pulled By: fkgozali

fbshipit-source-id: 4ef0e0f60d909f3c59f9cfc87c667189df656a3b
2020-08-27 01:18:33 -07:00
Peter Argany 38c3b95798 Bridgeless support for RCTKeyboardObserver
Summary:
RCTKeyboardObserver only uses the bridge to avoid sending events during a reload. See D6573855 (d9c658566a) for reference.

In bridgeless mode, the bridge is expected to always be nil, as the module uses `invokeJS` block to send events instead.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D23176990

fbshipit-source-id: 7946c9c2684d7d9ea0a606bad375309a5530a719
2020-08-21 13:21:12 -07:00
Lulu Wu bdbb040382 Fix Logbox Fullscreen View
Summary:
Logbox inside bridgeless surfaces was crashing and not able to open, this diff should fix it.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23043773

fbshipit-source-id: 6e584f97e53e626b9bfedd6dc997ba6ba8c08b8f
2020-08-18 12:29:45 -07:00
Devon Deonarine f319ff321c iOS: Update RCTAlertManager to use new RCTAlertController (#29295)
Summary:
This should fix https://github.com/facebook/react-native/issues/29082 and https://github.com/facebook/react-native/issues/10471

Currently when an alert is being shown while a modal is being dismissed, it causes the alert not to show and In some cases it causes the UI to become unresponsive. I think this was caused by using RCTPresentedViewController to try and display the Alert the currently presented view. The View the Alert was going to be shown on is dismissed and the modal doesn't show. I implemented a new RCTAlertController to show the alert on top of the view, the modal being dismissed should now not interfere with the alert being shown.

## Changelog

[iOS] [Fixed] - Fixed showing Alert while closing a Modal

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

Test Plan:
To recreate the bug:

1. npx react-native init Test --version 0.63.0-rc.1
2. Paste the following code into App.js

```javascript
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * format
 * flow strict-local
 */

import React from 'react';
import {
  SafeAreaView,
  StyleSheet,
  View,
  Text,
  StatusBar,
  Modal,
  Alert
} from 'react-native';

const App: () => React$Node = () => {
  const [visible, setVisible] = React.useState(false)

  const onShowModal = () => {
    setVisible(true)
  }

  onCloseBroken = () => {
    setVisible(false)
    Alert.alert('Alert', 'Alert won\'t show')
  }

  onCloseWorking = () => {
    setVisible(false)
    setTimeout(() => Alert.alert('Alert', 'Works fine'), 10)
  }

  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView style={styles.container}>
        <Text onPress={onShowModal}>Show modal</Text>
      </SafeAreaView>
      <Modal animationType="fade" visible={visible} onRequestClose={onCloseWorking} >
        <View style={styles.container}>
          <Text onPress={onCloseBroken}>Close modal immediately</Text>
          <Text onPress={onCloseWorking}>Close modal with delay</Text>
        </View>
      </Modal>
    </>
  )
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'space-around',
  },
})

export default App

```

3. cd Test && npx react-native run-ios
4. Show the modal and click the `Close modal immediately` button

The first button doesn't show the alert, the second does because it gets rendered after the modal view is dismissed. After this commit, the alert always shows on top of every view properly. You can test by pointing the react native package to my branch by modifying the package json file like this

```
    "react-native": "https://github.com/devon94/react-native.git#fix-ios-modal"
```

I was unable to reproduce the case where it causes the UI to be responsive in the test app but was able to reproduce it in our react native app at work. I can provide a video later if needed but the code is too complex to simplify into a test case.

Reviewed By: sammy-SC

Differential Revision: D22783371

Pulled By: PeteTheHeat

fbshipit-source-id: 3e359645c610074ea855ee5686c59bdb9d6b696b
2020-08-06 16:20:47 -07:00
Peter Argany 448db78a88 Fix loading from Metro in Bridgeless mode (#29453)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/29453

Problem Statement: A native module needs to call a function on `ReactInstance` (in this case `loadScript`). Typically, this is handled by the bridge.
Current Bridgeless Solution: Create a new protocol (in this case `RCTJSScriptLoaderModule`) which lets a block be passed in TM init to forward the method call to `ReactInstance`. This is the best thing I could think of right now.

Changelog:[Internal]

Reviewed By: RSNara

Differential Revision: D22512748

fbshipit-source-id: e6559279b6e299e17d1199407129ad3902c41e6b
2020-07-23 17:11:32 -07:00
Ramanpreet Nara a27c295f53 Rename RCTTurboModuleLookupDelegate to RCTTurboModuleRegistry
Summary:
## Why?
1. RCTTurboModuleLookupDelegate sounds a bit nebulous.
2. In JS and Java, we use a `TurboModuleRegistry` interface to require TurboModules. So, this diff will make JS, Java, and ObjC consistent.

Changelog:
[Internal]

Reviewed By: PeteTheHeat

Differential Revision: D22405754

fbshipit-source-id: 30c85c246b39d198c5b8c6ca4432a3196ca0ebfd
2020-07-07 16:25:11 -07:00
Christoph Nakazawa 6d6c68c2c6 "The Metro Server" -> Metro
Summary:
Pet Peeve: Metro is a brand name. You don't say "the Metro server" just like you don't say "the iPhone phone". This is a leftover from when it used to be called "the packager server".

Note: It makes sense to refer to "the Metro server" when talking about it in the context of Metro's features, like if you are discussing "Metro's bundling" and "Metro's server". However, when talking about the tool itself, just Metro is enough.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D22330966

fbshipit-source-id: 667618363c641884df543d88cac65d1e44956ad3
2020-07-02 14:51:18 -07:00
Christoph Nakazawa ad879e50bc Add `RCTDevSplitBundleLoader` native module
Reviewed By: ejanzer

Differential Revision: D21302418

fbshipit-source-id: a868f6dad3306190c7add26e8f9a976866c16aef
2020-06-08 09:07:42 -07:00
Ramanpreet Nara 39d67737c0 Run getConstants method statements on main queue
Summary:
If a NativeModule requires main queue setup, its `getConstants()` method must be executed on the main thead. The legacy NativeModule infra takes care of this for us. With TurboModules, however, all synchronous methods, including `getConstants()`, execute on the JS thread. Therefore, if a TurboModule requires main queue setup, and exports constants, we must execute its `getConstants()` method body on the main queue explicitly.

**Notes:**
- The changes in this diff should be a noop when TurboModules is off, because `RCTUnsafeExecuteOnMainQueueSync` synchronously execute its block on the current thread if the current thread is the main thread.
- If a NativeModule doens't have the `requiresMainQueueSetup` method, but has the `constantsToExport` method, both NativeModules and TurboModules assume that it requires main queue setup.

## Script
```
const exec = require("../lib/exec");
const abspath = require("../lib/abspath");
const relpath = require("../lib/relpath");
const readFile = (filename) => require("fs").readFileSync(filename, "utf8");
const writeFile = (filename, content) =>
  require("fs").writeFileSync(filename, content);

function main() {
  const tmFiles = exec("cd ~/fbsource && xbgs -n 10000 -l constantsToExport")
    .split("\n")
    .filter(Boolean);

  const filesWithoutConstantsToExport = [];
  const filesWithConstantsToExportButNotGetConstants = [];
  const filesExplicitlyNotRequiringMainQueueSetup = [];

  tmFiles
    .filter((filename) => {
      if (filename.includes("microsoft-fork-of-react-native")) {
        return false;
      }

      return /\.mm?$/.test(filename);
    })
    .map(abspath)
    .forEach((filename) => {
      const code = readFile(filename);
      const relFilename = relpath(filename);

      if (!/constantsToExport\s*{/.test(code)) {
        filesWithoutConstantsToExport.push(relFilename);
        return;
      }

      if (!/getConstants\s*{/.test(code)) {
        filesWithConstantsToExportButNotGetConstants.push(relFilename);
        return;
      }

      if (/requiresMainQueueSetup\s*{/.test(code)) {
        const requiresMainQueueSetupRegex = /requiresMainQueueSetup\s*{\s*return\s+(?<requiresMainQueueSetup>YES|NO)/;
        const requiresMainQueueSetupRegexMatch = requiresMainQueueSetupRegex.exec(
          code
        );

        if (!requiresMainQueueSetupRegexMatch) {
          throw new Error(
            "Detected requiresMainQueueSetup method in file " +
              relFilename +
              " but was unable to parse the method return value"
          );
        }

        const {
          requiresMainQueueSetup,
        } = requiresMainQueueSetupRegexMatch.groups;

        if (requiresMainQueueSetup == "NO") {
          filesExplicitlyNotRequiringMainQueueSetup.push(relFilename);
          return;
        }
      }

      const getConstantsTypeRegex = () => /-\s*\((?<type>.*)\)getConstants\s*{/;
      const getConstantsTypeRegexMatch = getConstantsTypeRegex().exec(code);

      if (!getConstantsTypeRegexMatch) {
        throw new Error(
          `Failed to parse return type of getConstants method in file ${relFilename}`
        );
      }

      const getConstantsType = getConstantsTypeRegexMatch.groups.type;

      const getConstantsBody = code
        .split(getConstantsTypeRegex())[2]
        .split("\n}")[0];

      const newGetConstantsBody = `
  __block ${getConstantsType} constants;
  RCTUnsafeExecuteOnMainQueueSync(^{${getConstantsBody
    .replace(/\n/g, "\n  ")
    .replace(/_bridge/g, "self->_bridge")
    .replace(/return /g, "constants = ")}
  });

  return constants;
`;

      writeFile(
        filename,
        code
          .replace(getConstantsBody, newGetConstantsBody)
          .replace("#import", "#import <React/RCTUtils.h>\n#import")
      );
    });

  console.log("Files without constantsToExport: ");
  filesWithoutConstantsToExport.forEach((file) => console.log(file));
  console.log();

  console.log("Files with constantsToExport but no getConstants: ");
  filesWithConstantsToExportButNotGetConstants.forEach((file) =>
    console.log(file)
  );
  console.log();

  console.log("Files with requiresMainQueueSetup = NO: ");
  filesExplicitlyNotRequiringMainQueueSetup.forEach((file) =>
    console.log(file)
  );
}

if (!module.parent) {
  main();
}

```

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D21797048

fbshipit-source-id: a822a858fecdbe976e6197f8339e509dc7cd917f
2020-06-02 23:01:35 -07:00
Valentin Shergin c8d678abcf Revert D21396409: Add possibility to disable buttons in action sheet ios
Differential Revision:
D21396409

Original commit changeset: b3c3e4429651

fbshipit-source-id: 073bea94d96f0ebbb474c474c73e4e3f01f27b2e
2020-05-19 16:36:32 -07:00
lukewalczak f0bf4b0986 Add possibility to disable buttons in action sheet ios (#28792)
Summary:
I've noticed that currently there is no option to disable button within the `ActionSheetIOS`. It can be really useful and decided to extend the API to support that functionality.

I added a new option called `disabledButtonsIndices` to `ActionSheetIOS` which is an array of button indices which should be disabled.

`ActionSheetIOS` documentation - PR https://github.com/facebook/react-native-website/pull/1898

## Changelog

[iOS] [Added] - Add disableButtonsIndices option to ActionSheetIOS component
Pull Request resolved: https://github.com/facebook/react-native/pull/28792

Test Plan:
1. Run the `RNTester`
2. Choose `ActionSheetIOS`
3. Check the fourth example `Show Action Sheet with disabled buttons`
4. `Option 1` and `Option 2` should be disabled

screenshot | gif
 --- | ---
<img width="493" alt="Screenshot 2020-04-30 at 15 16 22" src="https://user-images.githubusercontent.com/22746080/80739025-1ec52780-8b16-11ea-8b1c-30bb40ad8c99.png"> | ![action_sheet_disabled](https://user-images.githubusercontent.com/22746080/80739043-24227200-8b16-11ea-8bcb-af25eb57baac.gif)

Differential Revision: D21396409

Pulled By: shergin

fbshipit-source-id: b3c3e442965160e0c5e52854352f0540575c4d4c
2020-05-19 00:19:56 -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