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

18122 Коммитов

Автор SHA1 Сообщение Дата
Ramanpreet Nara 5e68a98c3d Make TurboModuleProviderFunctionType not depend on TurboModuleManager instance
Summary:
## Description
The C++ lambda that JS invokes to create TurboModules uses `TurboModuleManager`. It is possible for this lambda to outlive the `TurboModuleManager` instance because we delete `TurboModuleManager` on the JS Thread before we schedule the deletion of `CatalystInstanceImpl` object on a neutral third-party background thread. `CatalystInstanceImpl` owns the JS VM instance that owns the C++ lambda.

## [CatalystInstanceImpl.java](https://fburl.com/diffusion/vt4pwjwa)
```
public void destroy() {
  // ...

  getReactQueueConfiguration()
    .getJSQueueThread()
    .runOnQueue(
        new Runnable() {
          Override
          public void run() {
            // We need to destroy the TurboModuleManager on the JS Thread
            if (turboModuleManager != null) {
              turboModuleManager.onCatalystInstanceDestroy();
            }

            getReactQueueConfiguration()
                .getUIQueueThread()
                .runOnQueue(
                    new Runnable() {
                      Override
                      public void run() {
                        // AsyncTask.execute must be executed from the UI Thread
                        AsyncTask.execute(
                            new Runnable() {
                              Override
                              public void run() {
                                // Kill non-UI threads from neutral third party
                                // potentially expensive, so don't run on UI thread

                                // contextHolder is used as a lock to guard against
                                // other users of the JS VM having the VM destroyed
                                // underneath them, so notify them before we reset
                                // Native
                                mJavaScriptContextHolder.clear();

                                mHybridData.resetNative();
                                getReactQueueConfiguration().destroy();
                                Log.d(
                                    ReactConstants.TAG,
                                    "CatalystInstanceImpl.destroy() end");
                                ReactMarker.logMarker(
                                    ReactMarkerConstants.DESTROY_CATALYST_INSTANCE_END);
                              }
                            });
                      }
                    });
          }
        });
    }
  });

  // ...
}
```

The JS thread is also terminated in the neutral third-party thread. Therefore, it should be possible for JS to request a `TurboModule` after `TurboModuleManager` has been destroyed (i.e: JS can try to access memory that was freed). This is why I think we're getting a segfault in T54298358.

## Fix
The fix was to wrap all the member variables of TurboModuleManager we use in `TurboModuleProviderFunctionType` in weak references. This way, we can make sure that the memory is valid before using it.

Reviewed By: fkgozali

Differential Revision: D17539761

fbshipit-source-id: fe527383458a019a4cb9107ec5c3ddd6295ae41c
2019-09-26 09:34:41 -07:00
Eli White a2aa008b33 Remove unused flow suppressions
Summary: I'm trying to clean up core files and finding suppressions that aren't needed. Bulk removing them.

Reviewed By: cpojer

Differential Revision: D17586683

fbshipit-source-id: fc289bd70b0c928b49a75015ecb5aebe8ab4f1da
2019-09-26 08:16:24 -07:00
Eli White c0029be953 Update ReactNativeTypes from PR to React
Summary:
I upstreamed the changes to this file from previous commits to React in this (unlanded) PR: https://github.com/facebook/react/pull/16898#issuecomment-535248721

I had to make some additional changes to be able to make Flow pass there. Bringing those changes back to FBSource as well. Having this change made here will make the next sync easier as we won't have to deal with conflicts then.

Changelog:
[Internal]

Reviewed By: cpojer

Differential Revision: D17586781

fbshipit-source-id: 4be8376d0af4fb5d63410afaaf5bb0005d992981
2019-09-26 08:16:24 -07:00
Eli White 79e08f3c15 Add Flowtests for HostComponent
Summary:
`HostComponent` is built specifically to differentiate from `ReactNative.NativeComponent`. These tests should ensure that is the case, and help it stay that way.

I also expect these tests to be duplicated to DefinitelyTyped to help the team working on the TypeScript types ensure they have things modeled correctly.

Reviewed By: cpojer

Differential Revision: D17580120

fbshipit-source-id: c14eb18507cbee1b308beeff0092607e18706171
2019-09-26 08:16:23 -07:00
Eli White bcc58bce02 Strengthen flowtype of measureLayout
Summary:
MeasureLayout requires either a reactTag or a ref to a host component. Now that we have a type for Host Components we can be more differentiating here.

Also, because Object is treated as `any` in flow, the type was allowing the return from findNodeHandle or a ref itself be passed, even though both of those are nullable.

