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

3545 Коммитов

Автор SHA1 Сообщение Дата
Dratwas d8fa1206c3 fix indexed RAM bundle (#24967)
Summary:
Co-Authored: zamotany
With React Native 0.59.8 the app keeps crashing with indexed RAM bundle on Android with the following error:

```
2019-05-09 11:58:06.684 2793-2856/? E/AndroidRuntime: FATAL EXCEPTION: mqt_js
    Process: com.ramtestapp, PID: 2793
    com.facebook.jni.CppException: getPropertyAsObject: property '__fbRequireBatchedBridge' is not an Object

    no stack
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:193)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:764)
```

After investigation we found that when using any bundle, let it be non-ram, FIle RAM bundle or Index RAM bundle, the `CatalystInstanceImpl.java` is always using `loadScriptsFromAsset`, which is calling `CatalystInstanceImpl::jniLoadScriptFromAssets` in C++. This method when checking if bundle is a RAM bundle, uses `JniJSModulesUnbundle::isUnbundle` which only check for js-modules/UNBUNDLE - file generated when building File RAM bundle. There is no other logic to handle Indexed RAM bundle, so it figures that the bundle is not RAM, cause there is no js-modules/UNBUNDLE file and tries to load as regular bundle and fails.

In this PR we added check if it is indexed RAM bundle in `jniLoadScriptFromAssets` and handle it if it is.
## Changelog
[Android] [Fixed] fix indexed RAM bundle

Solves https://github.com/facebook/react-native/issues/21282
Pull Request resolved: https://github.com/facebook/react-native/pull/24967

Differential Revision: D15575924

Pulled By: cpojer

fbshipit-source-id: 5ea428e0b793edd8242243f39f933d1092b35260
2019-06-03 07:14:25 -07:00
Janic Duplessis a4f7e17a4f Release underlying resources when JS instance is GC'ed on Android (#24767)
Summary:
Android followup for #24745. This adds a jsi object that removes blobs when it is gc'ed. We don't have many modules with native code on Android so I've added the native code directly in the blob package as a separate .so. I used a similar structure as the turbomodule package.

## Changelog

[Android] [Fixed] - [Blob] Release underlying resources when JS instance is GC'ed on Android
Pull Request resolved: https://github.com/facebook/react-native/pull/24767

Differential Revision: D15279651

Pulled By: cpojer

fbshipit-source-id: 2bbdc4bbcbeae8945588ac5e3e895c49e6ac9e1a
2019-05-31 03:55:27 -07:00
Tim Yung dac037d371 RN: Debug Menu Cleanup (Android)
Summary:
Addresses a number of pieces of feedback regarding the debug menu.

- Simplify labels for the debugger actions (e.g. no "remote", no emoji).
- Reorder actions so that modal items are generally lower.
- Renamed "Live Reloading" to "Reload-on-Save".
- Renamed "Dev Settings" to "Settings".

Changelog:
[Android] [Changed] - Cleaned up debug menu.

Reviewed By: cpojer

Differential Revision: D15553883

fbshipit-source-id: d30e8cd0804e010985c0cf40d443defc7c0710ac
2019-05-30 22:42:24 -07:00
Tim Yung 739651afa1 RN: Simplify Context Creation (Android)
Summary:
Every call site is either already using `createReactContextInBackground` correctly or guarding the invocation using `hasStartedCreatingInitialContext`. This is an unnecessary and overly complex dance that can be simplified.

This revision simplifies the use of `createReactContextInBackground` by integrating the check. This is not a breaking change.

Reviewed By: zackargyle, mdvacca

Differential Revision: D15566632

fbshipit-source-id: 7b50285c9ac6776d1297d2c9c53dff208851b722
2019-05-30 18:50:43 -07:00
Ram N 060a3ea3bf Delete Start/Stop Profiler from Dev Menu in Android
Reviewed By: mdvacca

Differential Revision: D10473627

fbshipit-source-id: eec61903f0a7abd0757aed0750d4bd828e4887bc
2019-05-30 17:28:03 -07:00
Emily Janzer 7fb02bd908 Rename onAccessibilityAction event on Android
Summary: D15391408 (https://github.com/facebook/react-native/pull/24695) added a new event type with the registration name 'onAccessibilityAction' on Android, using the key 'performAction'. On iOS the same event uses the key 'topAccessibilityAction', which caused a runtime error after I started registering both using the unified JS view config in D15488008. This diff changes Android to use the same name as iOS since the convention is to start with 'top'.

Reviewed By: cpojer

Differential Revision: D15542623

fbshipit-source-id: c339621d2b4d3e1700feb5419ae3e3af8b185ca8
2019-05-30 16:00:26 -07:00
Petter Hesselberg 2aca234dee Don't reference null android.ndkDirectory in build.gradle (#25088)
Summary:
If you (try to) build React Native for Android without having the NDK properly installed and referenced, you get the following error:

>A problem occurred evaluating project ':ReactAndroid'.
\> Cannot get property 'absolutePath' on null object

This is not an overly helpful diagnostic. This PR results in this message instead:

>ndk-build binary cannot be found, check if you've set $ANDROID_NDK environment variable correctly or if ndk.dir is setup in local.properties

Fixes #25087

## Changelog

[Android] [Fixed] - Show proper error message instead of throwing a NullReferenceException if Gradle cannot find the NDK
Pull Request resolved: https://github.com/facebook/react-native/pull/25088

Differential Revision: D15559271

Pulled By: cpojer

fbshipit-source-id: 35c9a9321af4e4a34bf519144ada48884b48352d
2019-05-30 11:11:09 -07:00
Oleksandr Melnykov aac95b409b Fix switch being stuck in intermidiate state on Android
Summary:
This diff fixes the bug of the switch component on Android being stuck in the middle when a user releases their finger whily dragging the thumb.

When a user releases their finger while dragging the thumb, `setChecked` will be called and if `mAllowChange` is set to false, `super.setChecked` is never called. The supper method will actually make sure the thumb will be animated to the correct edge. Without calling the super method, the thumb might stay in the middle of the switch where a user released their finger.

The fix had to be applied both to ReactSwitch and FbReactSwitchCompat.

One more fix had to be made to FbReactSwitchCompat since D5884661 was applied to ReactSwitch, but not to FbReactSwitchCompat:

if (mAllowChange && **isChecked() != checked**) {
...
}

Reviewed By: mdvacca

Differential Revision: D15535611

fbshipit-source-id: 22ca1fe3fa993ae65cbd677bfae2208a02c368d4
2019-05-30 10:36:24 -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
Emily Janzer 298f59c5d3 Use startSurface on Android
Summary:
We currently have two different codepaths for actually rendering a surface with Fabric on iOS and Android: on iOS we use Fabric's `UIManagerBinding.startSurface` to call `AppRegistry.runApplication`, but on Android we don't; instead we use the same codepath as paper, calling `ReactRootView.runApplication`.

This diff does a few different things:
1. Unify iOS and Android by removing the `#ifndef` for Android so that we call `startSurface` for both
2. Pass through the JS module name on Android so that this actually works (it currently passes in an empty string)
3. Remove the call to `ReactRootView.runApplication` for Fabric so that we don't end up doing this twice
4. Copy over some logic that we need from `ReactRootView.runApplication` (make sure that root layout specs get updated, and that content appeared gets logged)

Reviewed By: mdvacca

Differential Revision: D15501666

fbshipit-source-id: 5c96c8cf036261cb99729b1dbdff0f7c09a32d76
2019-05-28 12:23:00 -07:00
Luna Wei bd3023abea Layout Animation fix for normalized indices
Summary:
[Android][Fix] - Fix how we normalize indices

Before, we were incorrectly normalizing indices given pending view deletion in the view hierarchy (namely, using LayoutAnimations)

What we had before (that was wrong):
* Maintained a pendingIndices sparse array for each tag
* For each pendingIndices sparse array we'd keep track of how many views we deleted at each abstract index
* Given an abstract index to delete a view at, we'd consult `pendingIndices` array to sum how many pending deletes we had for indices equal or smaller than and add to abstract index

^ Above algorithm is wrong and you can follow along with the following example to see how.

## The correct approach
Given these operations in this order:
1. {tagsToDelete: [123], indicesToDelete [2]}
2. {tagsToDelete: [124], indicesToDelete [1]}
3. {tagsToDelete: [125], indicesToDelete [2]}
4. {tagsToDelete: [126], indicesToDelete [1]}

The approach we want to be using to calculate normalized indices:
### Step 1: Delete tag 124 at index 2

|Views:|122|123|124|125|126|127|
|Actual Indices:|0|1|2|3|4|5|
|Abstract Indices:|0|1|2|3|4|5|
=> simple, we just mark the view at 2

### Step 2: Delete tag 123 at index 1
View tags and indices:
|Views|122|123|~~124~~|125|126|127|
|Actual indices|0|1|~~2~~|3|4|5|
|Abstract Indices|0|1||2|3|4|
=> again, simple, we can just use the normalized index 1 because no pending deletes affect this operation

### Step 3: Delete tag 126 at index 2
View tags and indices:
|Views|122|~~123~~|~~124~~|125|126|127|
|Actual Indices|0|~~1~~|~~2~~|3|4|5|
|Abstract Indices|0|||1|2|3|
=> Here we want to normalize this index to 4 because we need to account the 2 views that should be skipped

### Step 4: Delete tag 125 at index 1
View tags and indices:
|Views|122|~~123~~|~~124~~|125|~~126~~|127|
|Actual Indices|0|~~1~~|~~2~~|3|~~4~~|5|
|Abstract Indices|0|||1||2|
=> The normalized index should be 3.

This diff updates the function `normalizeIndex` to do the above algorithm by repurposing `pendingIndicesToDelete` to instead be a sparse int array that holds [normalizedIndex]=[tag] pairs
It's required that `pendingIndicesToDelete` is ordered by the normalizedIndex.

Reviewed By: mdvacca

Differential Revision: D15485132

fbshipit-source-id: 43e57dffa807e8ea50fa1650c5dec13a6fded624
2019-05-28 09:09:08 -07:00
Luna Wei 5979eafb16 Back out "[RN] Fix layout animation crash"
Summary: Original commit changeset: 41200e572ed7

Reviewed By: mdvacca

Differential Revision: D15485156

fbshipit-source-id: d0868a03b7186bb33998afc2c99dd85f31c8fef9
2019-05-28 09:09:07 -07:00
Andrea Cimitan 54abe1f599 Linking.getInitialURL() to work with NFC tags on Android (#25055)
Summary:
This PR solves bug https://github.com/facebook/react-native/issues/24393 for Android. Allows an app to be opened with an NFC tag and getting the url trough Linking.getInitialURL()

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

Differential Revision: D15516873

Pulled By: cpojer

fbshipit-source-id: e8803738d857a69e1063e926fc3858a416a0b25e
2019-05-28 07:33:20 -07:00
valerio.ponte d88e4701fc Add showSoftInputOnFocus to TextInput (#25028)
Summary:
Add prop showSoftInputOnFocus to TextInput. This fixes #14045. This prop can be used to prevent the system keyboard from displaying at all when focusing an input text, for example if a custom keyboard component needs to be displayed instead.

On Android, currently TextInput always open the soft keyboard when focused. This is because `requestFocus` calls `showSoftKeyboard`, which in turn instructs `InputMethodManager` to show the soft keyboard.

Unfortunately even if we were to define a new input type that extends ReactEditText, there is no way to overcome this issue.
This is because `showSoftKeyboard` is a private method so it can't be overriden. And at the same time `requestFocus` needs to invoke `super.requestFocus` to properly instruct Android that the field has gained focused, so overriding `requestFocus` in a subclass of ReactEditText is also not an option, as when invoking `super.requestFocus` we would end up calling again the one defined in ReactEditText.

So currently the only way of doing this is to basically add a listener on the focus event that will close the soft keyboard immediately after. But for a split second it will still be displayed.

The code in the PR changes `requestFocus` to honor showSoftInputOnFocus as defined in Android TextView, displaying the soft keyboard unless instructed otherwise.

## Changelog

[Android] [Added] - Add showSoftInputOnFocus to TextInput
Pull Request resolved: https://github.com/facebook/react-native/pull/25028

Differential Revision: D15503070

Pulled By: mdvacca

fbshipit-source-id: db4616fa165643d6ef2b3185008c4d279ae08092
2019-05-24 15:40:22 -07:00
rkang 206bb6d3b9 Update the "nativeStackAndroid" (#25014)
Summary:
Update the "nativeStackAndroid" frame limit to 50 and include the class name on the "nativeStackAndroid".

nativeStackAndroid only contains up to 10 lines of stack traces. This is due to the "ERROR_STACK_FRAME_LIMIT" set to 10 on https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java.

![2019-05-22_10-33-23](https://user-images.githubusercontent.com/14658357/58291337-eba8de80-7d71-11e9-9524-5bd6814c9f4a.png)

nativeStackAndroid should contain a more reasonable number of the native stack traces. (nativeStackIOS includes all of them). another improvement could be adding the "declaringClass" on top of the "methodName", "LineNumber", and "file" on the stack trace frameMap.

![2019-05-22_13-38-43](https://user-images.githubusercontent.com/14658357/58290869-1b56e700-7d70-11e9-9e63-2149fd1486c7.png)

## Changelog

[Android] [Added] - Update the "nativeStackAndroid" frame limit to 50 and include class name
Pull Request resolved: https://github.com/facebook/react-native/pull/25014

Differential Revision: D15503022

Pulled By: cpojer

fbshipit-source-id: 6f1bc25ea739715d0e7589d430bf9cf72da305b2
2019-05-24 15:33:43 -07:00
Hermanyo b9b9137604 if-else refactoring (#25025)
Summary:
## Summary
## Changelog
[Internal] [Changed] - Code review

## Test Plan
N/A
Pull Request resolved: https://github.com/facebook/react-native/pull/25025

Differential Revision: D15502838

Pulled By: cpojer

fbshipit-source-id: 9b8d2525411dea35e746638146b9af90832733f6
2019-05-24 15:13:55 -07:00
Shen Jin 7d1c827cb2 Fix spinner mode
Summary:
Okay, I think this is the best I can do David, I don't think there's an obvious/easy way for me to try to get `getIdentifier()` to return a non zero value. Setting it to what Spencer suggested works for my use case.

## Changelog

[Android] [Changed] - Update spinner mode to render spinner instead of calendar

Reviewed By: sahrens

Differential Revision: D15427793

fbshipit-source-id: b04f024a9a1f052f69f3bda47d77821782dc2c0e
2019-05-24 14:42:28 -07:00
David Vacca 6f63b054b6 Add Nullable annotation into Mounting Manager
Summary: trivial diff to remove warnings because of the lack of Nullable annotations in MountingManager.ViewState

Reviewed By: shergin

Differential Revision: D15476040

fbshipit-source-id: 2b9a4efa1be1d5aa29d4e32cf32c8ff502f7c60c
2019-05-24 11:30:30 -07:00
David Vacca 92f8fd22e2 Optimize the update of state during first render of a View
Summary: This is an optimization to avoid transfering updateState instructions twice during the frist render of a view (same a props)

Reviewed By: shergin

Differential Revision: D15476041

fbshipit-source-id: 8a62035dbbb63c93f86a2f8d217986a325cb1805
2019-05-24 11:30:30 -07:00
David Vacca cd5fe06abe Fix bottom sheet in Fabric Android
Summary: This diff fixes the rendering of Bottom Sheet in Fabric Android. In D15343702 we added state as part of the "preallocateView" method but we forgot to call viewManager.updateState(), this prevents the state to be updated during the first render.

Reviewed By: shergin

Differential Revision: D15476042

fbshipit-source-id: cd6fc9bdd178589d2e04f85723425b5e5c3e5a04
2019-05-24 11:30:30 -07:00
David Vacca c629cdc39a Remove ComponentRegistry class
Summary: This class is not necessary anymore, this diff deletes it from the repo

Reviewed By: JoshuaGross

Differential Revision: D15457346

fbshipit-source-id: c7293d93b50271efe3b3d2121c128ba6e13c7627
2019-05-24 11:30:30 -07:00
David Vacca cb1a28c859 Remove jsi package from fabric android
Summary: Refactor of packages of RN Android

Reviewed By: JoshuaGross

Differential Revision: D15457141

fbshipit-source-id: a291f7e1ca8e0be3e93daf9c34161c8f1fdbafac
2019-05-24 11:30:29 -07:00
David Vacca bbf1a7d085 Back out "[Venice][Fabric] Use startSurface on Android"
Summary: Original commit changeset: 4a506a589108

Reviewed By: ejanzer

Differential Revision: D15497094

fbshipit-source-id: 47e5d0c3c69cc56cc3dd56d28e23e1db5b562fa4
2019-05-24 11:30:29 -07:00
Oleksandr Melnykov fb6cf2552a Fix backgroundColor top level prop of TextInput
Summary:
Changelog: [Android] [FIXED] - Fix backgroundColor top level prop of TextInput

This diff fixes two issues with the `backgroundColor` top level property of TextInput on Android:
 * Now it is possible to set a **string** value for the top-level `backgroundColor` property of TextInput (crashed the app previously):
```
<TextInput backgroundColor="#ffccbb">Hello, React Native</TextInput>
```
* Now it's possible to set an **integer** value for the top-level `backgroundColor` property of TextInput (had no effect previously):
```
<TextInput backgroundColor={0xffccbbff}>Hello, React Native</TextInput>
```

A `customType = "Color"` annotation parameter must be provided for `ReactBaseTextShadowNode.setBackgroundColor(...)` since the color value must be previously processed in JS before sending it over the bridge to the native code. The JS code will parse the color value and return the proper ARGB color integer to the native platforms (https://fburl.com/uqup52tn).

Without providing the custom type for the background color, if a string value is set for the top-level `backgroundColor` property in the JS code, the Android code will crash since it expects an integer value for the color in `ReactBaseTextShadowNode.setBackgroundColor(...)`, but a string will be passed from JS without any conversion and there will be a `ClassCastException` thrown. If an integer value without the alpha component (like `0xffccbb`) is set, the Android native view would get an integer color value with its alpha component set to `0x00`, which means a transparent color.

On a side note: the alpha component of a color must always be set when using an integer value for `backgroundColor` since the JS code, while processing the color type, shifts the rightmost 8 bytes (alpha component) to the leftmost position. If those 8 bytes are not the alpha component, you will get the wrong color in the end. It doesn't seem to be a problem for string values of `backgroundColor` though.

Reviewed By: mdvacca

Differential Revision: D15453980

fbshipit-source-id: f3f5d9c9877cdbce79a67f2ed93ad4589576d166
2019-05-24 02:53:42 -07:00
David Vacca 01abcf0e83 Fix update of accessibilityStates in Android
Summary:
This diff fixes a bug on the update of accessibiltyState prop in RN Android.
In particular, this bug was reproducible when a view has an accessibiltyState = ['disabled'] and there was a state update to set the {accessibiltyState = {null}}. In this scenario, the BaseViewManager.setViewStates method did not update the view with the default values for accessibilityState

Reviewed By: sahrens

Differential Revision: D15446078

fbshipit-source-id: 75f160916e55f0ee469516db2fe9b0a7d4758cd8
2019-05-23 18:31:39 -07:00
Emily Janzer f23da3aeb0 Use startSurface on Android
Summary:
Right now calling FabricUIManager.addRootView() doesn't actually start running the application on Android. This diff:

1. Removes the #ifndef so that we actually call UIManagerBinding.startSurface() on Android
2. Passes through the JS module name from addRootView so we can render the surface (falls back to an empty string if not provided, which is the current behavior)
3. Adds an option for starting the surface using `RN$SurfaceRegistry` instead of `AppRegistry`, if that global property has been defined in JS. This is used for Venice (bridgeless RN)

Reviewed By: shergin

Differential Revision: D15366200

fbshipit-source-id: 4a506a589108905d4852b9723aac6fb0fad2d86e
2019-05-23 13:47:30 -07:00
Emily Janzer d742c7be36 Auto-formatting for Binding
Summary:
I just learned about Nuclide's auto-formatting (cmd-shift-c) and started using it in another diff, but I didn't want to pollute the diff with a bunch of formatting changes, so here we are.

I don't know if anyone else uses Nuclide's auto-formatting, or something else - happy to ditch this if that's not how we roll.

Reviewed By: shergin

Differential Revision: D15389601

fbshipit-source-id: e3b20acd073adf3cc7bab1f62d86c5b5dab8c4fc
2019-05-23 13:47:29 -07:00
Marc Mulcahy 099be9b356 New Accessibility states API. (#24608)
Summary:
As currently defined, accessibilityStates is an array of strings, which represents the state of an object. The array of strings notion doesn't well encapsulate how various states are related, nor enforce any level of correctness.

This PR converts accessibilityStates to an object with a specific definition. So, rather than:

<View
...
accessibilityStates={['unchecked']}>

We have:

<View
accessibilityStates={{'checked': false}}>

And specifically define the checked state to either take a boolean or the "mixed" string (to represent mixed checkboxes).

We feel this API is easier to understand an implement, and provides better semantic definition of the states themselves, and how states are related to one another.

## Changelog

[general] [change] - Convert accessibilityStates to an object instead of an array of strings.
Pull Request resolved: https://github.com/facebook/react-native/pull/24608

Differential Revision: D15467980

Pulled By: cpojer

fbshipit-source-id: f0414c0ef6add3f10f7f551d323d82d978754278
2019-05-23 05:37:33 -07:00
Vojtech Novak 04564a0322 allow overriding spannedFromShadowNode in ReactTextInputShadowNode (#24995)
Summary:
Motivation is the same as in https://github.com/facebook/react-native/pull/24927 - when building a custom textinput (eg with rich text editing), one needs custom text processing logic. `ReactTextInputShadowNode` contains 6671165f69/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java (L211)

where an instance of `ReactTextUpdate` is created. For the custom use case, we'd like to just change the usage of [`spannedFromShadowNode()`](6671165f69/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java (L217)) to our own implementation.

from there:
It's easy to subclass `ReactTextInputShadowNode` and override `public void onCollectExtraUpdates()` but the problem is that the method accesses private members. It also means overriding more code than necessary as we only care for `spannedFromShadowNode()`.

Solution might be changing the members to protected, but that seemed weird because there are already setters for them. Creating getters also seemed weird, as we'd end up having unused getters hanging around.

So the second way which I find nicer is changing `protected static Spannable spannedFromShadowNode(ReactBaseTextShadowNode textShadowNode, String text)` to just `protected` since that will allow subclasses to override just this behavior.

## Changelog

[Android] [Added] - allow custom spannedFromShadowNode in ReactTextInputShadowNode subclasses
Pull Request resolved: https://github.com/facebook/react-native/pull/24995

Differential Revision: D15468066

Pulled By: cpojer

fbshipit-source-id: 73d5f0b9e06f3e02a03bf9db5effac62cecc80c4
2019-05-23 05:31:00 -07:00
Blair Vanderhoof 9fb31d1538 Fix layout animation crash
Summary: As of D14529038, LayoutAnimations can sometimes throw an exception due to the view being null.  This can happen when elements are removed/added and is not fixable in product code. This is a temporary fix - the root cause for this issue will be fixed soon.

Reviewed By: lunaleaps

Differential Revision: D15428791

fbshipit-source-id: 41200e572ed7d5d470754792c5576a0ea23fe946
2019-05-22 13:25:00 -07:00
Ramanpreet Nara 5127ac5c2a Implement support for legacy CxxModules
Summary:
## Background
Legacy Cxx NativeModules are implemented as Hybrid classes. Essentially, when a Cxx NativeModule is requested, you instantiate its hybrid class, which then creates a C++ counterpart. Then, the bridge uses the C++ counterpart's `getModule()` method to obtain ownership of the Cxx NativeModule.

## Summary
This diff implements backwards-compability for Cxx NativeModules.

If a Cxx NativeModule implements the `TurboModule` interface, then when the module is requested by name, we:
1. Instantiate its Java hybrid class, createing a C++ counterpart.
3. Obtain the CxxModule from the C++ counterpart using `getModule()` and use it to create a `TurboCxxModule` instance (this forwards all JavaScript method calls to the CxxModule) inside `TurboModuleManager`.
5. Return this `TurboCxxModule` to JS.

Reviewed By: mdvacca

Differential Revision: D15252041

fbshipit-source-id: cdbb62632d7a8735f7687daf62de63df9e3ad2c5
2019-05-22 13:16:13 -07:00
Ramanpreet Nara 37583bd6e8 Only create TurboModule jsi::HostObject if Java module is non-null
Summary:
## Summary
If the Java instance of a TurboModule is null, then the resultant JS object returned from `TurboModuleRegistry` should also be null.

Reviewed By: mdvacca

Differential Revision: D15253476

fbshipit-source-id: 83a6b9aa97b547aeecf9b285986ad0f5b9e413da
2019-05-22 13:16:13 -07:00
Ramanpreet Nara e1102b43ff Implement Android Cxx TurboModule support
Summary:
## Summary
This diff does a bunch of things:
1. The TurboModule resolution algorithm on Android now supports C++ TurboModules.
2. `SampleTurboCxxModule` is moved from `ReactCommon/turbomodule/samples/platform/ios/` to `ReactCommon/turbomodule/samples` so that both iOS and Android can share it.
3. `CatalystTurboModuleManagerDelegate::getTurboModule(std::string, JSCallInvoker)` now understands and returns `SampleTurboCxxModule`.

Reviewed By: mdvacca

Differential Revision: D15253477

fbshipit-source-id: 3def91911b091f8cf93be17decd245a0499ed718
2019-05-22 13:16:13 -07:00
Ramanpreet Nara 08d87cdacc Introduce ReactPackageTurboModuleManagerDelegate
Summary:
## Summary
People use `ReactPackage` instances to create NativeModules. To make the migration from NativeModule to TurboModule easy, I'm introducing a `TurboModuleManagerDelegate` that understands `ReactPackage`s, and uses them to lookup and create the Java TurboModule objects. This way, we don't have to change the way we declare NativeModules for the migration.

## TurboModule registration
Each application should have its own subclass of `ReactPackageTurboModuleManagerDelegate`. This subclass is a hybrid class with a C++ and a Java part. The Java part can (and probably should) do nothing (for now). The C++ part has to implement the `moduleName -> jni::HostObject` and `moduleName, javaInstance -> jni::HostObject` functions for all TurboModules in the application.

**Use Case: Migrating a NativeModule to TurboModule system**
1. Make the Java NativeModule extend `TurboModule`. (The reason why this doesn't happen automatically is probably because we haven't changed the Java codegen yet).
2. Modify the `moduleName -> jni::HostObject` or `moduleName, javaInstance -> jni::HostObject` functions to return the `TurboModule`.

**Use Case: Adding a new TurboModule**
1. Add the TurboModule to a `ReactPackage` in the application.
2. Modify the `moduleName -> jni::HostObject` or `moduleName, javaInstance -> jni::HostObject` functions to return the TurboModule `jsi::HostObject`.

**Note:** It's also possible to declare TurboModules by overriding the `getModule(String moduleName)` function of `ReactPackageTurboModuleManagerDelegate`. It's not a good idea, because it'll make switching between the NativeModule/TurboModule system difficult.

Reviewed By: mdvacca

Differential Revision: D15209129

fbshipit-source-id: 4b0a303595145be9b19d6f4934f956b91990f859
2019-05-22 13:16:13 -07:00
Ramanpreet Nara 12c0ec85f7 Implement ReactContext.getNativeModule support
Summary: `ReactContext.getNativeModule` can be used to access NativeModules. With these changes, it can also be used to instantiate (if necessary) and retrieve a TurboModule.

Reviewed By: mdvacca

Differential Revision: D15167631

fbshipit-source-id: 3cb0d9a4be16cbadebbf6648c3f1481ba26513c3
2019-05-22 13:16:12 -07:00
nossbigg cea0a2b61a Set duration=0 for android keyboard events (#24994)
Summary:
Set duration=0 for android keyboard events. Brings actual implementation closer to existing flowtypes, and duration is set to 0 to minimize impact on existing keyboard event consumers.
Follow up to #24947, upon cpojer's [input](https://github.com/facebook/react-native/pull/24947#issuecomment-494681618) :)

## Changelog

[Android] [Added] - Set duration=0 for android keyboard events
Pull Request resolved: https://github.com/facebook/react-native/pull/24994

Differential Revision: D15449394

Pulled By: cpojer

fbshipit-source-id: d43096238bd38d189fbec54fc2d93f17010d9ddb
2019-05-22 05:41:22 -07:00
Joshua Gross b05761f1bb Pass State to `preallocateView` and `createView` methods whenever possible
Summary:
For some components, we will have state as soon as the ShadowNode is created that may be meaningful. In those cases, ViewManagers should be able to use State to create or preallocate views.

FB: This will be used in following diffs for Litho support.

Reviewed By: mdvacca

Differential Revision: D15343702

fbshipit-source-id: 8fd672251cb88dea662b5cae5a9efc96877d28a9
2019-05-21 15:05:18 -07:00
Vojtech Novak c9df1db00a allow custom maybeSetText logic for ReactEditText subclasses (#24927)
Summary:
We're working on a custom EditText that supports some rich text editing, and one of the places where our logic has to be different from the textinput provided by RN is the text setting logic:

7abfd23b90/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java (L377)

However, some of the important members are private and our subclass cannot access them (we work around this now with reflection). It would be nice if we could work with them directly, either using getters and setters or by changing the  access. Let me know what you think about this. Thanks.

## Changelog

[Android] [Added] - allow custom maybeSetText logic for ReactEditText subclasses
Pull Request resolved: https://github.com/facebook/react-native/pull/24927

Differential Revision: D15431682

Pulled By: cpojer

fbshipit-source-id: 91860cadac0798a101ff7df6f6b868f3980ba9b1
2019-05-21 06:41:19 -07:00
nossbigg 168a67e4b2 Return endCoordinates for keyboardDidHide keyboard event (#24947)
Summary:
This pull request enhances the Keyboard API event emitter for Android upon `keyboardDidHide` by returning a `KeyboardEvent` with a meaningful `endCoordinates` property (instead of emitting a null as of current implementation). This change standardizes the `keyboardDidHide` keyboard event emission across both iOS and Android, which makes it easier for developers to use the API.

In particular, the semantics of `endCoordinates` emitted during the `keyboardDidHide` event on Android will match nicely with semantics of the same event emitted on iOS:
- `screenY` will be height of the screen, as that the keyboard has collapsed to the bottom of the screen
- `screenX` will be 0, as the keyboard will always be flush to the sides of the screen
- `height` will be 0, as the keyboard has fully collapsed
- `width` will be the width of the screen, as the keyboard will always extend to the width of the screen

Also, the flowtypes for `KeyboardEvent` have been further improved and are more explicit to better highlight the different object shapes (see `IOSKeyboardEvent` and `AndroidKeyboardEvent`) depending on the platform.

## Changelog

[Android] [Added] - Return endCoordinates for keyboardDidHide keyboard event
Pull Request resolved: https://github.com/facebook/react-native/pull/24947

Differential Revision: D15413441

Pulled By: cpojer

fbshipit-source-id: aa3998542b7068e9852467038f57310355018379
2019-05-21 03:46:50 -07:00
David Vacca 563e0bce97 Refactor sComponentNames Map out of FabricUIManager
Summary:
Easy diff to refactor the sComponentNames map out of the FabricUIManager class.
This is a necessary clean-up to perform a slightly major refactor of the Fabric classes

Reviewed By: JoshuaGross

Differential Revision: D15421769

fbshipit-source-id: 3be73a6e20b338c8cea23ef0c88db417df7e3aa9
2019-05-20 15:43:32 -07:00
David Vacca 3b8fc8b10a Remove warnings
Summary: Easy diff to remove warnings in FabricUIManager

Reviewed By: JoshuaGross

Differential Revision: D15421771

fbshipit-source-id: 647391a0826272d0bc9320196fc8b3cb80eecfac
2019-05-20 15:43:31 -07:00
David Vacca 651ca3bc9f Refactor RootTag -> surfaceId
Summary:
Quick diff to refactor RootTag for surfaceId in Binding.cpp class
This is the first diff to start moving away from rootTag naming in Fabric

Reviewed By: JoshuaGross

Differential Revision: D15421770

fbshipit-source-id: 7bca7782f96be3d7148ee93f5d5a3a54e0d768dd
2019-05-20 15:43:31 -07:00
Eric Lewis 2231263b8b Fix typo in error handler (#24940)
Summary:
Fixes a typo!

## Changelog

[Android] [Fixed] - Typo in NativeModuleRegistryBuilder error handler
Pull Request resolved: https://github.com/facebook/react-native/pull/24940

Differential Revision: D15411931

Pulled By: cpojer

fbshipit-source-id: c5d9305e00160a3a2e8619188ccff77a5b39e910
2019-05-20 02:44:34 -07:00
Uilque Messias 2ad3bb2e2d fix(android): Normalize start and end args (#24938)
Summary:
Fixes #18579

Normalize `start` and `end` arguments when `onSelectionChange` is
dispatched on Android.

It just applies a [fix](https://github.com/facebook/react-native/issues/18579#issuecomment-474466525) sent by TheSavior (Thanks, by the way 😄)

## Changelog

[Android] [Fixed] - fix(android): Normalize start and end args
Pull Request resolved: https://github.com/facebook/react-native/pull/24938

Differential Revision: D15412005

Pulled By: cpojer

fbshipit-source-id: bb132313cfb8877a682f3865a5f9e48d45ac20ac
2019-05-20 01:45:51 -07:00
Sharon Gong 14b4668947 Extended Accessibility Actions Support (#24695)
Summary:
This is a reconstitution of #24190. It extends accessibility actions to include both a name and user facing label. These extensions support both standard and custom actions.

We've also added actions support on Android, and added examples to RNTester showing how both standard and custom accessibility actions are used.

## Changelog

[general] [changed] - Enhanced accessibility actions support
Pull Request resolved: https://github.com/facebook/react-native/pull/24695

Differential Revision: D15391408

Pulled By: cpojer

fbshipit-source-id: 5ed48004d46d9887da53baea7fdcd0e7e15c5739
2019-05-20 01:32:53 -07:00
Joshua Gross b0d1f9ac10 ReadableNativeMap: `importKeys` shouldn't choke on null `map_`
Summary: Make sure that `importKeys` doesn't choke on null `map_`, since ReadableNativeMap can have a null backing `map_`.

Reviewed By: mdvacca

Differential Revision: D15360094

fbshipit-source-id: b507bdd93c247153aa34e4f62ac6f93349c1faf5
2019-05-17 18:04:16 -07:00
luancurti bb060d6cf8 Fix DatePickerAndroid with mode spinner on Android Nougat(7.0) (#24739)
Summary:
When mode is spinner in Android Nougat the DatePicker shows calendar

I got it from https://gist.github.com/jeffdgr8/6bc5f990bf0c13a7334ce385d482af9f and
did some adjustments in order to work with `DatePicker`. Workaround for this bug: https://code.google.com/p/android/issues/detail?id=222208. In Android 7.0 Nougat, spinner mode for the DatePicker in DatePickerDialog is incorrectly displayed as calendar.

## Changelog

[Android][Fixed] Fix date picker with mode spinner on Android Nougat (7.0)
Pull Request resolved: https://github.com/facebook/react-native/pull/24739

Differential Revision: D15391354

Pulled By: cpojer

fbshipit-source-id: 09f45367250aa14857a9c68846c7f2ce7c49ee3b
2019-05-17 02:54:12 -07:00
Oleg Lokhvitsky 7abfd23b90 Fix error in Animated Interpolation when inputMin === inputMax
Summary:
This is already handled cleanly on the JS side of things in AnimatedInterpolation.js: 0ee5f68929/Libraries/Animated/src/nodes/AnimatedInterpolation.js (L133-L142)

However, the native driver interpolation will try to divide by 0, produce NaN and then crash. This change just copies the logic from the JS version of the interpolation logic and adds it to the Java version.

Note that this bug only reproduces on Android Q. It seems that RenderNode::setCameraDistance now crashes when receiving NaN on Android Q.

Reviewed By: sahrens

Differential Revision: D15380844

fbshipit-source-id: cfa82d8f58574e1040a851aaa5b5af1e23c9daa8
2019-05-16 18:15:11 -07:00
David Vacca 016afe26bc Adding @Nullable into Fabric UI Manager
Summary: cleanup diff to add Nullable annotations into Fabric UI Manager classes

Reviewed By: shergin

Differential Revision: D15365295

fbshipit-source-id: b9d39addd5b71377389a7687ea3176cd4359c5ba
2019-05-16 13:00:25 -07:00
Alexey Lang 1ece46b42c Use array map from android support library
Summary: `android.util.ArrayMap` ins't available on API < 19. Let's use the one that Android Support Library (aka AndroidX) provides.

Reviewed By: mdvacca

Differential Revision: D15372704

fbshipit-source-id: 5c2ea3c7ea7368bb75ff22c54af0b258558556b5
2019-05-16 11:02:58 -07:00
Dulmandakh 654868da33 revert gradle download plugin import (#24863)
Summary:
Revert Gradle download plugin import, because new way is causing some issues when building from source.

## Changelog

[Android] [Changed] - revert Gradle download plugin import
Pull Request resolved: https://github.com/facebook/react-native/pull/24863

Differential Revision: D15352002

Pulled By: cpojer

fbshipit-source-id: 5996ce8aeeca1fdd8b43fdc9087af705cf7f682d
2019-05-15 03:31:04 -07:00
Sidharth Guglani a2707ac97d added listener in flipper plugin for yoga
Summary:
Adds YogaEventListener interface and it's implementation which will be used in flipper for events coming from Yoga
After this diff , we will start getting layout calculate events in flipper listener

Reviewed By: davidaurelio

Differential Revision: D15316928

fbshipit-source-id: da3a53374a52386037b553d460038d988b0162c2
2019-05-15 01:20:08 -07:00
Joshua Gross 04782ff57a Send ReactNative C++ State to Android `measure` API
Summary:
The `measure` API receives LocalData and Props, it should also receive State.

This will also be used in future diffs.

Reviewed By: mdvacca

Differential Revision: D15325182

fbshipit-source-id: 6cb46dd603ce7d46673def16f0ddb517e2cf0c4f
2019-05-14 14:22:10 -07:00
Moti Zilberman a05e9f8e09 Android: Sort modules by ID when serializing delta bundle
Summary:
Fixes redbox/yellowbox symbolication when the Java delta client is enabled. Previously the modules would get concatenated in a nondeterministic order (owing to Metro's parallelism) which differed from their order in the source map, where they're explicitly sorted by module ID.

This diff changes the data structure holding modules in memory from a `LinkedHashMap` (which iterates in insertion order) to a `TreeMap` (which iterates in key order).

NOTE: Similar to this change in the Chrome debugger's delta client: https://github.com/react-native-community/cli/pull/279

Reviewed By: dcaspi

Differential Revision: D15301927

fbshipit-source-id: 27bdecfb3d6963aa358e4d542c8b7663fd9eb437
2019-05-14 10:24:57 -07:00
wojteg1337 e4aff423ac fix: set js delta bundle default value to false (#24848)
Summary:
When running Android app for the first time, the packager is requesting delta bundles from metro instead of a bundle (in dev settings delta bundles are disabled by default and marked as experimental). UI of dev settings is not consistent with the current state, to turn off delta bundles you have to enable them and then disable.

[Android] [Fixed] - Disable delta bundles on the first app run
Pull Request resolved: https://github.com/facebook/react-native/pull/24848

Differential Revision: D15334059

Pulled By: cpojer

fbshipit-source-id: 384a8abba64c54db3656a4d5d0e24acc825870c8
2019-05-14 04:20:14 -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
Emily Janzer c75f062a77 Change JSCallInvoker to be an abstract class
Summary: The existing implementation of JSCallInvoker holds a reference to Instance (aka the bridge). This diff makes JSCallInvoker an abstract base class that's extended by BridgeJSCallInvoker, which is what's returned by CatalystInstance to initialize TurboModules. This will allow us to add another class that derives from JSCallInvoker that doesn't rely on the bridge.

Reviewed By: shergin

Differential Revision: D15252375

fbshipit-source-id: 75eee2ca149235a63e2a2cd8cdd361b163d1d1ab
2019-05-13 12:04:33 -07:00
Luna Wei 0d7a0dc997 Add log to view that is being dropped
Summary:
We are getting errors where views are being dropped twice.
This is following from logic that viewManagers are only removed from `mTagsToViewManagers` from `dropView`.

This log will hopefully identify if we are getting improper operations because we shouldn't be re-using tags

Reviewed By: mdvacca

Differential Revision: D15152869

fbshipit-source-id: 914ee9c1772fa066adefde0753075ecba6377a0c
2019-05-13 11:00:55 -07:00
David Vacca 1b4678105b Ensures constraintSurfaceLayout is executed before 'JS run application' starts
Summary:
This diff ensures the method scheduler.constraintSurfaceLayout is executed before the JS run application start.
This is necessary to properly set the pointScaleFactor for the Root before running JS.

This is a workaround to fix a bug when the pointScaleFactor changes over time for the rootShadowNode. The bug is easily reproducible when rendering the "fabric" indicator on Fabric screens. During the first render of a Fabric screen this method was called before "JS run application" starts, and the Fabric indicator was render correctly.
Beacuse of timing of measure APIS, the second time a Fabric screen is rendered the method is called after the "JS run application process started", as a consecuence the Fabric indicator is not rendered correctlly (the pointScaleFactor is incorrectly assigned into the layout metrics of the Fabric indicator text).

We still need to analyze why the pointScaleFactor is not correctly assigned when it is set after the "JS run application process started", but this will be part of another diff.

Reviewed By: shergin

Differential Revision: D15303554

fbshipit-source-id: 7d985cefee20fd40dbe04166c1a1358b3f3ddc85
2019-05-10 16:32:01 -07:00
Valentin Shergin 184073813e Fabric: Making `YogaStylableProps.yogaStyle` protected
Summary: `YogaStylableProps.yogaStyle` is designed to be consumed by Yoga only. Making it `protected` allows us to avoid confusion and misuse of this props.

Reviewed By: JoshuaGross

Differential Revision: D15296474

fbshipit-source-id: cf9e416afee99fb426d72765557b34d303a63dbe
2019-05-10 15:34:25 -07:00
Kudo Chien 310cc38a5a Fix PickerAndroid will reset selected value during items update. (#24793)
Summary:
Fixes #13351

Two root causes:
1. Android Spinner will reset selection to undefined after setAdapter()
   which will trigger onValueChange().
   The behavior is not expected for RN.
   And the solution is to setSelection() explicitly

2. In original implementation, it setups `items` immediately,
   but delays the `selected` setup after update transaction.
   There will be some race condition and incosistency
   if update `items` only.
   The fix will do the setup all after update transaction.

[Android] [Fixed] - Fix #13351 PickerAndroid will reset selected value during items update.
Pull Request resolved: https://github.com/facebook/react-native/pull/24793

Differential Revision: D15293516

Pulled By: cpojer

fbshipit-source-id: 5a99a60015c7e1b2968252cdc0b2661d52a15b9d
2019-05-10 02:01:14 -07:00
Maciej Srokowski ebeb893b50 Fix Android Camera Roll crash on mime type guessing (#24780)
Summary:
Fixes this issue:
https://github.com/facebook/react-native/issues/24468
It was incorrectly closed by a fix on react-native-community CameraRoll implementation. CameraRoll in react-native still crashes when finding a file with # sign

[Android] [Fix] - Fix Android Camera Roll crash on mime type guessing
Pull Request resolved: https://github.com/facebook/react-native/pull/24780

Reviewed By: mdvacca

Differential Revision: D15281062

Pulled By: lunaleaps

fbshipit-source-id: ca3364c8478d9bfc9a0a6657b531ffb384145d8c
2019-05-09 18:40:59 -07:00
Emily Janzer d5b27fc0a8 Allow creating ThemedReactContext without a CatalystInstance
Summary: In the future we're planning to decouple ThemedReactContext from the bridge (CatalystInstance). For now, we just need to be able to create a ThemedReactContext with a ReactContext that has no Catalyst instance.

Reviewed By: mdvacca

Differential Revision: D15246442

fbshipit-source-id: 99ebda6521f4df72969011ea0e6ea41b046875c8
2019-05-09 17:47:18 -07:00
Emily Janzer db40c28728 Move message queue initialization in ReactContext into its own method
Summary: Refactoring ReactContext to move message queue initialization into its own function that can be called independently of initializeWithInstance. This allows you to create a ReactContext with message queue threads without a CatalystInstance.

Reviewed By: mdvacca

Differential Revision: D15246287

fbshipit-source-id: 4b8c53e68112af7eded47d8c31311500cc296dfe
2019-05-09 15:49:18 -07:00
Emily Janzer 078f14c5d2 Require passing in JSCallInvokerHolder to TurboModuleManager
Summary: Right now TurboModuleManager gets the JSCallInvokerHolder from the bridge in its constructor; this diff changes the constructor to make the JSCallInvokerHolder a required argument so that TurboModuleManager doesn't directly depend on the bridge.

Reviewed By: axe-fb, RSNara

Differential Revision: D15227184

fbshipit-source-id: b16e6abaa727587986a132d0e124163acdf55408
2019-05-09 11:28:30 -07:00
David Aurelio 7d44113bee **breaking:** remove `YGNodeGetInstanceCount`
Summary:
@public

`YGNodeGetInstanceCount` was only ever meant for tests, and caused data races in multi-threaded environments.

It was completely replaced with event-based counting for tests.

Here we remove public API around the counter, and the counter itself.

Reviewed By: SidharthGuglani

Differential Revision: D15174857

fbshipit-source-id: 228e85da565bac9e8485121e956a2e41910b11c8
2019-05-09 04:22:42 -07:00
Joshua Gross d7447fadeb Core React/Litho support and Java codegen
Summary:
Core React/Litho support and Java codegen. View updating still in progress.

Generated ViewManager code:

```
// Copyright 2004-present Facebook. All Rights Reserved.
//
// Autogenerated by ComponentsReactNativeSupportProcessor
package com.facebook.catalyst.samples.componentsembedding;

import com.facebook.litho.Component;
import com.facebook.litho.ComponentContext;
import com.facebook.litho.reactnative.ComponentsShadowNode;
import com.facebook.litho.reactnative.ComponentsViewManager;
import com.facebook.litho.reactnative.ReactLithoView;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.StateWrapper;
import com.facebook.react.uimanager.ThemedReactContext;
import java.util.HashMap;
import java.util.Map;

ReactModule(
    name = "SampleComponent"
)
public class GeneratedSampleComponentViewManager extends ComponentsViewManager {
  Override
  public String getName() {
    return "SampleComponent";
  }

  Override
  public ReactLithoView createViewInstanceWithProps(ThemedReactContext context,
      ReactStylesDiffMap props) {
    Map<String, Object> propsMap;
    if (props != null && props.toMap() != null) {
      propsMap = props.toMap();
    } else {
      // Non-Fabric will always follow this path, initial props are never provided;
      return ReactLithoView.create(context, null, null);
    }
    Component component = createComponentInstanceWithPropsMap(new ComponentContext(context), propsMap);
    return ReactLithoView.create(context, component, propsMap);
  }

  Override
  public Component createComponentInstanceWithPropsMap(ComponentContext context,
      Map<String, Object> propsMap) {
    SampleComponent.Builder componentBuilder = SampleComponent.create(context);
    setComponentBuilderPropsWithMap(componentBuilder, propsMap);
    return componentBuilder.build();
  }

  Override
  public void updateProperties(ReactLithoView view, ReactStylesDiffMap props) {
    super.updateProperties(view, props);
    Map<String, Object> propsMap = props.toMap();
    Map<String, Object> oldProps = view.getProps();
    if (oldProps == null) {
      // Non-Fabric RN will always terminate here; we do not store props, nor do we need to.;
      // Prop updating happens incrementally in non-Fabric RN.;
      return;
    }
    Map<String, Object> mergedProps = new HashMap<>(oldProps);
    mergedProps.putAll(propsMap);
    SampleComponent.Builder componentBuilder = SampleComponent.create(new ComponentContext(view.getComponentContext()));
    setComponentBuilderPropsWithMap(componentBuilder, mergedProps);
    view.setProps(mergedProps);
    view.setComponent(componentBuilder.build());
  }

  private void setComponentBuilderPropsWithMap(SampleComponent.Builder componentBuilder,
      Map<String, Object> propsMap) {
    if (propsMap != null && propsMap.containsKey("title")) {
      componentBuilder.title((((String)propsMap.getOrDefault("title", null))));
    }
    if (propsMap != null && propsMap.containsKey("imageUri")) {
      componentBuilder.imageUri(android.net.Uri.parse(((String)propsMap.getOrDefault("imageUri", null))));
    }
  }

  Override
  public GeneratedSampleComponentShadowNode createShadowNodeInstance(ReactApplicationContext context) {
    return new GeneratedSampleComponentShadowNode();
  }

  Override
  public Class<? extends ComponentsShadowNode> getShadowNodeClass() {
    return GeneratedSampleComponentShadowNode.class;
  }

  Override
  public void updateState(ReactLithoView view, StateWrapper stateWrapper) {
    view.setStateWrapper(stateWrapper);
  }
}
```

Reviewed By: shergin

Differential Revision: D14846423

fbshipit-source-id: 4eeeb991f7e32c0cec5e9307d6175b81c8fd034e
2019-05-08 14:53:51 -07:00
Ramanpreet Nara f2618fd81b Fix OSS Android build (#24764)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/24764

The `test_android` CI build was failing:

```
./scripts/circleci/buck_fetch.sh
+ buck fetch ReactAndroid/src/test/java/com/facebook/react/modules
Not using buckd because watchman isn't installed.
Picked up _JAVA_OPTIONS: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
PARSING BUCK FILES: FINISHED IN 1.1s
No build file at ReactAndroid/src/main/libraries/fbjni/BUCK when resolving target //ReactAndroid/src/main/libraries/fbjni:java.

This error happened while trying to get dependency '//ReactAndroid/src/main/libraries/fbjni:java' of target '//ReactAndroid/src/main/java/com/facebook/react/turbomodule/core:jscallinvokerholder'
Exited with code 1
```

The problem was that I was using `react_native_dep("libraries/fbjni:java")` to access JNI classes like `HybridData`. In open source this target translates to the path `//ReactAndroid/src/main/libraries/fbjni`, which doesn't exist. Instead, the actual classes are available at the path `//ReactAndroid/src/main/java/com/facebook/jni`. Therefore, I changed the target to `react_native_dep("java/com/facebook/jni:jni")`. This is exactly how the bridge (i.e: `//ReactAndroid/src/main/java/com/facebook/react/bridge:bridge`) accesses JNI clases.

Reviewed By: hramos

Differential Revision: D15261218

fbshipit-source-id: 659a5627389bbca3603db7de347618cd400d4ffc
2019-05-08 12:28:26 -07:00
Alan Kenyon 09f17a4e29 AccessibilityInfo.announceForAccessibility (#24746)
Summary:
AccessibilityInfo.announceForAccessibility is currently only available on iOS. I've added the Android specific implementation, updated RNTester, and the documentation.

[Android] [Added] - Added AccessibilityInfo.announceForAccessibility for Android
[General] [Added] - RNTester example for AccessibilityInfo.announceForAccessibility
Pull Request resolved: https://github.com/facebook/react-native/pull/24746

Differential Revision: D15258054

Pulled By: cpojer

fbshipit-source-id: 3e057a5c32b28e30ea2ee74a18854b012cd2dbfd
2019-05-08 03:58:13 -07:00
Dulmandakh fd6386a07e custom fonts support The Android Way (#24595)
Summary:
In https://github.com/facebook/react-native/pull/23865, RN introduced support for custom fonts the Android Way. But it introduced performance regression because it'll lookup for a font using getIdentifier() every time fontFamily changed. This PR fixes regression by requiring custom fonts to be listed in **fonts** array, and populating **mTypeCache** at first use using the list.

[Android] [Changed] - Require custom fonts to list in **fonts** array. Fixes performance regression.
Pull Request resolved: https://github.com/facebook/react-native/pull/24595

Reviewed By: mdvacca

Differential Revision: D15184590

Pulled By: fkgozali

fbshipit-source-id: e3feb2396609583ebc95101130186a1f5af931da
2019-05-07 18:44:10 -07:00
Piotr Trocki a5c57b4ed4 onKeyPress is not fired on Android when entering an Emoji (#24717)
Summary:
Resolve #24690

This is very simple unicode detecting. Should I improve this solution creating StringsUtils for detecting unicodes in whole react-native project ?

[Android][Fixed] onKeyPress method is calling, when user type emoji
Pull Request resolved: https://github.com/facebook/react-native/pull/24717

Differential Revision: D15238388

Pulled By: cpojer

fbshipit-source-id: 038b1040e1c44fd6f9401a3988a782f5778e1209
2019-05-07 04:25:14 -07:00
Marc Mulcahy 70e2ab2ec9 Update Android view state when accessibility states are changed. (#24678)
Summary:
In #24095, we removed the code that changes the underlying Android view's enabled state to false when "disabled" is included in the accessibility states, which seems correct. The Android view's state shouldn't mirror the accessibility state, it should be the other way round-- the accessibility state should represent the state of the view.

It seems that the existing test is brokenly setting the disabled state in the Javascript object, and then querying the Android view's enabled state to confirm the change. If the Button implementation is actually the culprit, then IMHO, the correct fix would be to have the Button implementation manipulate the Android View's enabled state, not the accessibilityStates code.

[android] [fix] - Fix internal test case around disabled state of buttons
Pull Request resolved: https://github.com/facebook/react-native/pull/24678

Differential Revision: D15237590

Pulled By: cpojer

fbshipit-source-id: d7ebefbcba9d4d9425da4285175302e4b6435df7
2019-05-07 03:23:38 -07:00
Eileen Zhang bfd06958f4 Revert D14817741: Move message queue initialization in ReactContext into its own method
Differential Revision:
D14817741

Original commit changeset: f314a526c653

fbshipit-source-id: 9925e6473a261f47582c8db5cc7e9d77836cdbb5
2019-05-06 19:14:21 -07:00
Eileen Zhang 15f17d3c05 Revert D15194220: [Venice] Allow creating ThemedReactContext without CatalystInstance
Differential Revision:
D15194220

Original commit changeset: 64689cbe79c8

fbshipit-source-id: 346009e3ee00286b095f26c78abffc73efea21dd
2019-05-06 19:14:21 -07:00
Emily Janzer 6cf784fae7 Allow creating ThemedReactContext without CatalystInstance
Summary: I'm not sure if this is a good idea. Right now FabricUIManager creates a ThemedReactContext in addRootView() using the RAC you pass in. If you pass in an RAC without a Catalyst instance, this will throw; this diff makes it so it'll throw the next time you try to actually try to access the CatalystInstance, instead. I don't know if we're really relying on this right now, but we need to be able to create a ThemedReactContext without a CatalystInstance for Venice (for now, until we actually go through and get rid of TRC's dependency on the CatalystInstance entirely - but that'll be a lot more work)

Reviewed By: mdvacca

Differential Revision: D15194220

fbshipit-source-id: 64689cbe79c84ae33fe16e3dc396e3c69ec8e20f
2019-05-06 15:51:13 -07:00
Emily Janzer c6b4eb7dcf Move message queue initialization in ReactContext into its own method
Summary: Refactoring ReactContext to move message queue initialization into its own function that can be called independently of initializeWithInstance. This allows you to create a ReactContext with message queue threads without a CatalystInstance.

Reviewed By: mdvacca

Differential Revision: D14817741

fbshipit-source-id: f314a526c6534792714e5ba55dd873f1728c6b9f
2019-05-06 15:51:13 -07:00
Luna Wei 5f027ec64d Rearrange order of manageChildren
Summary:
[General] [Fix] - Reorder operations of native view hierarchy

When we update the native view hierarchy in `manageChildren` we:
1. iterate through all views we plan to remove and remove them from the native hierarchy
2. iterate through all views we plan to add and add them to the native hierarchy
3. iterate through all views we plan to delete and delete them (remove them from memory)

This covers these cases:
a. A view is moved from one place to another -- handled by steps 1 & 2
b. A view is added -- handled by step 2
c. A view is deleted -- handled by step 1 & 3

> Note the difference between remove and delete

Everything above sounds fine! But...

The important bit:
**A view that is going to be deleted asynchronously (by a layout animation) is NOT removed in step 1. It is removed and deleted all in step 3.** See: https://fburl.com/ryxp626i

If the reader may recall we solved a similar problem in D14529038 where we introduced the `pendingIndicesToDelete` data structure to keep track of views that were marked for deletion but had not yet been deleted. An example of an order of operations that we would've solved with D14529038 is:

* we "delete" the view asynchronously (view A) in one operation
* we add a view B that shares a parent with view A in subsequent operation
* view A finally calls its callback after the animation is complete and removes itself from the native view hierarchy

A case that D14529038 would not fix:
1. we add a view B in one operation
2. we delete a view A in the same operation asynchronously because it's in a layout animation
3. ... etc.

What we must remember is that the index we use to add view B in step 1 is based on the indices assuming that all deletions are synchronous as this [comment notes](https://fburl.com/j9uillje): removals (both deletions and moveFroms) use the indices of the current order of the views and are assumed independent of each other. Whereas additions are indexed on the updated order (after deletions!)

This diff re-arranges the order in how we act upon the operations to update the native view hierarchy -- similar to how UIImplementation does its operations on the shadow tree here: https://fburl.com/j9uillje

By doing the removals and deletions first, we know that the addAt indices will be correct because either the view is removed from the native view hierarchy or `pendingIndicesToDelete` should be tracking an async delete already so the addAt index will be normalized

Reviewed By: mdvacca

Differential Revision: D15112664

fbshipit-source-id: 85d4b21211ac802183ca2f0fd28fc4437d312100
2019-05-06 08:35:40 -07:00
David Vacca 57074143ac Eager initialize more Fabric classes
Summary:
This diff forces the eager initialization of some additional classes into FabricJSIModuleProvider.loadClasses().
This is a "hack" that will be removed in the near future

Reviewed By: JoshuaGross

Differential Revision: D15208977

fbshipit-source-id: 2e2c7856839b6c6888452800ef6da7f269e46735
2019-05-03 17:23:53 -07:00
Joshua Gross ff1de68e67 Java objects should own C++ State
Summary: When passing StateWrapper objects across the JNI, we were not ensuring that the Java objects would own the C++ state. This was initially done because I assumed that in Java, State would either be used immediately or discarded, so this wouldn't be unsafe. As it turns out, it makes sense in some cases to store the StateWrapper in Java and use it later, potentially even in other threads, so we need to make sure we maintain ownership of the C++ object from the Java object.

Reviewed By: shergin

Differential Revision: D15206194

fbshipit-source-id: a437d921ba00b194cf08bad80666bd99baf11d52
2019-05-03 15:51:19 -07:00
Valentin Shergin 0f2a09d1f6 Fabric: MountingCoordinator - the new way to ensure ordering of mount transaction
Summary:
TBD.
This thing fixes flickering during appearing of Fabric screens on iOS.

Reviewed By: mdvacca

Differential Revision: D15116079

fbshipit-source-id: 95ed0ba94667cad67fe4317025128d01b34f69c5
2019-05-03 15:11:35 -07:00
Valentin Shergin 4803cab8c4 Fabric: MountingTelemetry and refinments in TimeUtils
Summary: This diff implements encapsulating all time metrics in a single class for better extensibility and readability.

Reviewed By: JoshuaGross

Differential Revision: D15179835

fbshipit-source-id: 62bdf94435a0d37a87ad9bad613cc8e38043a235
2019-05-03 15:11:34 -07:00
Ramanpreet Nara d77adcadbe Fix OSS build
Summary:
`CatalystInstanceImpl.cpp` now depends on `JSCallInvoker` and `JavaJSCallInvokerHolder`. Therefore, we need to correctly adjust the OSS builds to include these dependencies into the `libreactnativejni.so` file.

I made `ReactCommon/turbomodule/jscallinvoker` a static library `libjscallinvoker.a`. I then made `ReactAndroid/src/main/jni/react/jni`'s `libreactnativejni.so` depend on that static library. Also, because the Android NDK build system doesn't support header namespaces, I had to use the filesystem to simulate them. This is why all the `.cpp` and `.h` files for `JSCallInvoker` were moved to a `jsireact` folder.

Reviewed By: mdvacca

Differential Revision: D15194821

fbshipit-source-id: 0cee682e41db53d0619f56ad017d5882f6d554aa
2019-05-03 13:31:20 -07:00
Ramanpreet Nara cba205b82c Introduce TurboModuleManagerDelegate
Summary:
`TurboModuleManagerDelegate` is an abstract base class with the following API:

```
  public TurboModule getModule(String name, ReactApplicationContext reactApplicationContext);
  public CxxModuleWrapper getLegacyCxxModule(String name, ReactApplicationContext reactApplicationContext);
```

```
  std::shared_ptr<TurboModule> getTurboModule(std::string name, jni::global_ref<JTurboModule> turboModule, std::shared_ptr<JSCallInvoker> jsInvoker) override;
  std::shared_ptr<TurboModule> getTurboModule(std::string name, std::shared_ptr<JSCallInvoker> jsInvoker) override;
```

On the C++ side, when asked to provide a TurboModule with name `name`:

1. First, is this a CxxModule? If so:
    1. Create the CxxModule and return
2. Otherwise:
    1. Somehow get a Java instance of the TurboModule
    2. If this Java object represents a CxxModule, like `FbReactLibSodiumModule`:
        1. Grab the C++ part of this object, and wrap it in a `TurboCxxModule.cpp` and return.
    3. Otherwise:
        1. Wrap the Java object in a C++ HostObject and return.

This pseudocode demonstrates how we'd use `TurboModuleManagerDelegate` to implement `__turboModuleProxy`.
```
__turboModuleProxy(name, jsCallInvoker):
  let cxxModule = TurboModuleManagerDelegate::getTurboModule(name, jsCallInvoker)
  if (!cxxModule) {
    return cxxModule;
  }

  // JNI Call that forwards to TurboModuleManagerDelegate.getLegacyCxxModule
  let javaCxxModule : CxxModuleWrapper = TurboModuleManager.getLegacyCxxModule(name)

  if (!javaCxxModule) {
    return std::shared_ptr<react::TurboCxxModule>(javaCxxModule.getModule())
  }

  // JNI Call that forwards to TurboModuleManagerDelegate.getModule
  let javaModule : TurboModule = TurboModuleManager.getModule(name)

  if (!javaCxxModule) {
    return TurboModuleManagerDelegate::getTurboModule(name, javaModule, jsCallInvoker)
  }

  return null
```

Reviewed By: mdvacca

Differential Revision: D15111335

fbshipit-source-id: c7b0aeda0e4565e3a2729e7f9604775782b6f893
2019-05-03 13:31:20 -07:00
Ramanpreet Nara ef4955fefe Make async calls work
Summary:
JSCallInvoker requires a `std::weak_ptr<Instance>` to create. In our C++, `CatalystInstance` is responsible for creating this `Instance` object. This `CatalystInstance` C++ initialization is separate from the `TurboModuleManager` C++ initialization. Therefore, in this diff, I made `CatalystInstance` responsible for creating the `JSCallInvoker`. It then exposes the `JSCallInvoker` using a hybrid class called `JSCallInvokerHolder`, which contains a `std::shared_ptr<JSCallInvoker>` member variable. Using `CatalystInstance.getJSCallInvokerHolder()` in TurboModuleManager.java, we get a handle to this hybrid container. Then, we pass it this hybrid object to `TurboModuleManager::initHybrid`, which retrieves the `std::shared_ptr<JSCallInvoker>` from the `JavaJSCallInvokerHandler`.

There were a few cyclic dependencies, so I had to break down the buck targets:
- `CatalystInstanceImpl.java` depends on `JSCallInvokerHolderImpl.java`, and `TurboModuleManager.java` depends on classes that are packaged with `CatalystInstanceImpl.java`. So, I had to put `JSCallInvokerHolderImpl.java` in its own buck target.
- `CatalystInstance.cpp` depends on `JavaJSCallInvokerHolder.cpp`, and `TurboModuleManager.cpp` depends on classes that are build with `CatalystInstance.cpp`. So, I had to put `JavaJSCallInvokerHolder.cpp` in its own buck target. To make things simpler, I also moved `JSCallInvoker.{cpp,h}` files into the same buck target as `JavaJSCallInvokerHolder.{cpp,h}`.

I think these steps should be enough to create the TurboModuleManager without needing a bridge:
1. Make `JSCallInvoker` an abstract base class.
2. On Android, create another derived class of `JSCallInvoker` that doesn't depend on Instance.
3. Create `JavaJSCallInvokerHolder` using an instance of this new class somewhere in C++.
4. Pass this instance of `JavaJSCallInvokerHolder` to Java and use it to create/instatiate `TurboModuleManager`.

Regarding steps 1 and 2, we can also make JSCallInvoker accept a lambda.

Reviewed By: mdvacca

Differential Revision: D15055511

fbshipit-source-id: 0ad72a86599819ec35d421dbee7e140959a26ab6
2019-05-03 13:31:20 -07:00
Joshua Gross 4a1d532674 Convert FabricUIManager.measure params to floats
Summary: Convert FabricUIManager.measure params to floats. Currently we convert parameters to ints across the JNI boundary, and then back to floats several times in Java. This is unnecessary and actually makes measurements trickier. The new implementation uses floats across the JNI boundary and uses Float.POSITIVE_INFINITY to represent unconstrained values, which is consistent with Fabric C++ as well.

Reviewed By: shergin, mdvacca

Differential Revision: D15176108

fbshipit-source-id: cf849b3773007637f059279460163872f300a4aa
2019-05-03 12:36:28 -07:00
Marc Horowitz 4900077e83 Add libfolly_futures target
Summary: This new target provides dependencies for using folly futures

Reviewed By: willholen

Differential Revision: D15018282

fbshipit-source-id: c38ad4775102b9f0c10b3a52c5a18f00aa398322
2019-05-01 18:44:26 -07:00
Marc Horowitz 709baabb62 add to inputs in buildReactNdkLib so gradle will rebuild on more changes
Summary: This make iteration work better without needing to clean as much

Reviewed By: willholen

Differential Revision: D15018285

fbshipit-source-id: 034f5529e2e51711aeaa75360ad10bb1f85c7fb8
2019-05-01 18:44:26 -07:00
Marc Horowitz 7486c77ab5 make prepareGlog idempotent
Summary:
The path to copy log_severity.h could refer to the
destination, which would result in an empty file being copied on some
rebuilds.

Reviewed By: willholen

Differential Revision: D15018283

fbshipit-source-id: 0081526a9686de8c74753738c165753de6dda18d
2019-05-01 18:44:26 -07:00
Tim Wang 88dbb4558c Use class canonical name for PARTIAL_WAKE_LOCK tag (#24673)
Summary:
When acquiring the `PARTIAL_WAKE_LOCK`, Android requires a tag to identify the source, normally the class name. This tag will show on dumpsys call and Google Play developer console.

`getSimpleName` will work fine as long as not enable ProGuard, in my case, it transformed the class name to just `"c"`, and I take my half day to find where the `c` comes from.

`getCanonicalName` will add the package path, which is more friendly for developers.

Later we can even let the developer choose the tag name, but this will require API break changes.

[Android] [Changed] - Use class canonical name for PARTIAL_WAKE_LOCK tag
Pull Request resolved: https://github.com/facebook/react-native/pull/24673

Differential Revision: D15164306

Pulled By: cpojer

fbshipit-source-id: fd65f9e5250c180b0053940b17877fe36af5d48b
2019-05-01 02:53:54 -07:00
David Vacca b3a07685f2 Add debug information in Mounting Manager
Summary: Easy diff that adds debug information in Mounting Manager

Reviewed By: JoshuaGross

Differential Revision: D15076577

fbshipit-source-id: 183c87c929ea7a99f0667956c33012d7dfdb246e
2019-04-30 15:05:02 -07:00
David Vacca abbeac9bb3 Refactor mapping of ComponentNames in FabricUIManager
Summary: The map of sComponentNames ONLY contains the names of components that are different between JS and Android. This diff adds a method to unify the way we use this map.

Reviewed By: shergin

Differential Revision: D15076549

fbshipit-source-id: 9df750dca305e55cb44037bc63f3ebb6476c8b81
2019-04-30 15:05:02 -07:00
David Vacca 532afbde6e Add support for Modal in Android
Summary: This diff implements Modal for Android in Fabric

Reviewed By: JoshuaGross

Differential Revision: D15069863

fbshipit-source-id: 4171c9590a4a7a1f4f80cf9b08ea9a9e94b9097a
2019-04-30 15:05:01 -07:00
Michał Pierzchała 49d26eb0c4 cleanup RedBox message and stack output (#24662)
Summary:
Cleanup RedBox messages and stack traces. This PR consists of 2 changes (I'm good with splitting them up if you'd like):

- [general] filter out some of the internal callsites from the symbolicated stack (I thought about using monospace font for title with code frame, but it looks weird)
- [ios][android] strip ANSI characters (coming from colored Babel code frame) from the error message

I think it's ok to strip it inside native handlers so we can still have a colorful code frame in the terminal output.

**JS Code frame:**

|before|after|
|--|--|
|<img width="400" alt="Screenshot 2019-04-30 at 12 32 05" src="https://user-images.githubusercontent.com/5106466/56956590-ef678d80-6b44-11e9-9019-6801f050ab0d.png">|<img width="400" alt="Screenshot 2019-04-30 at 12 52 43" src="https://user-images.githubusercontent.com/5106466/56957302-f42d4100-6b46-11e9-869b-ea9c7ce5b90f.png">|

|before|after|
|--|--|
|![image](https://user-images.githubusercontent.com/5106466/56959472-c8618980-6b4d-11e9-84be-6261d8375f4a.png)|![image](https://user-images.githubusercontent.com/5106466/56959463-bc75c780-6b4d-11e9-9d8b-25ffe46c87cf.png)|

**Filtered stack traces:**

|before|after|
|--|--|
|<img width="50%" alt="Screenshot 2019-04-30 at 12 27 21" src="https://user-images.githubusercontent.com/5106466/56956641-0908d500-6b45-11e9-8cdc-8c2a34a071e5.png"><img width="50%" alt="Screenshot 2019-04-30 at 12 27 28" src="https://user-images.githubusercontent.com/5106466/56956642-0908d500-6b45-11e9-921c-fabfb8515cc0.png">|<img width="100%" alt="Screenshot 2019-04-30 at 12 26 55" src="https://user-images.githubusercontent.com/5106466/56956650-0efeb600-6b45-11e9-9f5f-f10dd69580d1.png">|

There's still a lot of places that are hard to read, but I think this is a good start towards more readable errors.

cc cpojer

[General][Changed] - Cleanup RedBox message and stack output
Pull Request resolved: https://github.com/facebook/react-native/pull/24662

Differential Revision: D15147571

Pulled By: cpojer

fbshipit-source-id: 1de4e521af988fa7fc709b6accd0ddd984388e72
2019-04-30 07:35:14 -07:00
David Vacca 61d2f1e6be Display wrong view hierarchy in Test exceptions
Summary: Trivial diff that adds extra logging information on Exceptions that are thrown by the FabricViewTest

Reviewed By: shergin

Differential Revision: D14817899

fbshipit-source-id: 32e1d1fcd1292715dfcf2750d3f14c668927c8b8
2019-04-30 01:48:25 -07:00
David Vacca f98880b1a3 - Fix mounting of views when a re-order happen caused by changes in viewflattening
Summary:
This diff fixes a bug that is reproducible when a view is reordered in a different level of hierarchy in the react tree.
Even if this is not supported by react, this can still happen because of viewFlattening.

Reviewed By: shergin

Differential Revision: D14817452

fbshipit-source-id: 13425b0e6a280affe681e80b4a6daa17ee56251a
2019-04-30 01:48:25 -07:00
David Vacca 81d0f9a690 Ensure proper Synchronization on ReactChoreographer
Summary: This diff refactors the way we synchronize in ReactChoreographer using a lock object

Reviewed By: ejanzer

Differential Revision: D14913056

fbshipit-source-id: e86c4395d5d3c3fd5b7330b72c14920b536f74ce
2019-04-29 18:12:01 -07:00
Emiel Mols 6f6696fa63 ReactAndroid: JS errors during bundle load were reported as UnknownCppException (#24648)
Summary:
This fixes a regression on Android introduced by f3e5cce where JS errors thrown during bundle load were lost (shown only as UnknownCppException). It is especially tough to debug (custom) bundling errors without seeing the javascript error.

Root cause hypothesis: since switching to clang, `JSError`s thrown in ReactCommon's `JSCRuntime::checkException` were never matched as `std::exception` in ReactAndroid's `convertCppExceptionToJavaException` due to these missing flags.

I'm a bit shy on low-level details concerning how C++ rtti works exactly around catching exceptions thrown in other libraries. All I can say that with this change, a `bundle.android.js` that only contains `throw new Error("wtf");` now nicely outputs a message and stack trace in the logcat. Before (and since DanielZlotin's switch to clang) it just outputted:

```
2019-04-29 12:17:59.365 1162-1306/com.rntest E/unknown:ReactNative: Exception in native call
    com.facebook.jni.UnknownCppException: Unknown
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:214)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:764)
```

[Android] [Fixed] - JS errors during bundle load were reported as UnknownCppException.
Pull Request resolved: https://github.com/facebook/react-native/pull/24648

Differential Revision: D15123525

Pulled By: mdvacca

fbshipit-source-id: 74b5ce9ebae38d172446b6e31739d795c601947b
2019-04-29 09:51:15 -07:00
Guilherme Iscaro 20b09e4c45 The ART '<Surface>' becomes invisible in Android (#22624)
Summary:
Hello Everyone, this series of commits helps to fix problems related to ART on Android. The main problem in here is that the ART components would disappear if the user turns off the screen and then turn it on again.  It's important to note that this behaviour only occurs after Android N (7.1 or higher).
Pull Request resolved: https://github.com/facebook/react-native/pull/22624

Differential Revision: D15122573

Pulled By: cpojer

fbshipit-source-id: e7fb8b9280b4c52562e3d0c1a89759d4d31cd53d
2019-04-29 09:30:56 -07:00
Janic Duplessis 9fba85569c Fix crash when borderXColor is null on Android (#24640)
Summary:
On android when borderXColor is null it causes the app to crash with:

```
04-28 17:44:18.021 20114 20213 E unknown:ReactNative: com.facebook.react.bridge.NoSuchKeyException: borderBottomColor
04-28 17:44:18.021 20114 20213 E unknown:ReactNative: 	at com.facebook.react.bridge.ReadableNativeMap.getValue(ReadableNativeMap.java:111)
04-28 17:44:18.021 20114 20213 E unknown:ReactNative: 	at com.facebook.react.bridge.ReadableNativeMap.getValue(ReadableNativeMap.java:115)
04-28 17:44:18.021 20114 20213 E unknown:ReactNative: 	at com.facebook.react.bridge.ReadableNativeMap.getInt(ReadableNativeMap.java:158)
04-28 17:44:18.021 20114 20213 E unknown:ReactNative: 	at com.facebook.react.uimanager.ViewProps.isLayoutOnly(ViewProps.java:246)
04-28 17:44:18.021 20114 20213 E unknown:ReactNative: 	at com.facebook.react.uimanager.NativeViewHierarchyOptimizer.isLayoutOnlyAndCollapsable(NativeViewHierarchyOptimizer.java:482)
```

Basically it is missing a `isNull` check on the props map before trying to access the value.

Fixes #22727

[Android] [Fixed] - Fix a crash when borderXColor is null
Pull Request resolved: https://github.com/facebook/react-native/pull/24640

Differential Revision: D15120182

Pulled By: cpojer

fbshipit-source-id: bc41da572f04d8abf733b5a4e94a74a0f40acda1
2019-04-29 03:31:03 -07:00
Dulmandakh bb6f316c87 Gradle KTS (#24631)
Summary:
Convert root Gradle script to Kotlin DSL, and cleanup. Currently, there is not much benefit or advantage over Groovy scripts, except IDE support and it'll cache compiled KTS scripts on first run.

[Android] [Changed] - Convert root Gradle script to Kotlin DSL, and cleanup.
Pull Request resolved: https://github.com/facebook/react-native/pull/24631

Differential Revision: D15120190

Pulled By: cpojer

fbshipit-source-id: 86691db5c7746e71bb243ebc263c1a3075ee9a9e
2019-04-29 02:41:05 -07:00
Dulmandakh 30348f7899 bump android gradle plugin to 3.4.0 (#24463)
Summary:
This PR bumps Android Gradle Plugin to 3.4.0, which enables R8 shrinker by default and improves build performance significantly.

Disabled R8 for ReactAndroid because it'll strip out AndroidX and other libraries bundled in ReactAndroid.

[Android] [Changed] - bump Android Gradle plugin to 3.4.0
Pull Request resolved: https://github.com/facebook/react-native/pull/24463

Differential Revision: D15107117

Pulled By: hramos

fbshipit-source-id: 35a03dc9955e889c9399faeaf9a862e0fc044fc4
2019-04-27 09:43:19 -07:00
Kevin Gozali 4b4c8d4d02 android: renamed strings.xml to strings_unlocalized.xml
Summary: 9079beda9b wasn't enough to blacklist the strings.xml files from FB infra. So this is a better workaround. According to https://developer.android.com/guide/topics/resources/string-resource the .xml file names doesn't really matter, so this shouldn't break the ability to get the string resource in code, like `R.strings.foo`.

Reviewed By: yungsters

Differential Revision: D15103303

fbshipit-source-id: 6d5174a8dc9598930670d35434e1494f9eaea059
2019-04-26 15:34:09 -07:00
Dulmandakh 243070afe2 DialogModule supports only FragmentActivity (#23365)
Summary:
Now RN has only ReactActivity which extends AppCompatActivity, subclass of FragmentActivity, therefore no need to check if activity is FragmentActivity or not. This PR changes DialogModule to work only with FragmentActivity.

Also DialogFragment from Android is deprecated in API 28, and recommends to use DialogFragment from Support Library. Excerpt from DialogFragment documentation.

> **This class was deprecated in API level 28.**
> Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.

**BREAKING CHANGE**: Brown field apps must extend FragmentActivity or its subclasses.

[Android] [Changed] - DialogModule supports only FragmentActivity
Pull Request resolved: https://github.com/facebook/react-native/pull/23365

Differential Revision: D14021986

Pulled By: cpojer

fbshipit-source-id: b0ede60ef19cec48111a12701659a8bc1f66c331
2019-04-26 02:46:24 -07:00
Build Service b46eda78a9 translation auto-update for i18n/fb4a.config.json on master
fbshipit-source-id: eaad91325c24d3e763910c46f95aa279fffea3a0
2019-04-25 22:41:19 -07:00
Build Service de29553818 translation auto-update for i18n/expresswifi.config.json on master
fbshipit-source-id: 88df8402fa6a64d18f6b73f357effbac23e0b6e4
2019-04-25 22:41:19 -07:00
Build Service 8eac1b3a4e translation auto-update for i18n/creatorapp.config.json on master
fbshipit-source-id: 71a74ed00df788b08533767924af7b772b327d4d
2019-04-25 22:41:18 -07:00
Build Service 86c2706d85 translation auto-update for i18n/bishop.config.json on master
fbshipit-source-id: 6ac2bf6d98f5af1e4ab0f99988224f92b9817ef2
2019-04-25 22:41:18 -07:00
Build Service 4585e3bd8e translation auto-update for i18n/analyticsapp.config.json on master
fbshipit-source-id: 7e418e80bdebe43a4c003a13629eaef3f1f97fab
2019-04-25 22:41:18 -07:00
Build Service 0db8226392 translation auto-update for i18n/adsmanager.config.json on master
fbshipit-source-id: b7f3a877004704368bb3e0e54dae2e7e50d3649c
2019-04-25 22:41:18 -07:00
Kevin Gozali 9079beda9b OSS: Marked strings.xml as non-translatable and removed irrelevant translations
Summary: These strings shouldn't be translated by FB system because each app has its own set of languages and/or translation outputs. We're keeping just values/strings.xml in the repo.

Reviewed By: cpojer

Differential Revision: D15087192

fbshipit-source-id: c4b6112f6dd010d317060ac6640b34e4b725c695
2019-04-25 16:29:23 -07:00
Kevin Gozali eb40b09bfd Back out "[react-native][PR] add support for native/downloadable fonts"
Summary: Original commit changeset: 67ba3148fb4b

Reviewed By: cpojer

Differential Revision: D15071309

fbshipit-source-id: 8ea6b40ae7cedd8aec1463373ccd219212fce0f5
2019-04-25 11:15:08 -07:00
Build Service 5592744825 translation auto-update for i18n/pages-manager.config.json on master
fbshipit-source-id: 0ddad3606613fe285bf10116d697096c7ab9779c
2019-04-25 10:59:50 -07:00
Build Service 27d2506dc7 translation auto-update for i18n/onavo-spaceship.config.json on master
fbshipit-source-id: 872f5a198325f4bb9c64d1af565738c293127c1d
2019-04-25 10:59:50 -07:00
Build Service 7a786ab1f0 translation auto-update for i18n/instagram.config.json on master
fbshipit-source-id: b349b15e647805ff824c97a4e9f650d52da73c22
2019-04-25 10:59:49 -07:00
Build Service b56e183f9e translation auto-update for i18n/instagram-igtv.config.json on master
fbshipit-source-id: 05869242c5d4df4bfff5556b234213508f1bc839
2019-04-25 10:59:49 -07:00
Build Service 8ddd37c56d translation auto-update for i18n/fb4a.config.json on master
fbshipit-source-id: 19ed7b34aff5385594696e66d925d40c766f9c00
2019-04-25 10:59:49 -07:00
Build Service 79bde6a48a translation auto-update for i18n/expresswifi.config.json on master
fbshipit-source-id: 302ee057295da87390d8606e0be81177d2c7ab29
2019-04-25 10:59:48 -07:00
Build Service 86462bfc84 translation auto-update for i18n/creatorapp.config.json on master
fbshipit-source-id: e003d25cc264e405700dae029ab07a56c4b7c508
2019-04-25 10:59:48 -07:00
Build Service 5628ac6447 translation auto-update for i18n/bishop.config.json on master
fbshipit-source-id: e83ff7061c7a6106cc4174b1512f9ae928a708b3
2019-04-25 10:59:48 -07:00
Build Service 28c18fcef5 translation auto-update for i18n/analyticsapp.config.json on master
fbshipit-source-id: 545d7d3d211996f2e600d92cddeac96c3c976378
2019-04-25 10:59:48 -07:00
Build Service ef4c9867d8 translation auto-update for i18n/adsmanager.config.json on master
fbshipit-source-id: 7f0c41e577c55458961e863c33ecd0f01a41b633
2019-04-25 10:59:47 -07:00
Marc Mulcahy 1aeac1c625 Additional Accessibility Roles and States (#24095)
Summary:
Assistive technologies use the accessibility role of a component to tell the disabled user what the component is, and provide hints about how to use it. Many important roles do not have analog AccessibilityTraits on iOS. This PR adds many critical roles, such as editabletext, checkbox, menu, and switch to name a few.

Accessibility states are used to convey the current state of a component. This PR adds several critical states such as checked, unchecked, on and off.

[general] [change] - Adds critical accessibility roles and states.
Pull Request resolved: https://github.com/facebook/react-native/pull/24095

Differential Revision: D15079245

Pulled By: cpojer

fbshipit-source-id: 941b30eb8f5d565597e5ea3a04687d9809cbe372
2019-04-25 06:13:07 -07:00
Thorben Primke 954f715b25 Adds Logic To Catch MissingWebViewPackageException (#24533)
Summary:
We are seeing crash reports that the webview is missing. In this case
it should fail gracefully so that a missing webview does not block
from using an app built with React Native.

The contains could also be changed to check for "webview" in general
to catch all webview related exception. It's currently checking on
for the specific string that I'm seeing in our app's crashreporting tool.

<img width="1507" alt="Screen Shot 2019-04-19 at 11 26 19 AM" src="https://user-images.githubusercontent.com/741767/56438307-5e1c2f80-6297-11e9-970b-a5095d18e9d7.png">

<img width="935" alt="Screen Shot 2019-04-19 at 11 32 58 AM" src="https://user-images.githubusercontent.com/741767/56438213-fa920200-6296-11e9-8008-5eb344eca8a8.png">

[Android] [Fixed] - The ReactCookieJarContainer/ForwardingCookieHandler now handles the missing WebView  gracefully.
Pull Request resolved: https://github.com/facebook/react-native/pull/24533

Differential Revision: D15062824

Pulled By: cpojer

fbshipit-source-id: 80805a47494f0d924b7ee029ce8ca0504eaeee57
2019-04-24 06:58:15 -07:00
Christoph Nakazawa 8d3e16831a Revert "improve RTL (#24069)" (#24580)
Summary:
This reverts commit b3c74967ca.

Fixes #24267

[Android] [Fixed] - Invalid text alignment for RTL fonts.
Pull Request resolved: https://github.com/facebook/react-native/pull/24580

Differential Revision: D15061667

Pulled By: cpojer

fbshipit-source-id: 6d02c9e938f1f8630ba691f57bdf79fd57db3bb2
2019-04-24 03:45:41 -07:00
David Aurelio 54af7fc645 `YGStyle`: wrap all fields into accessors
Summary:
@public

In order to encapsulate property access on `YGStyle`, as a first measure we wrap all fields with accessors.

This will e.g. enable dynamic property storage and instrumentation in the future.

All accessors have a `const` version that allows direct access via `const&`. For mutation, bit fields are wrapped with a custom reference object.

This style allows for the least amount of changes in client code. Property access simply needs appended parens, eg `style.direction` becomes `style.direction`.

Reviewed By: shergin

Differential Revision: D14999096

fbshipit-source-id: fbf29f7ddab520513d4618f5e70094c4f6330b30
2019-04-23 08:12:35 -07:00
Pavel Rotek 67be81968e Fix smooth scrolling on old devices (SDK >=16) (#24545)
Summary:
React Native Environment Info:
    System:
      OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
      CPU: (4) x64 Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz
      Memory: 1.12 GB / 15.55 GB
      Shell: 4.4.19 - /bin/bash
    Binaries:
      Node: 8.10.0 - /usr/bin/node
      Yarn: 1.13.0 - /usr/local/bin/yarn
      npm: 3.5.2 - /usr/bin/npm
    SDKs:
      Android SDK:
        API Levels: 16, 19, 22, 23, 24, 25, 26, 27, 28
        Build Tools: 23.0.1, 23.0.3, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.3, 27.0.3, 28.0.2, 28.0.3
        System Images: android-16 | Google APIs Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    npmPackages:
      react: 16.8.6 => 16.8.6
      react-native: git+https://github.com/facebook/react-native.git#v0.59.5 => 0.59.5
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

The workaround implemented in https://github.com/facebook/react-native/pull/21117 tries to fix
https://issuetracker.google.com/issues/112385925 scroll direction (according to the latest comments, the scroll direction problem has been reverted in security patches so not sure if the workaround is still valid).

But... proposed solution in fling method is using signum which leads to zero computedVelocityY in case of zero mOnScrollDispatchHelper.getYFlingVelocity() on old devices(Samsung s4 mini) even when real velocityY is non zero

```
final int correctedVelocityY = (int)(Math.abs(velocityY) * Math.signum(mOnScrollDispatchHelper.getYFlingVelocity()));
```

Proposed solution is to take signum from original velocityY in case of zero
```
float signum = Math.signum(mOnScrollDispatchHelper.getYFlingVelocity());
if (signum == 0) {
  signum = Math.signum(velocityY);
}
final int correctedVelocityY = (int)(Math.abs(velocityY) * signum);
```

The symptoms are the same as described in issue https://github.com/facebook/react-native/issues/22925, but proposed workaround doesn't work.

[Android][fixed] - Fix smooth scrolling on old devices (SDK >=16)
Pull Request resolved: https://github.com/facebook/react-native/pull/24545

Differential Revision: D15044834

Pulled By: cpojer

fbshipit-source-id: 3f523eb1a438df774e22387aecded433b9031ab9
2019-04-23 03:45:17 -07:00
Kudo Chien 040502b5d9 Fix jsc-android not found if building from source (#24547)
Summary:
If an app [builds from RN source](https://facebook.github.io/react-native/docs/building-from-source), there was an error for jsc-android not found.
It is a side effect of my previous [JSC as node dependency change](8e375850de)
For building from RN source case, the jsc-android is located at `/path/to/app/node_modules/jsc-android`.
Original gradle task will try to find it at `/path/to/app/node_modules/react-native/ReactAndroid/../node_modules/jsc-android`, as ReactAndroid project path was being override inside node_modules.
The change fixes the building from source case.

N/A
This change does not need to publish into changelog, as it is a master branch building fix.
Pull Request resolved: https://github.com/facebook/react-native/pull/24547

Differential Revision: D15044703

Pulled By: cpojer

fbshipit-source-id: a7d824b1a14064d46c4a2ec9ea28255179174c83
2019-04-23 02:27:44 -07:00
Dulmandakh ebed815fb5 fix CI instrumentation tests (#24561)
Summary:
It seems that **react_native_dep("android_res/com/facebook/catalyst/appcompat:appcompat")** is no longer used. fixes https://github.com/facebook/react-native/issues/24537

[Android] [Changed] - fix CI instrumentation tests
Pull Request resolved: https://github.com/facebook/react-native/pull/24561

Differential Revision: D15043343

Pulled By: hramos

fbshipit-source-id: 8dd657758e57c6c384850bf2d6c26535e1fdc42b
2019-04-22 23:20:14 -07:00
Will Holen 7442437d07 Remove unnecessary shared library dependency from libreactnativejni
Summary:
libreactnativejni does not need to link against libjsc directly:
that library is only needed by libjscexecutor.

Reviewed By: mhorowitz

Differential Revision: D15017942

fbshipit-source-id: fb545c9127221dab28434321fe9c116fe72f7507
2019-04-22 12:14:35 -07:00
Valentin Shergin af0daaf583 Fabric: Introducing MountingTransaction
Summary:
`MountingTransaction` encapsulates all artifacts of `ShadowTree` commit, particularly list of mutations and meta-data.
We will rely on this heavily in the coming diffs.

Reviewed By: JoshuaGross

Differential Revision: D15021795

fbshipit-source-id: 811da7afd7b929a34a81aa66566193d46bbc34f8
2019-04-20 10:53:16 -07:00
Emily Janzer f81d77c102 Change ViewManager.measure() to use Context instead of ReactContext
Summary: It seems like ReactContext isn't actually needed in measure functions. Changing the signature of ViewManager.measure() to take a Context instead.

Reviewed By: lunaleaps

Differential Revision: D14940330

fbshipit-source-id: b29987fd1d7f9c191a5f26138151082ca61cb351
2019-04-18 10:10:38 -07:00
Estevão Lucas e76a7df5b5 - Add DevSetting native module (making it cross-platform) (#24441)
Summary:
React Native has a `NativeModule` to manipulate programmatically the dev menu options (live reload, hot reload, remote debugging, etc), called [`DevSettings`](https://github.com/facebook/react-native/blob/master/React/Modules/RCTDevSettings.mm#L120). However this module is only available for iOS.

This PR brings the same `DevSettings` for Android, making it a cross-platform NativeModule.

Motivation: Right now if your app needs to programmatically reload RN, one option is to install [`react-native-restart`](https://www.npmjs.com/package/react-native-restart). It's a tiny dependency, but it's annoying to have to install it, while the code to do so is inside RN codebase. According to NPM, react-native-restart has ~12k weekly downloads, shows it's a recurring feature for many apps (my case).

Thus making `NativeModules.DevSettings` is a small increment in the codebase, just exposing the dev menu methods, to improve the Development Experience

[Android] [Added] - Add DevSetting native module (making it cross-platform)

With expection of `setIsShakeToShowDevMenuEnabled`, the following methods will be available for both platforms:
* reload
* setHotLoadingEnabled
* setIsDebuggingRemotely
* setIsShakeToShowDevMenuEnabled
* setLiveReloadEnabled
* setProfilingEnabled
* toggleElementInspector
Pull Request resolved: https://github.com/facebook/react-native/pull/24441

Differential Revision: D14932751

Pulled By: cpojer

fbshipit-source-id: 465e6a89c3beb5fd1ea22e80ea02e9438f596a09
2019-04-17 11:00:17 -07:00
Sam Mathias Weggersen 01bcde3ed8 Keyboard accessibility improvements (#24359)
Summary:
In order to meet our accessibility requirements we need to have full support for keyboard navigation. The Touchable components works with press/tap with a finger, but doesn't respond to 'enter' when using a keyboard. Navigation works fine. This PR adds an onClick listener to touchable views that have the onPress prop defined.

[Android] [Added] - Add View.OnClickListener to Touchable components when onPress is defined
Pull Request resolved: https://github.com/facebook/react-native/pull/24359

Differential Revision: D14971230

Pulled By: cpojer

fbshipit-source-id: ca5559ca1308ee6c338532a00dcea4d00fa57f42
2019-04-17 09:55:24 -07:00
Rick Ratmansky 44fe9904ac Removing more unused libraries from the repo
Summary: This is removing packages and libraries from the repo.  Any modified buck files simply change the redirect targets to something more appropriate (no logic actually changed)

Differential Revision: D14950721

fbshipit-source-id: 6c14f827b76ca1dbaf83dcb983930f362c6a27d4
2019-04-16 11:32:43 -07:00
Valentin Shergin 184cfd5594 Fabric: Bunch of small changes in ContextContainer
Summary:
So, changes:
* Correctness checks only in debug mode (codesize win?);
* `registerInstance` marked as const (because it's thread safe);
* ContextContainer::Shared also enforces constness;
* Using faster better::map;
* Using shared/RW mutex instead of regular one;
* SharedContextContainer got removed.

Reviewed By: sahrens

Differential Revision: D14920284

fbshipit-source-id: f0f8d970e7fae79a1abe3bc32827db9fd2d17e13
2019-04-16 07:35:07 -07:00
David Aurelio cdf3343dd0 Code formatting: allow short inline methods on one line
Summary:
@public

This allows short methods defined in class declarations to occupy a single line.
The change makes class declarations more readable.

Reviewed By: SidharthGuglani

Differential Revision: D14950012

fbshipit-source-id: 1321949475184181c6cceb86613f730e430763e2
2019-04-16 07:14:12 -07:00
Taylor123 faaa92bb04 disable momentum scrolling for horizontal ScrollView (#24045)
Summary:
Would like feedback from the community as this may not be the best solution for all

I would like to restrict (or paginate) the fling of a horizontal ScrollView when `snapToInterval` is set. This is not currently possible with `pagingEnabled`, since the pagination works only when items are the entire width of the ScrollView.

This implementation simply restricts the predicted `targetOffset` found from the `x` velocity and replaces it with the offset when the pan gesture ended.

To get pagination working, I may paginate based on the interval by calculating the offset delta from the beginning of the gesture to current offset and restricting the scrolling behavior to the `snapToInterval`. If this is preferred, I can update this PR or make a new one, but wanted to start a discussion since it seems like there are many in the community that would like this feature  #21302 .

[General] [Added] - add prop `disableIntervalMomentum` to disable the predictive scrolling behavior of horizontal ScrollViews
Pull Request resolved: https://github.com/facebook/react-native/pull/24045

Differential Revision: D14939754

Pulled By: sahrens

fbshipit-source-id: 26be19c47dfb8eed4d7e6035df53a77451e23081
2019-04-15 14:40:44 -07:00
Alston Lin e28b6f314a Fixed bug with Android's CameraRoll module where saveToPhotos crashed devices on a very small subset of devices
Summary:
For a small subset of Android devices, the following line of code caused the device to crash

```
output.transferFrom(input, 0, Long.MAX_VALUE);
```

According to the [Java docs](https://docs.oracle.com/javase/1.5.0/docs/api/java/nio/channels/FileChannel.html), this is what the function does.

> Transfers bytes into this channel's file from the given readable byte channel.
An attempt is made to read up to count bytes from the source channel and write them to this channel's file starting at the given position. An invocation of this method may or may not transfer all of the requested bytes; whether or not it does so depends upon the natures and states of the channels. Fewer than the requested number of bytes will be transferred if the source channel has fewer than count bytes remaining, or if the source channel is non-blocking and has fewer than count bytes immediately available in its input buffer.

Hence, using `Long.MAX_VALUE` seemed to be the standard way to transfer all bytes from one channel to the other.

However, it appeared that for some reason on a subset of old Android devices, the device tries to allocate `count` bytes of memory before transferring the bytes. Obviously, this caused a crash because no device has that much memory. This was fixed transferring bytes using a 1MB buffer.

Differential Revision: D14921778

fbshipit-source-id: 7fa46e10c656e23ae7d5679c72b278188f09ad0a
2019-04-15 12:38:30 -07:00
Estevão Lucas f70e58f355 - remove accessibilityComponentType and accessibilityTraits props (a11y) (#24344)
Summary:
Closes: https://github.com/facebook/react-native/issues/24016

React Native 0.57 introduced cross-platform `accessibilityRole` and `accessibilityStates` props in order to replace `accessibilityComponentType` (for android) and `accessibilityTraits` (for iOS). With #24095 `accessibilityRole` and `accessibilityStates` will increase, receiving more options, which seems to be a good moment to remove deprecated props.

Remove deprecated `accessibilityComponentType` and `accessibilityTraits` props.

[General] [Removed] - Remove accessibilityComponentType and accessibilityTraits props
Pull Request resolved: https://github.com/facebook/react-native/pull/24344

Reviewed By: rickhanlonii

Differential Revision: D14842214

Pulled By: cpojer

fbshipit-source-id: 279945e503d8a23bfee7a49d42f5db490c5f6069
2019-04-15 10:53:50 -07:00
Joshua Gross bbd925cdd1 MountingManager can create views with props in one step instead of two
Summary: Create views with props in one call instead of two. Backwards-compatible.

Reviewed By: shergin

Differential Revision: D14846424

fbshipit-source-id: cb53225579089f7e51d4e9d1fc9fc2e331a994c1
2019-04-15 01:46:04 -07:00
Valentin Shergin 792585fd48 Fabric: ContextContainer was moved to `utils` module
Summary: That allows avoiding circular deps and unnecessary deps on uimanager module.

Reviewed By: PeteTheHeat

Differential Revision: D14917227

fbshipit-source-id: fe7962ee528aa659d8bd23e3e46627722551d995
2019-04-12 15:14:48 -07:00
Kevin Gozali e3d3b2cab9 Fabric Android: added ReactUnimplementedView impl
Summary: Similar to iOS, here we provide the basic impl of unimplemented view.

Reviewed By: mdvacca

Differential Revision: D14895706

fbshipit-source-id: 9053edfb2175b370d9070b6921794dbcafa1f37a
2019-04-11 14:23:13 -07:00
Dulmandakh 9b80560715 fix surface BUCK, and CI (#24404)
Summary:
Fix surface BUCK, and make Android CI green.

[Android] [Changed] - fix surface BUCK, and make CI green.
Pull Request resolved: https://github.com/facebook/react-native/pull/24404

Differential Revision: D14888049

Pulled By: cpojer

fbshipit-source-id: b0e0440c3e22ff8f90f0ff99f9fcb6fed3689725
2019-04-11 04:32:50 -07:00
Mike Diarmid c953e0b431 JSStackTrace -> Ensure lineNumber exists before consuming (#24399)
Summary:
Fixes https://github.com/facebook/react-native/issues/24382

[ANDROID] [INTERNAL] - Fixed a `NoSuchKeyException` when parsing JS stack frames without line numbers.
Pull Request resolved: https://github.com/facebook/react-native/pull/24399

Differential Revision: D14890746

Pulled By: cpojer

fbshipit-source-id: cea3653076484ad624084c370439f8a39c303083
2019-04-11 03:15:28 -07:00
Vojtech Novak 3b1760d1d1 improve dev mode and HMR interop (#24377)
Summary:
Motivation is following - I'm sure many people encountered this because it has been like this for a long time.

1 . you're developing something on android, HMR and dev mode is enabled
2 . you go to dev settings, you disable dev mode because you want to see how something behaves
3 . you reload the app because that's what is required for the change to take effect
4 . you wait for the bundle to be compiled and served, and when that is done, you get an error message about HMR not being a registered callable module - because HMR is not available when `__DEV__ === false` (todo screenshot)

this fixes the described case by checking if HMR is enabled and dev mode disabled when reloading (step 3) and disables HMR in that case.

this also fixes the case when dev mode is disabled and without knowing it, you try to enable HRM (will enable both dev hmr and dev mode).

[Android] [Changed] - improve developer experience around Dev mode and HMR interop
Pull Request resolved: https://github.com/facebook/react-native/pull/24377

Differential Revision: D14890695

Pulled By: cpojer

fbshipit-source-id: 95b6ff4131c6d05a32aadd09a9d5ed11f602122c
2019-04-11 02:41:28 -07:00
David Vacca 261cda92de Temporarly ignore exception when running animations
Summary: Running animations sometimes fail in Android. we are ignoring those failures temporarly

Reviewed By: fkgozali

Differential Revision: D14884510

fbshipit-source-id: 66d6113e12b1bd67e8bcc564943b423825b4cea6
2019-04-10 17:31:32 -07:00
David Vacca ebbc4f6cc4 Adding debug information in Mounting Manager
Summary: This diff adds extra debug information in the mounting manager

Reviewed By: shergin

Differential Revision: D14817456

fbshipit-source-id: 5619c94eb76cdc20f5d7767f1aa4263e63f8d021
2019-04-10 16:18:21 -07:00
David Vacca 40590348ea Recycle only views created by RN
Summary: This diff ensure that only views created by RN are taken into consideration for recycling.

Reviewed By: fkgozali

Differential Revision: D14874678

fbshipit-source-id: ea7dd5a0f29f6acf0dce8573fc77b012395476bd
2019-04-10 14:13:42 -07:00
Dulmandakh f01c4e2a14 add support for native/downloadable fonts (#23865)
Summary:
Android API 26 and Android Support Library 26 added support for font resource type and native/downloadable fonts. It allows apps to easily download fonts from online providers, but also use of various font weights other than normal and bold, like medium. So it deprecated APIs for asset fonts, and should be removed in the future.

Advantages:
- Just copy font files in res/font and use it specifying filename (without extension) in fontFamily
- Define custom font-family using XML file (in res/font) and font files, it may have many weights and styles. See PR for example.
- Define configuration to download fonts from online font providers, and use it.

See https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml and https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts

[Android] [Changed] - add support for custom/downloadable fonts
Pull Request resolved: https://github.com/facebook/react-native/pull/23865

Differential Revision: D14506542

Pulled By: hramos

fbshipit-source-id: 67ba3148fb4b548cdbc779213cf6c1b2c3baffd2
2019-04-10 13:53:25 -07:00
Sebastian McKenzie d338a60cbe Remove copyToClipBoardMiddleware
Summary:
This diff removes the copyToClipBoardMiddleware. This was exposing the /copy-to-clipboard endpoint that allowed unauthenticated access to writing to a developers clipboard.

This was only used in a single place, the Android red box dialog, so I've removed it from there.

Reviewed By: cpojer

Differential Revision: D14790813

fbshipit-source-id: 80e044eefd9658b8c5885643cdadf7947c00d34a
2019-04-10 13:40:01 -07:00
Luna Wei 135ba492fb Detach dependency on RRV for Instance Manager
Summary: Remove dependency on ReactRootView in ReactInstanceManager by creating a rough interface (ReactRoot) so that either a Surface or ReactRootView can be attached to ReactInstanceManager.

Reviewed By: ejanzer, mdvacca

Differential Revision: D14158890

fbshipit-source-id: b7ab4654b1e0ef8343230a3c15023653a7f23a4b
2019-04-10 13:13:16 -07:00
Пётр Потапов a05b409b38 Fix: specific border radius corner causes visual bug on other corners (#24390)
Summary:
Fixes #22511

I understand the motivation of adding extraRadiusForOutline to corner radius: without it there can be an empty space between border and view's background color.

So I add simple check: if corner radius is more than zero we still add extraRadiusForOutline. And if not, we don't add it to prevent all the corners to become slightly curved.

[GENERAL] [Fixed] -  fix of Android's bug that causes all the corners to become slightly curved if only specific corners' radius should be more than zero.
Pull Request resolved: https://github.com/facebook/react-native/pull/24390

Differential Revision: D14870476

Pulled By: cpojer

fbshipit-source-id: df40fc584a2f8badc499413cb3c4e4d96b9e18cf
2019-04-10 06:44:20 -07:00
David Vacca db8e3f7744 Fix Lint warnings
Summary: Trivial reorder on buck dependencies and import in ComponentRegistry.cpp

Reviewed By: shergin

Differential Revision: D14779320

fbshipit-source-id: df4111d4ecfb04d67c7170f0800a745656100fb4
2019-04-09 20:22:40 -07:00
Will Holen 094f221a0c Move JSI source files into a separate directory
Summary: This will simplify updating the JSI API from upstream in the future.

Reviewed By: mhorowitz

Differential Revision: D14762674

fbshipit-source-id: fa4a86f08425943e301da4ef3df9893ebaa1493e
2019-04-09 11:44:32 -07:00
David Aurelio 2d8ad076fe JNI: set language level to C++11
Summary:
@public

compiler flags were pushed to C++14, but we don’t currently have any code that requires it. Setting to `-std=c++11` in order to fix the OSS build.

Reviewed By: SidharthGuglani

Differential Revision: D14833737

fbshipit-source-id: df2cd7da8c7124e89863c90d7b77bcf86c495618
2019-04-09 03:11:47 -07:00
Spencer Ahrens 8ec13c306c Fix tests with JavaOnlyMap
Summary: Need to force the double thing in more places.

Reviewed By: cpojer

Differential Revision: D14835792

fbshipit-source-id: fb7a5435675b322d5fbbe9858e08804e9abe65db
2019-04-08 23:07:35 -07:00
Emily Janzer 8e70e374f6 Export JNativeRunnable from react/jni
Summary: Adding JNativeRunnable to exported headers in react/jni/BUCK so I can use it outside of CatalystInstance.

Reviewed By: axe-fb

Differential Revision: D14817655

fbshipit-source-id: 15aa794e50f273778da337956c887c235a5aec3d
2019-04-08 14:40:34 -07:00
landon e5d975b5c7 ignore dropView method when view is null (#24347)
Summary:
In #20288, we solved `com.facebook.react.uimanager.NativeViewHierarchyManager.dropView (NativeViewHierarchyManager.java:536)` by adding codes that prevent to run method on `view` object when `view.getId()` is null.

But if `view` is null, `view.getId()` can make error about NullPointerException. So, I think `dropView` method  needs to check if `view` is null.

If you need more information, Please read #24346.

[Android] [Fixed] - Ignore dropView method when view is null.
Pull Request resolved: https://github.com/facebook/react-native/pull/24347

Differential Revision: D14833822

Pulled By: cpojer

fbshipit-source-id: 88b6a05090ea8e8d6737c1f10b40e93649fab151
2019-04-08 12:44:48 -07:00
Joshua Gross e34761ff25 Android plumbing for State and LocalData update mount items
Summary: Android plumbing for State and LocalData update mount items. See other commits in stack for usage

Reviewed By: mdvacca

Differential Revision: D14663522

fbshipit-source-id: 5604a6a9af292805e9ce46c68e5ce7472eef0218
2019-04-06 00:52:43 -07:00
Emily Janzer 7944d47a63 Back out "[react-native][PR] Android - Add a ReactFragment"
Summary: Original commit changeset: b50b708cde45

Reviewed By: mdvacca

Differential Revision: D14792438

fbshipit-source-id: c5e0b5f7663fe70110f73ae94a6fa99388f87ae3
2019-04-04 18:43:01 -07:00
Kudo Chien 8e375850de Use node package dependency to manage JSC version (#24276)
Summary:
In origin approach, we packed libjsc.so inside react-native.aar and it is difficult for user to choose different JSC variants. E.g., [the Intl supported version](https://github.com/react-native-community/jsc-android-buildscripts#international-variant).

This change list allows application to determine JSC versions or variants by npm/yarn package.

There is a |useIntlJsc| flag in build.gradle, it will use the same JSC version but with Intl support.

`yarn add jsc-android@canary`

[Android] [Changed] - Allow application to select different JSC variants

**MIGRATION**
Note that there are some changes in build.gradle.
Existing application needs to change their android/build.gradle and android/app/build.gradle.
Hopefully, the rn-diff-purge should handle the case well.
Pull Request resolved: https://github.com/facebook/react-native/pull/24276

Differential Revision: D14752359

Pulled By: cpojer

fbshipit-source-id: a4bfb135ad8e328f404a2d1a062412f40ebf4622
2019-04-04 14:22:14 -07:00
YuTeh Shen 84a1cacfa5 Fix crash if set text and set selection at the same time. (#22723)
Summary:
Since text and selection has dependency, handle text selection in
updateExtraData as well.

The root cause is due to setText is handled on extra data update but setSelection is handled on set property. And extra data update will be handled after all properties are handled. Since selection and text has dependency, move selection to extra data update as well.

Changelog:
----------
[Android] [Fixed] - Fix crash when set text and selection on textinput at the same time
Pull Request resolved: https://github.com/facebook/react-native/pull/22723

Differential Revision: D14783791

Pulled By: cpojer

fbshipit-source-id: a4065f3e151d23f4813d76e91d68362cfd4daaf4
2019-04-04 14:08:37 -07:00
Pieter De Baets d9a82221a4 Back out "[react-native] Remove experimental gating for LayoutAnimation on Android"
Summary: We've identified a couple of remaining issues that need to be re-tested before we can ship this more broadly.

Reviewed By: fred2028

Differential Revision: D14775730

fbshipit-source-id: 22402149066c5fbe72c36fcf7f547d63feaf5241
2019-04-04 09:47:12 -07:00
John Shelley 691f2f9d02 Android - Add a ReactFragment (#12199)
Summary:
React Native on Android has currently been focused and targeted at using an [Activity](https://developer.android.com/reference/android/app/Activity.html) for its main form of instantiation.

While this has probably worked for most companies and developers, you lose some of the modularity of a more cohesive application when working in a "brown-field" project that is currently native. This hurts more companies that are looking to adopt React Native and slowly implement it in a fully native application.

A lot of developers follow Android's guidelines of using Fragments in their projects, even if it is a debated subject in the Android community, and this addition will allow others to embrace React Native more freely. (I even assume it could help with managing navigation state in applications that contain a decent amount of Native code and would be appreciated in those projects. Such as sharing the Toolbar, TabBar, ViewPager, etc in Native Android)

Even with this addition, a developer will still need to host the fragment in an activity, but now that activity can contain native logic like a Drawer, Tabs, ViewPager, etc.

**Test plan (required)**
* We have been using this class at Hudl for over a couple of months and have found it valuable.
* If the community agrees on the addition, I can add documentation to the Android sections to include notes about the potential of this Fragment.
* If the community agrees on the addition, I can update one or more of the examples in the `/Examples` folder and make use of the Fragment, or even create a new example that uses a native layout manager like Drawer, Tabs, Viewpager, etc)

Make sure tests pass on both Travis and Circle CI.

_To Note:_
* There is also talk of using React Native inside Android Fragment's without any legit documentation, this could help remedy some of that with more documentation included in this PR https://facebook.github.io/react-native/releases/0.26/docs/embedded-app-android.html#sharing-a-reactinstance-across-multiple-activities-fragments-in-your-app
* Others have also requested something similar and have a half-baked solution as well http://stackoverflow.com/questions/35221447/react-native-inside-a-fragment

[ANDROID][FEATURE][ReactAndroid/src/main/java/com/facebook/react/ReactFragment.java] - Adds support for Android's Fragment system. This allows for a more hybrid application.
<!--
Help reviewers and the release process by writing your own release notes

**INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

  CATEGORY
[----------]        TYPE
[ CLI      ]   [-------------]      LOCATION
[ DOCS     ]   [ BREAKING    ]   [-------------]
[ GENERAL  ]   [ BUGFIX      ]   [-{Component}-]
[ INTERNAL ]   [ ENHANCEMENT ]   [ {File}      ]
[ IOS      ]   [ FEATURE     ]   [ {Directory} ]   |-----------|
[ ANDROID  ]   [ MINOR       ]   [ {Framework} ] - | {Message} |
[----------]   [-------------]   [-------------]   |-----------|

[CATEGORY] [TYPE] [LOCATION] - MESSAGE

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Pull Request resolved: https://github.com/facebook/react-native/pull/12199

Differential Revision: D14590665

Pulled By: mdvacca

fbshipit-source-id: b50b708cde458f9634e0c14b3952fa32f9d82048
2019-04-04 00:23:28 -07:00
Christoph Nakazawa e62cfc0f72 Fix crash in RCTText in open source RNTester
Summary: See https://github.com/facebook/react-native/issues/24288

Reviewed By: sahrens

Differential Revision: D14765625

fbshipit-source-id: f7275f3735691e1f0c87e682f6dd675e5ba5a7c0
2019-04-03 18:55:36 -07:00
David Vacca da44010b59 Implement AxialGradientView in Fabric Android
Summary: This diff integreates AxialGradientView in Fabric Android

Reviewed By: shergin

Differential Revision: D14631690

fbshipit-source-id: 54785466ab4cd7251c6667c8dc12d69d9d194832
2019-04-03 17:57:24 -07:00
David Vacca 2777c6572a Pre-allocate Fabric views even when React is running in the UI Thread
Summary: Before D14297477, the pre-allocation of views was ONLY necessary when react was running in the JS Thread, this is because the batch of mount items used to contain mount items for creation of views. After D14297477, views are only created during pre-allocation, that means that pre-allocation of views need to be trated the same way independently the thread where it is running.

Reviewed By: shergin

Differential Revision: D14714933

fbshipit-source-id: 7bd19cd33b624a5b0daaafabb476bb06707eea17
2019-04-03 17:31:37 -07:00
Kevin Gozali 1e2e07da2c TM Android: fixed up JSCallInvoker creation
Summary: A previous commit changed the signature of the Instance (the arg to JSCallInvoker) to be a weak ref, so this callsite needs updating.

Reviewed By: mmmulani

Differential Revision: D14757188

fbshipit-source-id: 1a8663e56a42b26c6202881c57a7caafa71da2ab
2019-04-03 13:23:51 -07:00
Aditya Sharat 99ec3dc845 Add YogaNode.cloneWithoutChildren
Summary: Adding flat clone method back to YogaNode for reconciliation.

Reviewed By: davidaurelio

Differential Revision: D14683019

fbshipit-source-id: 08ed2ffbb16052cb11aa464f67a7ba9a64297985
2019-04-03 12:43:05 -07:00
Dulmandakh 6a26cb4bea bump fresco to 1.13 (#24274)
Summary:
Bump Fresco to 1.13, which uses libc++ and many improvements.

[Android] [Changed] - Bump Fresco to 1.13
Pull Request resolved: https://github.com/facebook/react-native/pull/24274

Differential Revision: D14750275

Pulled By: cpojer

fbshipit-source-id: 3c040fccd4cb484e31d9c6e849ec285666f140c7
2019-04-03 10:45:34 -07:00
David Aurelio b015b99fce Move `YGSetUsedCachedEntries` to internal header
Summary:
@public

In order to get out of pre-releases again, we move `YGSetUsedCachedEntries` from `Yoga.h` to `Yoga-internal.h`.
This way, it’s obvious that the function is not public, and we can remove it from future versions without breaking semver contracts.

Reviewed By: SidharthGuglani

Differential Revision: D14726029

fbshipit-source-id: 8d7e747e843bf5c4b5e1d4cfbfa37ca9d240dffb
2019-04-03 08:45:39 -07:00
Nurzhan Bakibayev f00d1b8518 Change default Inspector Proxy port to 8081
Summary: Change default Inspector Proxy port to 8081

Reviewed By: cwdick

Differential Revision: D14745974

fbshipit-source-id: f4b3b158f55c6f5f1b3d9cc2528c5ddb59774a8b
2019-04-03 08:39:08 -07:00
Rick Ratmansky 7f6ab5068c Removing unused and very old versions of the support library resources
Summary: TSIA

Differential Revision: D14727969

fbshipit-source-id: 1c73534dea7225f2d952ef0f20ea602894d78f04
2019-04-03 07:58:40 -07:00
Pieter De Baets 9895d01137 Remove experimental gating for LayoutAnimation on Android
Reviewed By: sahrens

Differential Revision: D14658087

fbshipit-source-id: 378ef4a5c5336d428b5045772d094a297b2767c7
2019-04-03 04:42:15 -07:00
Pieter De Baets f571c62ddf Implement completion callback for LayoutAnimation on Android
Summary: All animations are scheduled by the UIManager while it processes a batch of changes, so we can just wait to see what the longest animation is and cancel+reschedule the callback.

Reviewed By: mdvacca

Differential Revision: D14656733

fbshipit-source-id: 4cbbb7e741219cd43f511f2ce750c53c30e2b2ca
2019-04-03 04:42:14 -07:00
Pieter De Baets a333c2b202 Remove legacy AnimationManagerModule
Summary: This code was shipped as part of the initial open-source release but was never used.

Reviewed By: sahrens

Differential Revision: D14649389

fbshipit-source-id: 0c068ca69b91d275008f4a7af77a23a4f1470c18
2019-04-03 04:42:14 -07:00
Luna Wei d9711e2693 Log uri for guessContentTypeFromName exceptions
Summary: Add additional logging around the exception to figure out what kind of uris are causing the exception for `getContentTypeForFileName`

Reviewed By: PeteTheHeat

Differential Revision: D14715917

fbshipit-source-id: 46299d2ff3f1f06991d7800784a025a85815ae8c
2019-04-02 18:38:39 -07:00
Emily Janzer 15b2f994ce Guard against content view being null in onOverScrolled
Summary:
It seems that the content view can sometimes be null when onOverScrolled is called (presumably when the scrollview gets unmounted while it's in the middle of scrolling?).

Changelog: [Android][fixed] - Guard against content view being null in onOverScrolled.

Reviewed By: mdvacca

Differential Revision: D14737534

fbshipit-source-id: e88ec6f585e50517b734a8809fc3843c0b22df10
2019-04-02 18:15:42 -07:00
Christoph Nakazawa 1ca9a95537 Move WebView Android files to FB internal
Summary: This moves the Java files to FB internal and updates all the buck files

Reviewed By: TheSavior

Differential Revision: D14622521

fbshipit-source-id: a8d293e9f9e08868cca3ed2986a08d0db16dec15
2019-04-02 11:19:47 -07:00
Sunny Luo 556aa93ed7 Prevent crash when setting underlineColorAndroid (#24183)
Summary:
Try to prevent the crash described in https://github.com/facebook/react-native/issues/17530

There seems to be a bug in `Drawable.mutate()` in some devices/android os versions even after you check the constant state. This error is hard to reproduce and to fix, so just try to catch the exception to prevent crash.

[Android][Fixed] Prevent random crash when setting underlineColorAndroid
Pull Request resolved: https://github.com/facebook/react-native/pull/24183

Differential Revision: D14710484

Pulled By: cpojer

fbshipit-source-id: 3af20a5cb0ecd40839beaf85118c0f5aa6905414
2019-04-02 09:41:16 -07:00
Adam Comella a2285b1790 Android: Enable views to be nested within <Text> (#23195)
Summary:
Potential breaking change: The signature of ReactShadowNode's onBeforeLayout method was changed
  - Before: public void onBeforeLayout()
  - After:  public void onBeforeLayout(NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer)

Implements same feature as this iOS PR: https://github.com/facebook/react-native/pull/7304

Previously, only Text and Image could be nested within Text. Now, any view can be nested within Text. One restriction of this feature is that developers must give inline views a width and a height via the style prop.

Previously, inline Images were supported via FrescoBasedReactTextInlineImageSpan. To get support for nesting views within Text, we create one special kind of span per inline view. This span is called TextInlineViewPlaceholderSpan. It is the same size as the inline view. Its job is just to occupy space -- it doesn't render any visual. After the text is rendered, we query the Android Layout object associated with the TextView to find out where it has positioned each TextInlineViewPlaceholderSpan. We then position the views to be at those locations.

One tricky aspect of the implementation is that the Text component needs to be able to render native children (the inline views) but the Android TextView cannot have children. This is solved by having the native parent of the ReactTextView also host the inline views. Implementation-wise, this was accomplished by extending the NativeViewHierarchyOptimizer to handle this case. The optimizer now handles these cases:
  - Node is not in the native tree. An ancestor must host its children.
  - Node is in the native tree and it can host its own children.
  - (new) Node is in the native tree but it cannot host its own children. An ancestor must host both this node and its children.

I added the `onInlineViewLayout` event which is useful for writing tests for verifying that the inline views are positioned properly.

Limitation: Clipping
----------

If Text's height/width is small such that an inline view doesn't completely fit, the inline view may still be fully visible due to hoisting (the inline view isn't actually parented to the Text which has the limited size. It is parented to an ancestor which may have a different clipping rectangle.). Prior to this change, layout-only views had a similar limitation.
Pull Request resolved: https://github.com/facebook/react-native/pull/23195

Differential Revision: D14014668

Pulled By: shergin

fbshipit-source-id: d46130f3d19cc83ac7ddf423adcc9e23988245d3
2019-04-01 19:55:23 -07:00
Héctor Ramos 2a80a42d40 Revert D14423742: Use of TraceCompat
Summary:
D14423742 introduced a regression on OSS test_android due to androidx.core.os not being available. I spent some time investigating a fix forward this morning, with no success. Reverting.

Changelog:

[Android] [Changed] - Revert 92f019c666

Reviewed By: cpojer

Differential Revision: D14668728

fbshipit-source-id: c7542992805551dc4302626e1536759794efaa82
2019-04-01 13:09:07 -07:00
Gábor Siffel 9ddef77b1d Add the ability to customize webview response to client cert requests
Summary:
Add the ability to set a custom handler on ReactWebViewManager to handle client certificate challenges during TLS authentication.

[Android][Added] - Public method setCustomClientCertRequestHandler to the native com.facebook.react.views.webview.ReactWebViewManager, that allows using a custom response for client certificate challenges.

Reviewed By: mjhu

Differential Revision: D14609697

fbshipit-source-id: 567c95458af638d1f8233fc3ca0d9cefc061c2bf
2019-04-01 11:16:54 -07:00
Valentin Shergin 3e4a8e35fe Fabric `ShadowTree` (and co) was moved to `mounting` module
Summary: Because it's kinda more logical and we will rely on this in comming diffs.

Reviewed By: mdvacca

Differential Revision: D14587124

fbshipit-source-id: 94ae9410b4ffeffd0fcb4da4a0518f0bb0d2ba63
2019-04-01 10:50:50 -07:00
Sidharth Guglani 11e93cdc1f added flag for useBatchingForLayoutOutputs experiment
Summary:
Using a config flag to switch between different implementations of transferring layout outputs
- YogaNodeJNI uses multiple access of java fields to pass all properties like width, height, margin etc...
- YogaNodeJNIBatching uses a float array to pass all the data in one java field access

Reviewed By: davidaurelio

Differential Revision: D14378301

fbshipit-source-id: 0da5b28e6a67ad8fd60eb7efe622d9b2deaf177f
2019-04-01 06:16:36 -07:00
Sidharth Guglani 9bbca7c531 Added implementation for YogaNodeJNIBatching and logic for passing array from c++ to java
Summary: This diff adds the logic to transfer layout outputs using a float array

Reviewed By: davidaurelio

Differential Revision: D14368120

fbshipit-source-id: d1f22283bcea051d15657f42c15b90edaa0a8a7a
2019-04-01 06:16:36 -07:00
Sidharth Guglani 5ad752079c added test for reset method in YogaNodeJNI to verify all layout outputs are reset properly
Summary: This diff adds a test for reset method in YogaNodeJNI to verify all layout outputs are reset properly

Reviewed By: davidaurelio

Differential Revision: D14643926

fbshipit-source-id: fffbcd07ccb6d2df83fc0bf187d992ef194f3bd0
2019-04-01 06:16:36 -07:00
Sidharth Guglani c378be490f moved all the properties used for layout outputs to YogaNodeJNI
Summary:
Moved layout outputs transfer logic from YogaNodeJNIBase to YogaNodeJNI.
This change set is for adding experiment for layout outputs batching using a float array

Reviewed By: davidaurelio

Differential Revision: D14642995

fbshipit-source-id: 5d0bc7fa18c1985be7e216d7351f5eab2e03861d
2019-04-01 06:16:35 -07:00
Ram N 0b62ff0b94 Move Android code for Geolocation out
Reviewed By: cpojer

Differential Revision: D14692916

fbshipit-source-id: 6bcfda8aa8c7d22dce36828dae9f57068815ce20
2019-03-31 22:52:36 -07:00
David Vacca 02562e51bd Disable view pooling
Summary:
Temporarily disable View Pooling in Fabric

Naming of classes will change in the near future

Reviewed By: JoshuaGross

Differential Revision: D14685009

fbshipit-source-id: 83573dd09af0202a67d0d0aa11e37c1660c3991f
2019-03-30 23:20:26 -07:00
Christoph Nakazawa 8b895ca710 Back out "[react-native][PR][Microsoft] This change fixes currently broken ReactContext listeners mechanism."
Summary: Original commit changeset: d506e5035a7f

Reviewed By: JoshuaGross

Differential Revision: D14689559

fbshipit-source-id: 9a8c8be0d2b7b9dd9be1ec038d7c3b356a5e3adf
2019-03-29 14:51:57 -07:00
Christoph Nakazawa d2981af68f Back out "[react-native][PR] There is a small gap in the SynchronizedWeakHashSet implementation. T?"
Summary: Original commit changeset: 2998bffb06e2

Reviewed By: JoshuaGross

Differential Revision: D14689422

fbshipit-source-id: 2638bed8005859cc95972ba5f78a9e9cace878ef
2019-03-29 14:51:57 -07:00
Kevin Gozali a47746b851 TM Android: temporarily disable callback support to unbreak build
Summary: With the recent change, JSCallInvoker now expects `Instance` to be passed in, not just the `MessageQueueThread`. There needs to be more plumbing to get the instance of `Instance` from the Java side, but this commit is just to unbreak the build temporarily.

Reviewed By: JoshuaGross

Differential Revision: D14687622

fbshipit-source-id: 42e0173ee8336fc5660fe8188a1e1f8517611521
2019-03-29 12:33:33 -07:00
David Vacca 5d0d50cc44 Fix scrolling of Android Horizontal Scroll View
Summary:
This diff fixes the scrolling of Android Horizontal Scroll View, the root cause was that Binding was mounting a ScrollView instead of an AndroidHorizontalScrollView component.
This will be automatically fixed when all the View components are autogenerated.

Reviewed By: shergin

Differential Revision: D14594622

fbshipit-source-id: 7c477ca167188ea9c473f61145461d3cf1696e17
2019-03-29 00:43:32 -07:00
David Vacca ed0085ca1b Refactor mapping of FabricComponentNames
Summary: Simple diff that refactors the usage of the sComponentNames to not require components to be part of the mapping when the name in JS is the same as the name in Native side.

Reviewed By: shergin

Differential Revision: D14594659

fbshipit-source-id: d1948b27e04686fefbf9b6e2b06d4f9317b97062
2019-03-29 00:43:31 -07:00
David Vacca 0c17992485 Add logs in mounting layer
Summary: Adds debug logging in FabricUIManager and the mounting layer of Fabric.

Reviewed By: shergin

Differential Revision: D14594521

fbshipit-source-id: a5c0ee39e1bac8a340849ca3e044694cbee5427e
2019-03-29 00:43:31 -07:00
David Vacca 58c16e63a4 Expose collapsable as React Prop in LayoutShadowNode
Summary: This diff exposes the collapsable prop as part of LayoutShadowNode, fixing the bug of the collapsable prop being filtered by JS in Fabric

Reviewed By: shergin

Differential Revision: D14594522

fbshipit-source-id: a892ba8228e76f11232acc6fe5c8d75e991d8fc6
2019-03-29 00:43:31 -07:00
Christoph Nakazawa 6345fcf12b Remove WebView from public RN interface
Summary:
This diff removes the `WebView` export from React Native. Internally, we are requiring `WebView` directly now and externally people will have to use the community maintained module. This diff does not yet move the WebView files from the repo, this will happen in a follow-up.

Note that I had to remove a test for Cookies that displayed data in a WebView. I don't think there is an easy way to retain this (debugging) information that likely very few people ever take a look at so I think it is fine.

Reviewed By: TheSavior

Differential Revision: D14613077

fbshipit-source-id: b1d412f970d09d7d70ecac2c23e62cfdd09d7c8e
2019-03-28 17:37:05 -07:00
Gábor Siffel 81fcaa151d Add the ability to customize the http client in networking native module
Summary:
Add the ability to build on top of the OkHttpClient.Builder by defining a lambda that gets called on network requests

[Android][Added] - Public method `setCustomClientBuilder` to the native `com.facebook.react.modules.network.NetworkingModule`, that allows customizing the OkHttpClient per-request for greater control over HTTP requests.

Reviewed By: hramos

Differential Revision: D14288613

fbshipit-source-id: 34df0ff3e18eeea1d565ccfcf97408379900120b
2019-03-27 21:50:56 -07:00
Ioannis Kokkinidis f149426c83 Enforced thread safety on UIImplementation methods that mutate the shadowNodeRegistry (#20025)
Summary:
Fixes: #17178

[ANDROID] [Fixes] - UIImplementation: Now enforcing atomic mutation of the shadowNodeRegistry
Pull Request resolved: https://github.com/facebook/react-native/pull/20025

Differential Revision: D14652876

Pulled By: shergin

fbshipit-source-id: 7b20bad4cb43d3e6f09e2037e3c60a217a91d273
2019-03-27 14:43:12 -07:00