This change explicitly requires checking for null before calling the function which is consistent with the behavior of the implementation of measureLayout.

Changelog:
[Changed] Flowtype for measureLayout now disallows null as reactTag

Reviewed By: cpojer

Differential Revision: D17579300

fbshipit-source-id: af062fcd9dfc40eab42e5c5452af2ff653d0888e
2019-09-26 08:16:23 -07:00
Han Lin Yap babf67f11c Upgrade all dependencies in package.json template (#26563)
Summary:
Upgrade all dependencies in package.json template

## Changelog

[General] [Changed] - Upgrade to latest dependencies in package.json template
Pull Request resolved: https://github.com/facebook/react-native/pull/26563

Differential Revision: D17589559

Pulled By: cpojer

fbshipit-source-id: edbc9da11a850e01d00e77d9e689d9278a05f6fd
2019-09-25 22:03:45 -07:00
Andrea Cimitan 8d8c3d4e1e Also listen to NFC actions for linking url events (#26553)
Summary:
This PR solves bug https://github.com/facebook/react-native/issues/26552 for Android. Allows an app to receive url events through Linking from NFC tags

## Changelog
[Android] [Fixed] - This branch checks also for `ACTION_NDEF_DISCOVERED` intent matches to send the url events
Pull Request resolved: https://github.com/facebook/react-native/pull/26553

Test Plan: Tested the code multiple times with both NFC tags and normal links

Differential Revision: D17589654

Pulled By: cpojer

fbshipit-source-id: 55e854e765a84da5e22ec2cc51d0fe0972254175
2019-09-25 18:44:43 -07:00
Mats Byrkjeland 46090b0e56 Make RelativeImageStub regex match images in scoped packages (#26567)
Summary:
I am importing an image from a scoped package and I expected this to be recognized by the `module.name_mapper` and treated as a `RelativeImageStub`. But since there's an `@` in the path, the string does not match the regex pattern as it is defined today. Therefore I added the possibility of a `@` in the start of the path to the regex pattern.

Example import not recognized by the name_mapper today:
```
import NicePicture from 'example-pkg/assets/nice-picture.png'
```

## Changelog

[General] [Fixed] - Make RelativeImageStub regex match images in scoped packages
Pull Request resolved: https://github.com/facebook/react-native/pull/26567

Test Plan:
* I have run `yarn flow` in the `react-native` project
* I tested that it resolves my issue with images in scoped packages in my own app's repo

Differential Revision: D17589473

Pulled By: cpojer

fbshipit-source-id: d0c18f2b36456fd974012a0605f3d9ceff0ad744
2019-09-25 18:27:27 -07:00
Ilia Burdukovski 81a6b6ed3c fix build with hermes on windows (#26556)
Summary:
On the Windows platform, with hermes-engine enabled, the assembly crashes with an error:
![image](https://user-images.githubusercontent.com/8634793/65568495-ab11d980-df8c-11e9-83a0-2a2d26447860.png)
The problem lies in calling hermes command without the leading arguments `"cmd", "/c"` ([react.gradle, line: 152](e028ac7af2/react.gradle (L152)) )

## Changelog

[General] [Fixed] - Added a platform check and running commandLine with the corresponding arguments
Pull Request resolved: https://github.com/facebook/react-native/pull/26556

Test Plan:
Under Windows, enable hermes-engine in _build.gradle_ and run the `gradlew assembleRelease` or `gradlew bundleRelease` command
Also check assembly on other available platforms

Differential Revision: D17587023

Pulled By: cpojer

fbshipit-source-id: bab10213b23fac5ab6a46ac4929759dcd43e39c2
2019-09-25 17:51:48 -07:00
Juan Tejada f0bcfbe9be Upgrade eslint-plugin-relay to 1.3.12
Summary:
Bump eslint-plugin-relay version to 1.3.12 on fbsource
`js1 upgrade dependency --package eslint-plugin-relay@1.3.12`

Reviewed By: kassens

Differential Revision: D17581310

fbshipit-source-id: 6285843dd2f92c6cdd4f0fe0bc2ac7f5c78dbff2
2019-09-25 16:00:05 -07:00
Peter Argany a6a6dbe05c Split up createTimer into two methods, createTimer and createTimerForNextFrame
Summary:
This diff adds nuance to timer creation.  Imagine the following bit of JS:

```
    setTimeout(() => {
      console.log("Timeout")
    }, 0);
    setImmediate(() => {
      setNine("Immediate");
    });
```

In classic RN, `setTimeout` will be called async by the bridge, immediate is implemented in JS, so the ordering of logs will be:

1. Immediate
2. Timeout

In bridgeless RN `setTimeout` is called sync, so the ordering of the logs is:

1. Timeout
2. Immediate

In order to preserve ordering, this diff adds a timer creation method which doesn't immediately invoke it, but waits one frame to do so.

This PR does the same thing for android, and explains the reasoning for preserving behaviour (some products may rely on this behaviour) f054928124

Reviewed By: ejanzer

Differential Revision: D17535639

fbshipit-source-id: 3f734c420a6a95be2ee10e8d6ac48adc79ef1c96
2019-09-25 15:31:26 -07:00
Logan Daniels 1bfd15ccb6 Re-land stack of D17563110: codemod xplat/js
Summary:
The stack of D17563110 was reverted because it triggered a failing OTA job that wasn't caught at land time.

Fixing the issue by reverting the change to `Route.js` and re-landing the rest of the diff.

Differential Revision: D17564219

fbshipit-source-id: 166b50a163ce8ae226de224882a98c40652e29ac
2019-09-25 14:47:02 -07:00
Eli White 5876052615 Make setting useNativeDriver required. Add runtime warning if not specified
Summary:
We found that many callsites existed that could be using the native driver, but weren't. In order to help people use it when appropriate and eventually switch the default, we are requiring that useNativeDriver is explicit, even when set to false.

This change adds a runtime warning if useNativeDriver is not specified, hopefully giving some light feedback to remember to use the native driver when you can. Without it being explicit it is very easy to forget setting this.

Reviewed By: JoshuaGross

Differential Revision: D17575918

fbshipit-source-id: e54612d87177e1821692b7de20fe673df0e890d2
2019-09-25 13:36:27 -07:00
Eli White 62acf6e26a Update codegen test fixtures to use HostComponent
Summary:
Changelog:
[Internal] Update codegen test fixtures to use HostComponent

Reviewed By: JoshuaGross

Differential Revision: D17573955

fbshipit-source-id: bae3ab44c5d300d4b9297fcb243e49667776f9bc
2019-09-25 13:16:04 -07:00
Eli White a446a38aaa Add HostComponent to the public API of React Native
Summary:
In React Native there are three types of "Native" components.

```
createReactClass with NativeMethodsMixin
```
```
class MyComponent extends ReactNative.NativeComponent
```
```
requireNativeComponent('RCTView')
```

The implementation for how to handle all three of these exists in the React Native Renderer. Refs attached to components created via these methods provide a set of functions such as
```
.measure
.measureInWindow
.measureLayout
.setNativeProps
```

These methods have been used for our core components in the repo to provide a consistent API. Many of the APIs in React Native require a `reactTag` to a host component. This is acquired by calling `findNodeHandle` with any component. `findNodeHandle` works with the first two approaches.

For a lot of our new Fabric APIs, we will require passing a ref to a HostComponent directly instead of relying on `findNodeHandle` to tunnel through the component tree as that behavior isn't safe with React concurrent mode.

The goal of this change is to enable us to differentiate between components created with `requireNativeComponent` and the other types. This will be needed to be able to safely type the new APIs.

For existing components that should support being a host component but need to use some JS behavior in a wrapper, they should use `forwardRef`. The majority of React Native's core components were migrated to use `forwardRef` last year. Components that can't use forwardRef will need to have a method like `getNativeRef()` to get access to the underlying host component ref.

Reviewed By: rickhanlonii

Differential Revision: D17563615

fbshipit-source-id: b9e6042805517d502770fcba37301c2c5b6452b6
2019-09-25 11:44:38 -07:00
Eli White 0676ebf79a Migrate NativeComponentType from codegenNativeComponent to HostComponent #2
Summary:
We need to migrate to HostComponent instead of the exported type from codegenNativeComponent which is the same type

Changelog:
[Internal] Migrate NativeComponentType from codegenNativeComponent to HostComponent

Reviewed By: rickhanlonii

Differential Revision: D17563307

fbshipit-source-id: 01c8fea8c67b33bed42ae28ffb8c132be87b9a7a
2019-09-25 11:44:38 -07:00
Eli White 1b4eaeb184 Migrate NativeComponentType from codegenNativeComponent to HostComponent #1
Summary:
We need to migrate to HostComponent, this is the first batch.

Changelog:
[Internal] Migrate NativeComponentType from codegenNativeComponent to HostComponent

Reviewed By: rickhanlonii

Differential Revision: D17562879

fbshipit-source-id: ce1993b64a79cede3598c89ddff0dadf07fde92f
2019-09-25 11:44:38 -07:00
Logan Daniels 89e3f70eab Upgrade nullthrows to ^1.1.1
Reviewed By: TheSavior

Differential Revision: D17552725

fbshipit-source-id: 535faeb8d9ca2b901c5342a48ccba7fc26aebd4f
2019-09-25 10:16:00 -07:00
Eli White 69c38e5a63 Introduce flow type to differentiate between HostComponent, NativeMethodsMixin, and NativeComponent
Summary:
In React Native there are three types of "Native" components.

```
createReactClass with NativeMethodsMixin
```
```
class MyComponent extends ReactNative.NativeComponent
```
```
requireNativeComponent('RCTView')
```

The implementation for how to handle all three of these exists in the React Native Renderer. Refs attached to components created via these methods provide a set of functions such as
```
.measure
.measureInWindow
.measureLayout
.setNativeProps
```

These methods have been used for our core components in the repo to provide a consistent API. Many of the APIs in React Native require a `reactTag` to a host component. This is acquired by calling `findNodeHandle` with any component. `findNodeHandle` works with the first two approaches.

For a lot of our new Fabric APIs, we will require passing a ref to a HostComponent directly instead of relying on `findNodeHandle` to tunnel through the component tree as that behavior isn't safe with React concurrent mode.

The goal of this change is to enable us to differentiate between components created with `requireNativeComponent` and the other types. This will be needed to be able to safely type the new APIs.

For existing components that should support being a host component but need to use some JS behavior in a wrapper, they should use `forwardRef`. The majority of React Native's core components were migrated to use `forwardRef` last year. Components that can't use forwardRef will need to have a method like `getNativeRef()` to get access to the underlying host component ref.

Note, we will need follow up changes as well as changes to the React Renderer in the React repo to fully utilize this new type.

Changelog:
[Internal] Flow type to differentiate between HostComponent and NativeMethodsMixin and NativeComponent

Reviewed By: jbrown215

Differential Revision: D17551089

fbshipit-source-id: 7a30b4bb4323156c0b2465ca41fcd05f4315becf
2019-09-25 10:12:38 -07:00
Uts Sikder 94e8ccf9c0 BREAKING: rm YogaNode parameter from YogaLogger#log
Summary:
In D17439957, I noted that YogaLogger#log throws a NoMethodFoundException when called from C++ b/c C++ and Java's signatures of that method don't match. C++ uses YogaNodeJNIBase for the first param, Java uses YogaNode. Both my attempts to fix this failed.

Attempt #1 - Make Java use YogaNodeJNIBase. This doesn't work because the :java-interface target includes YogaLogger but not YogaNodeJNIBase. Moving YogaLogger to the impl target doesn't work either b/c other files in :java-interface reference YogaLogger.

Attempt #2 - Make C++ use YogaNode. This doesn't work b/c we try to call the log method with objects of fbjni type YogaNodeJNIBase. This would be fine in Java since YogaNodeJNIBase extends YogaNode. But fbjni's typing isn't advanced enough to know this, so the Yoga C++ fails to compile.

At this point, I was wondering what the value of having this param in the log function at all was. None of the implementations in our codebase use it today. It might be easier to just remove it all together. This also removes a bug with YGNodePrint where we pass a null layout context that eventually causes a SIG_ABRT when we use it to try to find a YogaNode to pass to this function. (https://fburl.com/diffusion/ssw9h8lv).

Reviewed By: amir-shalem

Differential Revision: D17470379

fbshipit-source-id: 8fc2d95505971a52af2399a9fbb60b63f27f0ec2
2019-09-25 09:12:43 -07:00
Eli White e028ac7af2 Fix ref and component return types
Summary:
These types aren't robust to changes in the React component type. When we refactor requireNativeComponent these will error. This change is forwards compatible.

Changelog:
[Internal] Improve internal type in DrawerLayoutAndroid

Reviewed By: JoshuaGross

Differential Revision: D17561194

fbshipit-source-id: 470289449b4d5b3148692f1945fb720e1e3972eb
2019-09-24 18:51:46 -07:00
Eli White 419722bd07 Flow type vendor/core/merge.js
Summary:
This is used by Image.android.js and needs to be flow typed to be able to have confidence in the requireNativeComponent type change

Changelog:
[Internal] Flow type vendor/core/merge.js

Reviewed By: JoshuaGross

Differential Revision: D17561195

fbshipit-source-id: 2639f2628e15b2dd5469bb2ebfe935a444025a21
2019-09-24 18:51:45 -07:00
Joshua Gross fb90f64d9c Collect more information on Debug T48643168
Summary:
It's possible that this crashes because the callback is non-null/non-undefined but isn't a function; if so, I would like to collect that information.

 These changes have already been made in the React repo.

Reviewed By: TheSavior

Differential Revision: D17559022

fbshipit-source-id: a0538d533c3c482d27eef0ed3c8c980e2bc8e817
2019-09-24 18:35:13 -07:00
Joshua Gross c16b219456 Revert D17518337: [flow][types-first] Export types so codemod can use them
Differential Revision:
D17518337

Original commit changeset: 253bf0fb4955

fbshipit-source-id: 4bd08c1061f6759f08f1186f5bd5a2c207c96315
2019-09-24 17:21:30 -07:00
Mehdi Mulani 2fbe956aac Make NSData usage in RCTNetworkTask threadsafe
Summary:
@public
We're seeing crashes from multiple threads trying to call `[NSData appendData:]` at the same time. Usually the RCTURLRequestHandlers implementation avoids this but if you're using a background queue, it is pretty easy to reach this case.
Adding a lock to accessors of `_data` should prevent this.

Reviewed By: shergin

Differential Revision: D17552136

fbshipit-source-id: 3384d36221d0ada8cda638ad8e79e1bf3862f93f
2019-09-24 12:41:05 -07:00
Logan Daniels 4f7659d675 Export types so codemod can use them
Reviewed By: panagosg7

Differential Revision: D17518337

fbshipit-source-id: 253bf0fb4955efc7788be1bc4e662bed37e67acf
2019-09-24 10:00:59 -07:00
Emily Janzer 6464ef0a92 Add @DoNotStrip to JavaScriptModule interfaces
Summary: Adding `DoNotStrip` to all the interfaces that extend `JavaScriptModule` to ensure they don't get stripped from release builds (because they have no Java implementors).

Reviewed By: emma0303

Differential Revision: D17534719

fbshipit-source-id: a793764caf17040bf1252be7ec4c72176d6989d4
2019-09-24 09:36:16 -07:00
Emily Janzer 990c9ea5ec Remove bridge access from JavaTimerManager, again
Summary: Another attempt at D17282188, which got partially reverted in D17505827 due to a crash in release builds.

Reviewed By: RSNara

Differential Revision: D17512419

fbshipit-source-id: a1b0abfed2c4a1f3f02da85e84abee0127b1a7e2
2019-09-23 19:14:43 -07:00
Valentin Shergin 3bc09892c0 Fabric: Enforcing const-correctness around ImageResponseObserverCoordinator
Summary:
`addObserver` and `removeObserver` now accepts const references instead of pointers which indicates the intent (non-nullability and non-owning) clearly. The delegate methods are also marked as `const` to designate the possible concurrent execution (`const` means "thread-safe" here).

All changes are pure syntactical, nothing really changes (besides the fact overall code quality and redability).

Reviewed By: JoshuaGross

Differential Revision: D17535395

fbshipit-source-id: b0c6c872d44fee22e38fd067ccd3320e7231c94a
2019-09-23 15:59:45 -07:00
Valentin Shergin 5dc16e2f43 Fabric: Fixed possible data race in ImageResponseObserverCoordinator
Summary:
# A race condition
The practical thing of this diff is fixing a data race.
Imagine a case where a thread A calls `addObserver` and thread B calls `nativeImageResponseFailed` at the same time.
Thread A might read `status_` exclusively and store result as a local variable and then go sleep.
Then thread B starts and finishes `nativeImageResponseFailed`, it writes `status_` and notifies all observers.
Then thread B wakes up. It adds an observer to a collection of observers and finishes.
As a result, the observer from `addObserver` will never be called.

To fix this, we changed a logic a bit to lock only once per method. During the lock, we read and/or write to storage and then perform side-effects.
In contrast, previously we often locked only around the access of a particular instance variable (several times per method).

The challenge here is that idiomatic/fancy to C++/STL ways to lock mutexes don't work in our case.

# C++ idioms and readability, multiple locks for the same transaction
STL has tools to avoid calling `lock` and `unlock` methods manually (std::lock_guard<> and lamdas). Unfortunately, using that in our use case is quite problematic. That's probably possible but will lead to much less readable code and some copy-pasta in `addObserver`.
Therefore we replaced using `std::lock_guard` with simple `lock` and `unlock` where using `std::lock_guard` was problematic.

# Why we changed `shared_mutex` to a normal one?
After consolidating the locks we found that we have an only case where we can use shared lock (in `nativeImageResponseProgress`). Calling this method in real life is not concurrent, so it makes sense to replace a shared lock with a more simple and performant regular one.

Reviewed By: sammy-SC

Differential Revision: D17368739

fbshipit-source-id: 61d66fb737d8c2dc73001a80a31edaa59a16d886
2019-09-23 15:59:44 -07:00
Valentin Shergin 69f9fd4f96 Fabirc: Improvements in `ImageResponseObserverCoordinator`
Summary:
This diff contains some small improvements in `ImageResponseObserverCoordinator` which are pretty minor:
 * Now we use `small_vector` instead of a normal one. In the vast majority of cases, the coordinator has only one observer, so having `small_vector` with default size `1` saves us a memory allocation (which is a dozen of allocations for a screen, not bad).
 * Empty constructor and destructor were removed.
 * Unnecessary copying of ImageResponse was removed. ImageResponse is a practically a shared_pointer, it has value semantic and does not need to be copied. We don't need to acquire mutex to access that.

Reviewed By: sammy-SC

Differential Revision: D17368740

fbshipit-source-id: 828e27a72b9c8ac0063c5fbda00f83ddb255309c
2019-09-23 15:59:44 -07:00
Kevin Gozali bfc9839a63 iOS Image: skip CADisplayLink optimization only when weakProxy is enabled
Summary: Just need to validate the intended fix properly via simple gating mechanism.

Reviewed By: mmmulani

Differential Revision: D17536264

fbshipit-source-id: 92db4156beabd6dec2a71b6ea7c2d7bf708d44b1
2019-09-23 15:25:30 -07:00
Luna Wei 9cd2a5f86e Create ScrollViewCommands
Summary: Use NativeCommands interface to dispatch command for ScrollViewManager

Reviewed By: TheSavior

Differential Revision: D17077016

fbshipit-source-id: 3f16b0ab212a7de31ebde1515aafb137ac4f8001
2019-09-23 15:25:30 -07:00
Ramanpreet Nara f5ab719445 Make RCTClipboard, RCTI18nManager, and RCTSourceCode TurboModule-compatible
Summary: These NativeModules were easy to convert, since no other NativeModules in `React/Modules` depend on them.

Reviewed By: PeteTheHeat

Differential Revision: D16817959

fbshipit-source-id: 1036c2d437e1275776a185bf68c450c6454985df
2019-09-23 15:25:30 -07:00
Daniel 21890e964d Fix onPress prop for Touchable Components being called twice on Android Tv (#26474)
Summary:
Due to an update to react-native on the  android tv platform tapping the select button on a remote calls the onPress prop twice for `TouchableHighlight`, `TouchableOpacity`, and `TouchableWithoutFeedback`. This is happening because touchableHandlePress gets called from two places. First from the onClick prop in the touchable component and second from the TVEventHandler in the TouchableMixin.

## Changelog

[Android] [Fixed] - Adds a not android check to the select case of the TVEventHandler callback in the TouchableMixin.
Pull Request resolved: https://github.com/facebook/react-native/pull/26474

Test Plan:
Confirmed on Android Tv and Apple Tv

1) Add a TouchableOpacity to a screen with an onPress callback
2) Run app
3) Focus the TouchableOpacity
4) Press the Select Button on the Remote

**Expected Results**
onPress is called once

Differential Revision: D17530170

Pulled By: TheSavior

fbshipit-source-id: b776faba477c6231ad296abd21f072335dca5556
2019-09-23 14:46:41 -07:00
Janic Duplessis 211ea485cd Fix `includeFontPadding` for `TextInput` placeholder (#26432)
Summary:
The custom font I'm using requires using `includeFontPadding={false}` to be correctly centered vertically. The only case where this is not working is with the placeholder of `TextInput`. To fix it we call `setIncludeFontPadding` on the `EditText` instance, like we do for `Text`.

## Changelog

[Android] [Fixed] - Fix `includeFontPadding` for `TextInput` placeholder
Pull Request resolved: https://github.com/facebook/react-native/pull/26432

Test Plan:
Tested the fix in an app.

Before

![image](https://user-images.githubusercontent.com/2677334/64898120-f1de0600-d653-11e9-97b3-f53416d5f9fe.png)

After

![image](https://user-images.githubusercontent.com/2677334/64897961-5b114980-d653-11e9-8897-baa14fc0f56c.png)

Reviewed By: mdvacca, mmmulani

Differential Revision: D17468767

Pulled By: JoshuaGross

fbshipit-source-id: ae29debf9a57198a636a24ec8ed9ba3d77f0a73e
2019-09-23 10:28:05 -07:00
Janic Duplessis 8b9f790069 Fix medium font weights for TextInput on Android (#26434)
Summary:
When using a medium (500) font weight on Android the wrong weight is used for the placeholder and for the first few seconds of input (before it gets text back from JS). To fix it I refactored the way we handle text styles (family, weight, style) to create a typeface to be more like the `Text` component.

Since all these 3 props are linked and used to create the typeface object it makes more sense to do it at the end of setting props instead of in each prop handler and trying to recreate the object without losing styles set by other prop handlers. Do do that we now store fontFamily, fontStyle and fontWeight as ivar of the ReactEditText class. At the end of updating prop if any of those changed we recreate the typeface object.

This doesn't actually fix the bug but was a first step towards it. There were a bunch of TODOs in the code to remove duplication between `Text` and `TextInput` for parsing and creating the typeface object. To do that I simply moved the code to util functions in a static class. Once the duplication was removed the bug was fixed! I assume proper support for medium font weights was added for `Text` but not in the duplicated code for `TextInput`.

## Changelog

[Android] [Fixed] - Fix medium font weights for TextInput on Android
Pull Request resolved: https://github.com/facebook/react-native/pull/26434

Test Plan:
Tested in my app and in RNTester that custom styles for both text and textinput all seem to work.

Repro in RNTester:

```js
function Bug() {
  const [value, setValue] = React.useState('');
  return (
    <TextInput
      style={[
        styles.singleLine,
        {fontFamily: 'sans-serif', fontWeight: '500', fontSize: 32},
      ]}
      placeholder="Sans-Serif 500"
      value={value}
      onChangeText={setValue}
    />
  );
}
```

Before:

![font-bug-1](https://user-images.githubusercontent.com/2677334/64902280-6889fc00-d672-11e9-8f44-9e524d844a6c.gif)

After:

![font-bug-2](https://user-images.githubusercontent.com/2677334/64902282-6cb61980-d672-11e9-8163-ace0f23070b6.gif)

Reviewed By: mmmulani

Differential Revision: D17468825

Pulled By: JoshuaGross

fbshipit-source-id: bc2219facb94668551a06a68b0ee4690e5474d40
2019-09-23 10:23:29 -07:00
Janic Duplessis 0cafa0f5d1 Use `warnOnce` for excessive number of callbacks error (#26508)
Summary:
I happened to hit this error a couple times and the issue is that if there are let's say 1000 pending callbacks the error would be triggered 500 times and pretty much crash the app. I think it is reasonable to use warn once here so it only happens once.

## Changelog

[General] [Fixed] - Use `warnOnce` for excessive number of callbacks error
Pull Request resolved: https://github.com/facebook/react-native/pull/26508

Test Plan: Tested by reducing the number of pending callbacks required to trigger the error.

Reviewed By: TheSavior

Differential Revision: D17512917

Pulled By: JoshuaGross

fbshipit-source-id: 5ce8e2a0a166805cc6f3fe6d78e2716d6792a80e
2019-09-23 10:14:51 -07:00
Valentin Shergin 30e9443487 Fabric: Fixed threading issue in RCTNativeAnimatedModule
Summary:
The previous version of the code accessed `_animIdIsManagedByFabric` on the main thread (which is should be accessed on the UIManager thread) and called `flushOperationQueues` on the main thread as well (also must be called on UIManager thread because it modifies instance variables (e.g. `_operations`) which supposed to be accessed on UIManager thread).

The diff fixes that introducing an additional queue jump. That's should be fine because the overall architecture of RCTNativeAnimatedModule is appeared to be asynchronous and should be resilient to possible races.

Reviewed By: sammy-SC

Differential Revision: D17523958

fbshipit-source-id: c4b4ce38b68b009726b2f6c28c38b32b9f9d6921
2019-09-23 09:30:38 -07:00
Oleksandr Padalko 034a7d185f Add new method jsBundleURLForBundleRoot with fallback block to RCTBundleURLProvider
Reviewed By: julian-krzeminski

Differential Revision: D17336324

fbshipit-source-id: b14a08d940ec7594978d3e34f1e833f65d3bd411
2019-09-23 09:26:59 -07:00
Samuel Susla 845cbec5cf Add codegen support for EdgeInsets
Summary: Add codegen support for `EdgeInsets`.

Reviewed By: rickhanlonii

Differential Revision: D17500509

fbshipit-source-id: b2909fe296c51d3a47cc961c45294eead7707853
2019-09-23 09:12:51 -07:00
Oleksandr Melnykov 5cfe588993 Use generated Java delegate for setting properties on ReactSwitchManager
Summary: This diff migrates `ReactSwtichManager` to use the generated `ReactSwtichManagerDelegate` for setting its properties.

Reviewed By: TheSavior

Differential Revision: D17395067

fbshipit-source-id: 1489c5d08cef860030ecbd23ef19bd8de1328d71
2019-09-23 07:18:10 -07:00
Oleksandr Melnykov 81f567d4aa Use generated Java delegate for setting properties on ReactDrawerLayoutManager
Summary: This diff migrates `ReactDrawerLayoutManager` to use the generated `AndroidDrawerLayoutManagerDelegate` for setting its properties.

Reviewed By: mdvacca

Differential Revision: D17343383

fbshipit-source-id: 85cd7ee3531b152da2601048f5e458f5dad73ad6
2019-09-23 07:18:10 -07:00
Oleksandr Melnykov 92f3b4a27f Allow null as default value for float props
Summary:
Some props must have their default values set by native. To be able to support this, we have to introduce a null as a supported default value for some types. In this diff I'm adding support for null default values for float props. An example of this to be useful is `ReactDrawerLayoutManager`:

```
  Override
  public void setDrawerWidth(ReactDrawerLayout view, Nullable Float width) {
    int widthInPx =
        width == null
            ? LayoutParams.MATCH_PARENT
            : Math.round(PixelUtil.toPixelFromDIP(width));
    view.setDrawerWidth(widthInPx);
  }
```

We need to be able to generate an interface method, that accepts a boxed `Float` value instead of the primitive `float` so that the native code can decide what value to use by default (`LayoutParams.MATCH_PARENT` in this case).

Reviewed By: rickhanlonii

Differential Revision: D17343172

fbshipit-source-id: 7662a4e0e495f58d05a92892f063535a359d09ae
2019-09-23 07:18:09 -07:00
Oleksandr Melnykov 2e7545cf7e Use generated Java delegate for setting properties on ReactProgressBarViewManager
Summary: This diff migrates `ReactProgressBarViewManager` to use the generated `AndroidProgressBarManagerDelegate` for setting its properties.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D17315619

fbshipit-source-id: 6293c6fc18567a934b6f3dce9b77abcc408052d8
2019-09-23 07:18:09 -07:00
Oleksandr Melnykov 23557d1f9a Flow type AndroidSwitch and generate Android OSS classes
Summary: This diff adds Flow types to `AndroidSwitchNativeComponent`.

Reviewed By: TheSavior

Differential Revision: D17205083

fbshipit-source-id: 3d11f11e269388b78a5f0ed528be94df04f9719d
2019-09-23 07:18:09 -07:00
Oleksandr Melnykov bf89d1d536 Allow null as default value for boolean props
Summary: Some props must have their default values set by native. To be able to support this, we have to introduce a `null` as a supported default value for some types. In this diff I'm adding support for `null` default values for boolean props. Check D17260168 for the example of the usage of the nullable boolean values.

Reviewed By: rickhanlonii, TheSavior

Differential Revision: D17258234

fbshipit-source-id: 63b7864be97856704d5964230526f23c0e395a67
2019-09-23 07:18:08 -07:00
Oleksandr Melnykov ef3b16ef6d Use generated Java delegate for setting properties on SwipeRefreshLayoutManager
Summary: This diff migrates `SwipeRefreshLayoutManager` to use the generated `AndroidSwipeRefreshLayoutManagerDelegate`.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D17225894

fbshipit-source-id: e659d2a9cb5dba42c589559f61a0e98330e21612
2019-09-23 07:18:08 -07:00
Oleksandr Melnykov 1eb8ef59ad Use generated Java delegate for setting properties on ReactModalHostManager
Summary: This diff migrates `ReactModalHostManager` to use the generated `ModalHostViewManagerDelegate` for setting its properties.

Reviewed By: mdvacca

Differential Revision: D17205817

fbshipit-source-id: 6724302fd4301f9df92df04fcfb41f0c2c939d9f
2019-09-23 07:18:08 -07:00
Oleksandr Melnykov 5925b3d408 Use generated Java delegate for setting properties on ReactSliderManager
Summary: This diff migrates `ReactSliderManager` to use the generated `SliderManagerDelegate` for setting its properties.

Reviewed By: mdvacca

Differential Revision: D17203078

fbshipit-source-id: 726736ef275074ecb799b334342ac64976153e2b
2019-09-23 07:18:07 -07:00