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

3567 Коммитов

Автор SHA1 Сообщение Дата
Kevin Gozali c1b0f398e6 TM iOS: move jscallinvoker under ReactCommon podspec
Summary:
This essentially changes the header namespace to `<ReactCommon/`
Relevant efforts:
https://github.com/facebook/react-native/pull/25619
https://github.com/facebook/react-native/pull/25393

Reviewed By: PeteTheHeat

Differential Revision: D16233125

fbshipit-source-id: 83eda4cc50ebb01efd1ce3eb18f47c97a049cffa
2019-07-12 22:44:20 -07:00
Kevin Gozali 6e7ce9c082 TM iOS: refactor header dir for TM
Summary:
For better cocoapods compatibility, refactored TM podspec to be a subspec of ReactCommon, then use `<ReactCommon/` header prefix for all TM files.

Relevant efforts:
https://github.com/facebook/react-native/pull/25619
https://github.com/facebook/react-native/pull/25393

Reviewed By: hramos

Differential Revision: D16231697

fbshipit-source-id: 38d3418b19978ff54aa0c61b064ac45ac0e1c36c
2019-07-12 22:44:20 -07:00
David Vacca 1914d9a4c0 Use AndroidX GuardedBy annotation in favor of Javax GuardedBy annotation
Summary: Use AndroidX GuardedBy annotation in favor of Javax GuardedBy annotation

Reviewed By: ejanzer

Differential Revision: D16234167

fbshipit-source-id: 7f818d20b332a866926f80275b4c8a7489d4c6d3
2019-07-12 18:51:39 -07:00
Dan Gilbert daa6b0a1fe Update types for autoComplete prop. (#25549)
Summary:
I believe there's a mismatch between the type definitions and the expected prop in Android for `TextInput`'s `autoComplete` prop.

* Android is expecting `autoComplete`.
* JS types are expecting `autoCompleteType`.
* Latest documentation documents `autoCompleteType`.

Prop added here: 179d490607

This change updates the JS types to match what Android is expecting (`autoComplete`). Can update documentation if this is the approach we'd prefer (rather than updating Android to expect `autoCompleteType`).

## Changelog

[Javascript] [Fixed] - Update types for `TextInput`'s `autoComplete` prop.
Pull Request resolved: https://github.com/facebook/react-native/pull/25549

Test Plan:
Before:

* Pass invalid value to `TextInput`'s `autoComplete` prop, see no type errors on JS side, and Android blows up with:

```sh
Invalid autocomplete option: foobar
updateViewProp
    ViewManagersPropertyCache.java:95
setProperty
    ViewManagerPropertyUpdater.java:132
updateProps
    ViewManagerPropertyUpdater.java:51
updateProperties
    ViewManager.java:37
```

After:

* Pass invalid value to `TextInput`'s `autoComplete` prop, see PropType warning for `autoComplete` prop.

Differential Revision: D16220809

Pulled By: mdvacca

fbshipit-source-id: e25e198cbcbe721c8d71f069bba293856bf5f36d
2019-07-12 10:37:57 -07:00
David Aurelio 9374b23b33 More generous access to `DestructorThread.Destructor`
Summary:
In order to extend / use  `DestructorThread.Destructor` outside of `com.facebook.jni`, we need access modifiers to be less strict:

- `Destructor#Destructor()`: package protected -> public
- `Destructor#destruct()`: package protected -> protected

This will enable Yoga to move from finalizers to `DestructorThread.Destructor` without having to buy into `HybridData` completely.

Reviewed By: cjhopman

Differential Revision: D16182362

fbshipit-source-id: ad616c403df8e7c1e3d751131cfb7a9cfe62cf24
2019-07-12 02:01:29 -07:00
Ram N 6c362a7b19 Enabling Sampling Profiler for all apps via Dev Menu
Reviewed By: makovkastar

Differential Revision: D16141959

fbshipit-source-id: 3a9964961a6af4bc7d4650526031db564ec2dd27
2019-07-11 23:32:25 -07:00
David Vacca aa5edca0e2 Migrate Nullable and NonNull annotations to AndroidX
Summary:
This diff migrates the usages Nullable and NonNull annotations to AndroidX instead of javax.

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

Reviewed By: makovkastar

Differential Revision: D16054504

fbshipit-source-id: 21d888854da088d2a14615a90d4dc058e5286b91
2019-07-11 16:23:29 -07:00
Oleksandr Melnykov aa2c682a86 Fix IllegalStateException in TextView.onEditorAction()
Summary:
This diff fixes a crash caused by an IllegalStateException thrown from the `TextView.onEditorAction()`. This could happen if we don't return false from the `OnEditorActionListener.onEditorAction()` and Android will fallback to the default behaviour, which will try to search and focus the next/previous view in case of `EditorInfo.IME_ACTION_NEXT` or `EditorInfo.IME_ACTION_PREVIOUS` accordingly. Because ReactEditText prevents requesting focus from Android (`ReactEditText.requestFocus()` returns false), the following piece of code from `TextView.onEditorAction()` will crash the app:

```
} else if (actionCode == EditorInfo.IME_ACTION_PREVIOUS) {
    View v = focusSearch(FOCUS_BACKWARD);
    if (v != null) {
        if (!v.requestFocus(FOCUS_BACKWARD)) {
            throw new IllegalStateException("focus search returned a view "
                    + "that wasn't able to take focus!");
        }
    }
    return;

} else if (actionCode == EditorInfo.IME_ACTION_DONE) {
    InputMethodManager imm = InputMethodManager.peekInstance();
    if (imm != null && imm.isActive(this)) {
        imm.hideSoftInputFromWindow(getWindowToken(), 0);
    }
    return;
}
```

To prevent this we have to catch `EditorInfo.IME_ACTION_NEXT` and `EditorInfo.IME_ACTION_PREVIOUS` inside `OnEditorActionListener.onEditorAction()` and prevent the default Android behaviour.

Reviewed By: mdvacca

Differential Revision: D16180306

fbshipit-source-id: 6118257c16a7a4a205ae05da671cd76d3a18d565
2019-07-11 03:51:39 -07:00
David Vacca fdd8debee0 Deprecate method UIManagerModule.viewIsDescendantOf
Summary:
We are deprecating the method UIManagerModule.viewIsDescendantOf as this is not going to be part of Fabric.

For more context: 9ae7f0c7da (commitcomment-34177828)

Reviewed By: fkgozali

Differential Revision: D16186404

fbshipit-source-id: 146600c2da20a7a39c50538741d5822838947f3c
2019-07-10 20:56:39 -07:00
David Vacca c242fac096 Back out "[RN][Android] Remove viewIsDescendantOf from Android code"
Summary:
Adding viewIsDescendantOf back, more context 9ae7f0c7da
This method might no not be implemented in Fabric

Reviewed By: ejanzer

Differential Revision: D16186407

fbshipit-source-id: bd7a3f46ac8fbe19ba270b2fbf5c324c9400b740
2019-07-10 20:56:38 -07:00
Oleksandr Melnykov 8e4b2e7448 Use try-with-resource to prevent output stream to be leaked in BlobProvider
Summary: This diff fixes a potential memory leak which can occur if an exception is thrown inside the try block and `outputStream.close()` is not called. By wrapping `outputStream.write(data)` inside try-with-resource we guarantee that outputStream will be closed regardless of whether the try statement completes normally or abruptly.

Reviewed By: sammy-SC

Differential Revision: D16148850

fbshipit-source-id: c5c0a78b36375857f6e717bb581e8686a4a94bb9
2019-07-10 02:34:52 -07:00
Oleksandr Melnykov 88e18b6c8d Release underlying resources when JS instance is GC'ed on Android
Summary:
[Android] [Added] - Release underlying resources when JS instance is GC'ed on Android

D15826082 was reverted because it introduced a crash in Ads Manager for Android (see P67222724).

This diff fixes the crash and re-applies D15826082. The problem was that `jni::findClassStatic` in the destructor of BlobCollector.cpp couldn't find the Java class `com/facebook/react/modules/blob/BlobModule` and crashed the app.

JNI didn't seem to have access to the Java class loader probably because the destructor was called from a non-Java thread (https://our.intern.facebook.com/intern/wiki/Fbjni/environment-and-thread-management/?vitals_event=wiki_click_navigation_link#threads). The fix is to wrap the code in the destructor inside `ThreadScope::WithClassLoader `, which will allow to run code that has full access to Java as though you were running in a Java thread.

Reviewed By: shergin

Differential Revision: D16122059

fbshipit-source-id: 12f14fa4a58218242a482c2c3e2149bb6770e8ec
2019-07-09 02:20:55 -07:00
Moti Zilberman 1a2937151b Make writable arrays and maps only shallowly writable
Summary:
@public

The `WritableArray` and `WritableMap` interfaces currently require that nested arrays and maps also be writable. Nothing in our code actually relies on this, so we can relax this restriction and get useful properties.

For instance, it is now possible to construct a `JavaOnlyMap` (or array) that reuses `ReadableMap` and `ReadableArray` values by reference ( = structural sharing) instead of forcing a deep copy.

Reviewed By: kathryngray

Differential Revision: D16132580

fbshipit-source-id: 9f41189ebea2a82e775a7a4da8c357a5ce9c5b9d
2019-07-08 13:25:02 -07:00
Moti Zilberman e0ae655787 Remove JsonWriter, support bridge types in JsonWriterHelper
Summary:
@public

* Removes `JsonWriter`; it's apparently a buggy fork of [`android.util.JsonWriter`](https://developer.android.com/reference/android/util/JsonWriter) which has existed since API level 11. Our version doesn't insert commas before objects or arrays within an array. Instead of fixing it, we can just use the Android one.
* Extends `JsonWriterHelper` to support serialising `ReadableMap`, `ReadableArray` and `Dynamic` values into a `JsonWriter`.

Reviewed By: kathryngray

Differential Revision: D16131713

fbshipit-source-id: d258af42b669f10218cae8b086e7adc3226d16c0
2019-07-08 13:25:01 -07:00
Valentin Shergin 06ce568155 Fabric: Use state in Paragraph component
Summary:
All props to Eric Lewis! cc ericlewis

This revert of revert of land of changes originally published in #24873 (with some slight fixes). The change removes usage of LocalData from the `<Text>` component.

After this change we only have ---one (maybe two)--- three components left using LocalData.

Reviewed By: mdvacca

Differential Revision: D15962376

fbshipit-source-id: 19f41109ce9d71ce30d618a45eb2b547a11f29a2
2019-07-07 22:46:21 -07:00
Valentin Shergin 71f0079809 Fabric: New extendend signature of `ViewManager::updateState()`
Summary: Now, the signature of `updateState` method practically copies the signature of `updateLocalData`. We need that to support all features that `updateLocalData` does support now (to migrate from it).

Reviewed By: mdvacca

Differential Revision: D15962377

fbshipit-source-id: 61e0af6c191e0c6a358c5859613e9c512f91d29a
2019-07-07 22:46:20 -07:00
Valentin Shergin 142af1751b Fabric: Unconditional state management in Binding::schedulerDidFinishTransaction
Summary: Originally, moving the mount instruction generation under the `if` was a perf optimization but now, since we converge `LocalData` and `State`, this is no longer possible (because we need to treat State as LocalData in some cases).

Reviewed By: mdvacca

Differential Revision: D15962378

fbshipit-source-id: 37f9fadb72ac53450c2d499452610d9835f2964d
2019-07-07 22:46:20 -07:00
Ram N 8e3ccaadf2 Re-add Start/Stop Sampling profiler in Dev Menu for Android
Reviewed By: yinghuitan

Differential Revision: D16069122

fbshipit-source-id: 179ba7ec709731f4b861dc4367df357e93e025f2
2019-07-06 11:23:58 -07:00
Mehdi Mulani 3468af54ce Android support for changing bundle location
Summary: With this, you can load the bundle from another server on the fly. This makes it much easier to hit a named server.

Reviewed By: makovkastar

Differential Revision: D16076020

fbshipit-source-id: 46d78ccd55b9b11481628f4585030494f9282003
2019-07-05 08:44:25 -07:00
Oleksandr Melnykov 24b2a66145 Use HYPHENATION_FREQUENCY_NONE instead of HYPHENATION_FREQUENCY_NORMAL to measure text
Summary:
[Android] [Fixed] - Use HYPHENATION_FREQUENCY_NONE instead of HYPHENATION_FREQUENCY_NORMAL to measure text

The text must be measured with HYPHENATION_FREQUENCY_NONE instead of HYPHENATION_FREQUENCY_NORMAL, since ReactTextView has hyphenation frequency set to HYPHENATION_FREQUENCY_NONE. These two values must match, otherwise the measured height of text we return from the Yoga measure function might be wrong.

Even though the TextView [documentation](https://developer.android.com/reference/android/widget/TextView#setHyphenationFrequency(int)) says that the default hyphenation frequency is HYPHENATION_FREQUENCY_NORMAL before Android Q, it's not true for TextViews instantiated in code (the default value is set from the theme which is missing in case of ReactTextView).

See the screenshots below where the text is measured incorrectly which causes the last line to be cut off.

I extracted the value to a class member variable because I'm planning to expose the hyphenationFrequency prop for the Text component so that it can be configured on Android (as requested by this Github issue: https://github.com/facebook/react-native/issues/17199).

Reviewed By: shergin

Differential Revision: D16109430

fbshipit-source-id: 278c8182c0f819be27bc1d2468559b9e9ae1f807
2019-07-04 03:10:24 -07:00
Michał Osadnik b7782fb57c Add codegen to AndroidDrawer
Summary:
Using Ricky's last changes I managed to subscribe for both new and old event name.

Fixed event to proper one for codegen in native code.

Reviewed By: TheSavior

Differential Revision: D16065660

fbshipit-source-id: b5d3762d673a34bbdf5a8e60ff4d51617c8adb81
2019-07-03 02:29:47 -07:00
Ramanpreet Nara d4e0f98a5e Protect getLegacyCxxModule from being stripped
Summary: We should annotate `ReactPackageTurboModuleManagerDelegate.getLegacyCxxModule` with `DoNotStrip`, so that ProGuard doesn't strip the method. `ReactPackageTurboModuleManagerDelegate.getModule` doesn't need the annotation because it's used in `TurboModuleManager`.

Reviewed By: fkgozali

Differential Revision: D16097376

fbshipit-source-id: 4b2622e8541fed0ab8fe13b5d0f5d25b58ea39ef
2019-07-02 15:03:14 -07:00
David Vacca 7c3f3e3146 Prevent execution of MountItems without mounting instructions
Summary: This diff prevents the execution of MountItems without mounting instructions

Reviewed By: JoshuaGross

Differential Revision: D16063571

fbshipit-source-id: 97ff93c6880c7d8857f61d4998df4327f41fafdd
2019-07-02 14:47:22 -07:00
David Vacca b1b6501ac9 NIT: rename FabricUIManager.scheduleMountItems -> FabricUIManager.scheduleMountItem
Summary: The method FabricUIManager.scheduleMountItems receives only one MountItem, is makes more sense to be called FabricUIManager.scheduleMountItem

Reviewed By: JoshuaGross, makovkastar

Differential Revision: D16062749

fbshipit-source-id: a27063be33b644af83ede6a9198edbfb1c3296e1
2019-07-02 14:47:22 -07:00
David Vacca a679f592cd Remove warnings in some RN Android classes
Summary: I've been analyzing some issue in RN Android code and I noticed some warnings to clean up

Reviewed By: ejanzer

Differential Revision: D16060522

fbshipit-source-id: 327fa86c24c7dd67ac2376bbd2f0ca4339f106d1
2019-07-02 14:47:21 -07:00
David Vacca d07ab35bfb Expose LayoutDirection to Fabric android
Summary: This diff exposes LayoutDirection as part of UpdateLayoutMountItem

Reviewed By: JoshuaGross

Differential Revision: D16060521

fbshipit-source-id: 163bf2a0bdca62dcecb03a8aaa2f4bf595b18c8f
2019-07-02 14:47:21 -07:00
David Vacca 6eec39313d Deprecate receiveCommand method for INT commands
Summary:
This diff deprecates:

```
  public void receiveCommand(int reactTag, int commandId, Nullable ReadableArray commandArgs) {

```
in favor of:

```
  public void receiveCommand(int reactTag, String commandId, Nullable ReadableArray commandArgs) {
```

Reviewed By: JoshuaGross, TheSavior

Differential Revision: D16019254

fbshipit-source-id: 61efefe5d5c43f9b24b729f17229725b87b60a1f
2019-07-02 14:47:20 -07:00
David Vacca 9c20f8ae4d NIT: Cleanup warnings in RN Android
Summary: Easy diff that removes warnings in RN Android code related to JSResponder

Reviewed By: sahrens

Differential Revision: D16019255

fbshipit-source-id: dca8836be848feedbe19ce8a8356ea73ca5b7681
2019-07-02 14:47:20 -07:00
David Vacca 57d1f8ae15 Update Modal State when there is a change on the size of the screen
Summary:
This diff adds support to Update Modal State when there is a change on the size of the screen

// TODO

Reviewed By: JoshuaGross

Differential Revision: D16000755

fbshipit-source-id: be87caa6d7f85c3d2778d2707c1e0cd821d6f6c6
2019-07-02 14:47:20 -07:00
David Vacca 59d85fbf0b Back out "[Fabric][Android] Force setConstraints to run in the JS Thread"
Summary: Original commit changeset: 6665a9388a6a

Reviewed By: fkgozali

Differential Revision: D15889338

fbshipit-source-id: 9acb13bc811446aae61bd9c91a9c427aa5bb0296
2019-07-02 14:47:20 -07:00
David Vacca 0e52ab4e1a Add synchronization on Binding.schedulerDidFinishTransaction
Summary: This diff ensures only one thread access the Binding.schedulerDidFinishTransaction method

Reviewed By: shergin

Differential Revision: D15995971

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

Reviewed By: cpojer

Differential Revision: D16090087

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

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

drop-conflicts

Reviewed By: cpojer

Differential Revision: D16071725

fbshipit-source-id: fc6e3852e45742c109f0c5ac4065d64201c74204
2019-07-02 04:16:46 -07:00
Ramanpreet Nara 8cfb08609a Remove TurboModuleManager dependency on ReactApplicationContext
Summary: TurboModuleManager doesn't need access to ReactApplicationContext.

Reviewed By: ejanzer

Differential Revision: D16076581

fbshipit-source-id: 7b825c5a75d352aa6e83ed76c46f1cd70ba92ab2
2019-07-01 14:59:16 -07:00
Ramanpreet Nara 516b058256 Initialize TurboModuleManager before we run JS
Summary:
NativeModuleRegistry is initialized in `ReactInstanceManager.createReactContext` and passed to the CatalystInstanceImpl's constructor. After we create the CatalystInstanceImpl, we then run the JS by calling `CatalystInstance.runJSBundle`. This makes it so that NativeModules are available by the time we run JS code that could require them.

With TurboModules, however, the JS startes executing first, and then we initialize TurboModuleManager. This is bad because by the time JS calls `TurboModuleRegistry.getEnforcing`, TurboModuleManager may yet not be ready. So, `TurboModuleRegistry.get` will just return null for all TurboModules. This will cause TurboModuleRegistry to raise errors. I suspect this is what's causing all RN surfaces to crash with "Unexpected error occurred" in prod builds of the app for users that are in the TurboModules FB4A test. But even if it doesn't fix the error, I think this is a better way to initialize TurboModules.

Reviewed By: ejanzer

Differential Revision: D16064364

fbshipit-source-id: 6053c251ace1668a331110d0cc64aba9d41a4837
2019-07-01 14:59:16 -07:00
Dan Abramov d3f9f88860 Show correct error message on initial load
Summary: This fixes an issue that caused us to show a confusing message on the initial load. I guess at some point the field was renamed. The code falls back to the "generic" message if it can't parse JSON, and in this case, it couldn't find the field called `description` as it's now called `message`.

Reviewed By: cpojer

Differential Revision: D16073931

fbshipit-source-id: a70ae28635b72f674cb1da26f89744b4214f18d9
2019-07-01 10:19:29 -07:00
Guilherme Iscaro ab80001c90 Reset sMatrixDecompositionContext before applying transformations (#25438)
Summary:
Prior to this commit React Native on Android was not properly setting
the transform's scale properly correctly when setting it to 0. In order
to properly set one would need to use values close to 0, like 0.0001.
This was happing due to BaseViewManager sharing sMatrixDecompositionContext
across all views in a React Native app.
In some cases the decomposeMatrix() method from the MatrixMathHelper would
return early and not set any new values in sMatrixDecompositionContext
(this is, the new transform values) and
since this is a shared object the BaseViewManager would set the transform values
from the a previous transform.

In order to prevent this issue, before setting the new transform values
always reset the sMatrixDecompositionContext values.

## Changelog

[Android] [Fixed] - Reset sMatrixDecompositionContext before applying transformations
Pull Request resolved: https://github.com/facebook/react-native/pull/25438

Test Plan:
Run the code below on an Android device/emulator and you should see the following results:

### Android without the patch - current implementation
Notice that the scale 0 is not properly applied to the last rectangle and the second rectangle does not animate properly.

![android-not-working](https://user-images.githubusercontent.com/984610/60400418-d29e0500-9b49-11e9-8006-63d6956d3a44.gif)

### Android with the patch
Everything works fine

![android-working](https://user-images.githubusercontent.com/984610/60400420-d5005f00-9b49-11e9-9025-f11a9ee62414.gif)

### iOS - current implementation
Everything works fine

![ios-working](https://user-images.githubusercontent.com/984610/60400421-d6ca2280-9b49-11e9-9d81-608780c69936.gif)

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

import React from 'react';
import { Animated, Button, StyleSheet, View, Text, SafeAreaView } from 'react-native';

const HorizontalContainer = ({ children, title }) => (
  <View style={styles.horizontalContainer}>
    {children}
    <Text style={styles.text}>{title}</Text>
  </View>
);

const App = () => {
  const animValue1 = React.useRef(new Animated.Value(1)).current;
  const animValue2 = React.useRef(new Animated.Value(1)).current;
  const onStartAnim = React.useCallback(() => {
    animValue1.setValue(0);
    animValue2.setValue(0);
    Animated.sequence([
      Animated.timing(animValue1, {
        toValue: 1,
        duration: 300,
        useNativeDriver: true,
      }),
      Animated.timing(animValue2, {
        toValue: 1,
        delay: 700,
        duration: 300,
        useNativeDriver: true,
      })
  ]).start();
  }, [animValue1, animValue2]);
  return (
    <SafeAreaView style={styles.container}>
      <Button title="Start Animation" onPress={onStartAnim} />
      <HorizontalContainer title="Animated scale from 0 to 1">
        <Animated.View style={[styles.view, { transform: [{ scaleX: animValue1 }] }]} />
      </HorizontalContainer>
      <HorizontalContainer title="Animated scale from 0 to 1 - delayed">
        <Animated.View style={[styles.view, { transform: [{ scaleX: animValue2 }] }]} />
      </HorizontalContainer>
      <HorizontalContainer title="Scale 0.4">
        <View style={[styles.view, { transform: [{ scaleX: 0.4 }] }]} />
      </HorizontalContainer>
      <HorizontalContainer title="Scale 0.2">
        <View style={[styles.view, { transform: [{ scaleX: 0.2 }] }]} />
      </HorizontalContainer>
      <HorizontalContainer title="Scale 0">
        <View style={[styles.view, { transform: [{ scaleX: 0 }, { translateY: 100 }] }]} />
      </HorizontalContainer>
    </SafeAreaView>
  );
};

export default App;

const styles = StyleSheet.create({
  text: {
    fontSize: 10,
    color: 'black',
    marginLeft: 10,
  },
  horizontalContainer: {
    justifyContent: 'center',
    alignItems: 'center',
    flex: 1,
    flexDirection: 'row',
  },
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  view: {
    width: 100,
    height: 100,
    backgroundColor: 'indigo',
    marginVertical: 5,
  }
});
```
Closes https://github.com/facebook/react-native/issues/25205
Closes https://github.com/facebook/react-native/issues/6278
Closes https://github.com/facebook/react-native/issues/6278

Differential Revision: D16071126

Pulled By: cpojer

fbshipit-source-id: 50820229db2e3c22cf6296831413d26b42f57070
2019-07-01 02:34:50 -07:00
Jacob Bower bbf7057a94 Fix incorrect case in build file
Summary: case-sensitive

Reviewed By: dulinriley

Differential Revision: D16053862

fbshipit-source-id: fa96ceef9fc338116c2ef5c55d611d3e7728696e
2019-06-28 12:35:38 -07:00
soh335 76c50c1db1 Fix some languages wrapped texts are cut off on android (#25306)
Summary:
Fix wrapped some languages (like Japanese, Chinese) texts are cut off on android. This p-r is based on linjson [patch](https://github.com/facebook/react-native/issues/25275#issuecomment-502548807).

- related (maybe)
    - https://github.com/facebook/react-native/issues/25297
    - https://github.com/facebook/react-native/issues/25275
    - https://github.com/facebook/react-native/issues/24837
    - https://github.com/facebook/react-native/issues/25155

`setUseLineSpacingFromFallbacks` is recommended to set true on [document](https://developer.android.com/reference/android/text/StaticLayout.Builder#setUseLineSpacingFromFallbacks(boolean))

>For backward compatibility reasons, the default is false, but setting this to true is strongly recommended. It is required to be true if text could be in languages like Burmese or Tibetan where text is typically much taller or deeper than Latin text.

## Changelog

[Android] [Fixed] - Fix some languages wrapped texts are cut off.
Pull Request resolved: https://github.com/facebook/react-native/pull/25306

Test Plan:
Set the target SDK to 28 in ``fbsource/fbandroid/java/com/facebook/catalyst/shell/AndroidManifest.xml``:
```
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28"/>
```

Insert the following code into Playground.js: P67720709

Start the Catalyst Android app and navigate to the playground:

`buck install -r catalyst`

|Before|After|
|{F163482789}|{F163481060}|

Reviewed By: cpojer

Differential Revision: D15985809

Pulled By: makovkastar

fbshipit-source-id: 0f98760b7a7fe4689fa3fe90ca747e9bf9fc4780
2019-06-27 02:32:11 -07:00
David Vacca cc79e971a3 Remove viewIsDescendantOf from Android code
Summary: The metheod viewIsDescendantOf is not used anymore, this diff removes it from Android code

Reviewed By: fkgozali

Differential Revision: D16014664

fbshipit-source-id: e189be38a02cdf5c07ceab13454d52ab842fd0ca
2019-06-26 18:47:13 -07:00
Eli White f7608d553c Support commands as strings in ViewPagerAndroid
Summary:
See 3cae6fa950 for more context

This component isn't exposed from the public API anymore because it has been moved to https://github.com/react-native-community/react-native-viewpager

This change will need to be made there but for FB internal which is still using this native code for now we need this migration

Reviewed By: mdvacca

Differential Revision: D16015151

fbshipit-source-id: 7a1b35e782e4ab4f6c01fa1824cdb9c61718a2db
2019-06-26 16:50:36 -07:00
Eli White ac87b0f6f3 Support commands as strings in ScrollView
Summary: See 3cae6fa950 for more context

Reviewed By: JoshuaGross

Differential Revision: D16011124

fbshipit-source-id: bd402773aafc4682d4d1570cf7dbb295044b0fa7
2019-06-26 14:10:01 -07:00
Eli White faf5c0b5ef Support commands as strings in TextInput
Summary: See 3cae6fa950 for more context

Reviewed By: JoshuaGross

Differential Revision: D16009306

fbshipit-source-id: 8060167a6774ff63ec753393d890f6c1a62e1ccc
2019-06-26 14:10:00 -07:00
Eli White 35570a1b63 Support commands as strings in AndroidDrawerLayout
Summary: See 3cae6fa950 for more context

Reviewed By: JoshuaGross

Differential Revision: D16008549

fbshipit-source-id: a574c203d4481b4cfe84519f846cee858ceda227
2019-06-26 14:10:00 -07:00
aamalric 00c8b3cd09 Prevent scrollView to scroll with dpad when scrollEnabled property is set to false. (#25309)
Summary:
ScrollView doesn't handle the scrollEnabled property using dpad. When set to false, the directionnal pad still allows to scroll in the view.

## Changelog

[ANDROID] [ADDED] - Prevent scrollView to scroll with dpad when scrollEnabled property is set to false.
Pull Request resolved: https://github.com/facebook/react-native/pull/25309

Test Plan:
Add P67680731 to Playground.js and start the Catalyst Android app:

```buck install -r catalyst```

Send the following adb commands to the device/emulator:

```adb shell input keyevent DPAD_RIGHT_LEFT```
```adb shell input keyevent DPAD_RIGHT_RIGHT```

Make sure the ScrollView doesn't scroll to the left and right.

Add ```horizontal={true}``` to ScrollView and send the following adb commands to the device/emulator:

```adb shell input keyevent DPAD_RIGHT_TOP```
```adb shell input keyevent DPAD_RIGHT_BOTTOM```

Make sure the ScrollView doesn't scroll to the top and bottom.

Reviewed By: mdvacca

Differential Revision: D15983785

Pulled By: makovkastar

fbshipit-source-id: 678cc801a168531d71c8651b986c99ecd9da400e
2019-06-26 10:05:33 -07:00
David Vacca 01d0cd540c Fix textDecorationLine in Fabric Android
Summary: This diff fixes ```textDecorationLine: 'line-through'``` in Fabric Android

Reviewed By: JoshuaGross

Differential Revision: D15989149

fbshipit-source-id: 907bb64abb247c3e32a56df7f87538dce1a08826
2019-06-26 10:05:33 -07:00
Ramanpreet Nara 90897a9f62 Prevent getLegacyCxxModule from being stripped
Summary: `ReactPackageTurboModuleManagerDelegate.getLegacyCxxModule` isn't called from Java. Therefore, ProGuard will strip this method to reduce code size. To prevent this, we need to add the `DoNotStrip` annotation to this method. This annotation isn't necessary for the `getModule` method, since `getModule` is used in `TurboModuleManager.getJavaModule`.

Reviewed By: fkgozali

Differential Revision: D15996432

fbshipit-source-id: d34a7d28f7678e2dfc917f52d5cacc286bc33a0a
2019-06-26 10:05:33 -07:00
Ramanpreet Nara bbc6695afc Move TurboModuleManager initialization into createReactContext
Summary:
TurboModuleManager was initialized in `ReactInstanceManager.setupReactContext`, which is executed on the NativeModule thread after we call `ReactInstanceManager.createReactContext` on a new thread. `NativeModuleRegistry` is initialized in `ReactInstanceManager.createReactContext`, so if someone requests a TurboModule after `ReactInstanceManager.createReactContext` is called and before `ReactInstanceManager.setupReactContext` fully finishes executing, that TurboModule won't be found.

This diff moves TurboModuleManager initialization into `ReactInstanceManager.createReactContext`

Reviewed By: fkgozali

Differential Revision: D15978486

fbshipit-source-id: 734e83eced414e545fe275e9a124d0df35204c40
2019-06-26 10:05:31 -07:00
David Vacca beee546779 Reduce visibility of ReactChoreographer.postFrameCallbackOnChoreographer method
Summary: The method ReactChoreographer.postFrameCallbackOnChoreographer should be private and it should be called from a context that contains the lock mCallbackQueuesLock

Reviewed By: JoshuaGross

Differential Revision: D15891758

fbshipit-source-id: fedba0db663aade25dbad1ef7151df1e340e05f6
2019-06-24 19:08:39 -07:00
David Vacca 89bf3d8b38 Allow ReactChoreographer to execute a FrameCallback that removes another FrameCallback from the mCallbackQueues
Summary: This diff extends the ReactChoreographer to allow the execution of FrameCallbacks that removes another FrameCallback from the mCallbackQueues.

Reviewed By: ejanzer

Differential Revision: D15891759

fbshipit-source-id: 62bc2b6afac45c50ac18771b0821742b4f7fc10e
2019-06-24 19:08:39 -07:00
Eli White 3cae6fa950 RN Android: Support View Manager Commands that are strings
Summary:
Right now JS triggers a view manager command with the following code:

```
UIManager.dispatchViewManagerCommand(
  ReactNative.findNodeHandle(this),
  UIManager.getViewManagerConfig('RCTView').Commands.hotspotUpdate,
  [destX || 0, destY || 0],
);
```

As we want to get rid of calls to UIManager, we need to stop looking for the integer defined in native from JavaScript. We will be changing methods like this to be:

```
UIManager.dispatchViewManagerCommand(
  ReactNative.findNodeHandle(this),
  'hotspotUpdate',
  [destX || 0, destY || 0],
);
```

We need to support ints and Strings to be backwards compatible, but ints will be deprecated.

Reviewed By: shergin

Differential Revision: D15955444

fbshipit-source-id: d1c488975ae03404f8f851a7035b58a90ed34163
2019-06-24 18:47:16 -07:00
Dan Abramov a52e6d1dbb Unify "Hot Reloading" and "Reload-on-Save" into "Fast Refresh"
Summary:
We have too many options in the Dev Menu, and they're really hard to pick from. They're also somewhat conflicting. This replaces two menu choices that have a similar purpose (faster iteration cycle) with one.

"Fast Refresh" tries to only update the affected modules, but falls back to doing a full reload if the update can't be handled by the React components.

If for some reason you prefer the "Reload-on-Save" behavior, please:

- Reach out to me so I can learn more about your use case.
- As a workaround, you can add `if (__DEV__) require.Refresh.forceFullRefresh = true` to your app's entry point to always do a full refresh.

Also note that I only removed the user-facing part of "Reload-on-Save". So if you have automation depending on it, that's gonna keep working.

I moved it above Systrace since it's a more generic feature.

As a total aside nit, I renamed "Enable Inspector" and "Disable Inspector" to "Show Inspector" and "Hide Inspector" because... that's what those options do, really.

Reviewed By: rickhanlonii

Differential Revision: D15958697

fbshipit-source-id: 20e856d56f661fe4d39b5ab47d8c44754bf70f67
2019-06-24 13:54:39 -07:00
Dan Abramov 1f04ff580d Make "Enable Hot Reloading" Instant
Summary:
As we saw in D15947985, and later traced down to D5623623, the `hot` option isn't used by Metro anymore. The relevant transforms _always_ run in DEV regardless of the option.

Given that, it doesn't make sense that enabling or disabling Hot Reloading forces a full refresh. This significantly raises the usage barrier because **currently, you might have to wait ~20 seconds (on a large app) to just start using Hot Reloading when you're already in the middle of some screen.** So you just end up not using it.

This diff changes enabling/disabling Hot Reloading to be _instant_.

Here's how it works:

1. Now we always send the necessary info to the client via the new `HMRClient.setup()` function. It creates a Metro HMR client instance, but only actually sets up the socket if Hot Reloading is on.

2. The "Enable Hot Reloading" menu no longer forces a reload. Instead, it calls `HMRClient.enable()` which lazily sets up a socket (at most once).

3. The "Disable Hot Reloading" menu also doesn't trigger a refresh now. Instead, it calls `HMRClient.disable()`. We don't actually tear down the socket here because it's a pain to deal with race conditions and such. Instead, we keep the connection — but we _ignore the updates_ that come in while we're disabled.

4. As a result, it is possible to enable and disable it many times during a single session. (Updates while disabled would be ignored — which has a risk of making your running app inconsistent — but I'd argue it's expected and is worth it. You can always save a particular file to force it to update once the mode is on.)

5. In order to support "ignoring" updates, Metro's `HMRClient` (not to be confused with RN's module) now supports a `shouldApplyUpdates` field. The RN module uses it to disable handling updates when the mode is off.

6. In case there is an error that makes hot reloading unavailable (such as the server disconnecting), we surface the error only if the mode is on. If the mode is off, we stash the error message in the `_hmrUnavailableReason` variable, and display it next time you try to enable Hot Reloading.

Reviewed By: rickhanlonii

Differential Revision: D15958160

fbshipit-source-id: 8256fc4d5c2c3f653a78edf13b8515a5671953e4
2019-06-24 09:48:56 -07:00
Sidharth Guglani 055b28b4f4 pass cachedLayout and cachedMeasure measures to plugin
Summary: Passing whether layout cache or measure cache was used or not

Reviewed By: davidaurelio

Differential Revision: D15920937

fbshipit-source-id: a6728e7af07ea228a285f824fbdfddc8130c5990
2019-06-24 08:35:34 -07:00
Oleksandr Melnykov 79e506d154 Fix typo in JavaDoc for ReactScrollViewManager
Summary: This diff fixes a typo in the JavaDoc for ReactScrollViewManager.

Reviewed By: cpojer

Differential Revision: D15965028

fbshipit-source-id: 3506cdde21c8d00ab916455a2d9fa29772f35359
2019-06-24 07:33:44 -07:00
Nate 8094377d32 Possible fix for #9023: Use View.INVISIBLE instead of View.GONE to hide ActivityIndicator (#25354)
Summary:
On Android, if the ActivityIndicator component is initially set to `animate={false}`, it does not display if later set to `true` (https://github.com/facebook/react-native/issues/9023)

For some reason, the layout width/height of the associated ProgressBar remains 0, despite the parent layout having the correct width/height:

![image](https://user-images.githubusercontent.com/590904/59955251-f8d2ef00-943d-11e9-8019-0977e19186b3.png)

I wasn't able to determine why this is the case, but I did notice that changing the visibility settings from `View.GONE` to `View.INVISIBLE` fixes the issue while not (as far as I can tell) having an impact on the React Native layout:

#### Before:

![before](https://user-images.githubusercontent.com/590904/59955177-a1cd1a00-943d-11e9-80da-876c99b7d5bf.gif)

#### After:

![after](https://user-images.githubusercontent.com/590904/59955183-a7c2fb00-943d-11e9-952b-892bdc23bd48.gif)

Using `View.INVISIBLE` appears to alleviate the issue.

This should fix https://github.com/facebook/react-native/issues/9023

## Changelog

[Android][fixed] - ActivityIndicator appears as expected when `animated={false}` is later set to `true`.
Pull Request resolved: https://github.com/facebook/react-native/pull/25354

Test Plan:
Link this branch to a new React native project with the following App.js class:

```javascript
import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  Button,
  View,
  ActivityIndicator,
  TouchableHighlight
} from "react-native";

export default class App extends Component {
  constructor() {
    super();

    this.state = {
      show: false
    };
  }

  hide = () => {
    this.setState({ show: false });
  };

  show = () => {
    this.setState({ show: true });
  };

  render() {
    return (
      <View>
        <ActivityIndicator
          animating={this.state.show}
          size="large"
          style={styles.indicator}
        />

        <ActivityIndicator
          animating={this.state.show}
          size="small"
          style={styles.indicator}
        />

        <View style={{ flexDirection: "row" }}>
          <Button title="Hide" style={styles.button} onPress={this.hide} />
          <Button title="Show" style={styles.button} onPress={this.show} />
        </View>

        <Text>Showing ? {this.state.show.toString()}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  indicator: {
    borderColor: "red",
    borderWidth: 1
  },
  button: {
    marginRight: 8
  }
});
```

Differential Revision: D15963366

Pulled By: cpojer

fbshipit-source-id: ee3df3fd84acbff342599dc6f4f4a391704876fa
2019-06-24 02:11:08 -07:00
Dulmandakh 0af25a8ea5 bump fresco to 2.0.0, supports AndroidX (#25358)
Summary:
Bump Fresco to 2.0.0, which supports AndroidX. We should cherry-pick to 0.60 release, to support brown field apps but also native components.

## Changelog

[Android] [Changed] - Bump Fresco to 2.0.0, supports AndroidX
Pull Request resolved: https://github.com/facebook/react-native/pull/25358

Test Plan: CI is green, and RNTester builds and runs as expected.

Differential Revision: D15959443

Pulled By: mdvacca

fbshipit-source-id: 58ba2c3e4d1342014d6ea632cd865b4f413548d9
2019-06-22 23:37:10 -07:00
Dulmandakh 3915c0fa61 custom fontWeight numeric values for Text on Android (#25341)
Summary:
I found that on Android we only support 2 fontWeight options, either **normal** or **bold**, even developer can set any numeric value. But iOS supports all possible numeric values. This PR tries to add support for all possible numeric values on Android, even if it's supported only on Android P(28) and above.

This change might break texts where fontWeight use improperly, because this PR removes conversion of values above 500 to BOLD and below 500 to normal.

FYI, also moved **mCustomTypefaceCache** usage up because it was working after unnecessary mFontCache usage.

## Changelog

[Android] [Changed] - add custom font weight support to Text component on Android, only on P(API 28) and above versions.
Pull Request resolved: https://github.com/facebook/react-native/pull/25341

Test Plan: RNTester app's Text examples will show Rubik Regular, Rubik Light, Rubik Bold, Rubik Medium and Rubik Medium Italic texts in corresponding font family, style and weights.

Differential Revision: D15956350

Pulled By: mdvacca

fbshipit-source-id: 61079d953c65fb34ab4497d44c22317912a5a616
2019-06-21 22:58:32 -07:00
Emily Janzer 8af7e9289f Remove @UiThread annotation from MountingManager.addRootView()
Summary: Removing the UiThread annotation from MountingManager.addRootView() because it doesn't seem like it's needed.

Reviewed By: mdvacca

Differential Revision: D15945819

fbshipit-source-id: 0cb9bfb2fe2889001f1c061a07518cf9734f0c16
2019-06-21 16:52:04 -07:00
Eli White 38d974e6a2 Android TextInput now supports strings for autoCapitalize
Summary:
Similar to D15909582, this change makes the Android TextInput take strings for the value of autoCapitalize and not just numbers. As we are going to stop sending view configs from native and instead hardcode them in JS we can't do that anymore.

In this commit we are supporting the old style as well as the new style.

Changelog:
[Android] [Internal] - Supporting autoCapitalize as string to clean up internal TextInput.js file

Reviewed By: mdvacca

Differential Revision: D15911323

fbshipit-source-id: b236fdb314489cc1ef33f9214ff2d6b0e28b7310
2019-06-21 16:10:43 -07:00
Eli White 1d0b397485 DrawerLayoutAndroid now takes strings for drawerPosition
Summary:
Previously DrawerLayoutAndroid required taking an int as the drawerPosition. This required a complex dance of pulling these constant values off of the native view config. As we are going to stop sending view configs from native and instead hardcode them in JS we can't do that anymore.

In this commit we are supporting the old style as well as the new style. The old way of specifying the sizes will go away in a future release.

Changelog:
[Android][Added] - DrawerLayoutAndroid now supports strings and not just numbers for drawerPosition.

Reviewed By: mdvacca

Differential Revision: D15912607

fbshipit-source-id: b444454a1e74f8f659995b9ebe5e164ac9660138
2019-06-21 15:59:31 -07:00
David Vacca 42e35b3b56 Add extra logs in FabricUIManager
Summary: This diff adds extra logging in FabricUIManager, this will be useful to debug production issues

Reviewed By: JoshuaGross

Differential Revision: D15907520

fbshipit-source-id: 94e16444af3c023b6c4837c4797404d3debe8e95
2019-06-21 11:52:56 -07:00
Oleksandr Melnykov a15eecf6bd Back out "[RN][Android] Release underlying resources when JS instance is GC'ed on Android"
Summary:
Since Ads Manager for Android is crashing when a user tries to log in, I'm reverting D15826082 for now. Will investigate the reason of the crash later.

Crashlog: P67222724

Reviewed By: cpojer

Differential Revision: D15939152

fbshipit-source-id: bc1276e6057418821e1ebd90203bea586943b633
2019-06-21 05:28:43 -07:00
Guilherme Iscaro 4b9c99dff0 Protocol property of WebSocket object is undefined (#25273)
Summary:
Prior to this patch the websocket protocol was not being set when a connection
was opened, which could cause client libraries and apps to not work properly.
According to the [whatwg] spec the protocol must be set once the connection is
estabilished.

[whatwg]: https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol

## Changelog

[Javascript] [Fixed] - Properly set the this.protocol on WebSocket open
[Android] [Fixed] - Send the server chosen protocol to the WebSocket object
[iOS] [Fixed] - Send the server chosen protocol to the WebSocket object
Pull Request resolved: https://github.com/facebook/react-native/pull/25273

Test Plan:
In order to reproduce the issue you **need to install wampy@6.2.1**. Since **wampy@6.2.2** and newer contains a workaround for this react-native bug.

https://www.npmjs.com/package/wampy

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

import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import Wampy from "wampy";

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};

export default class App extends Component<Props> {
  state = {conState: 'Initializing...'};
  componentDidMount() {
    const url = "wss://demo.crossbar.io/ws";

    const ws = new Wampy(url, {
      realm: "crossbardemo",
      ws: WebSocket,
      debug: true,
      onConnect: () => {
        console.log("WAMP onConnect");
        this.setState({conState: 'Connected'});
      },
      onClose: () => {
        console.log("WAMP onClose");
        this.setState({conState: 'Connection closed'});
      },
      onError: () => {
        console.log("WAMP onError");
        this.setState({conState: 'Connection Error'});
      }
    });
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.message}>{this.state.conState}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  message: {
    fontSize: 20,
    color: 'black'
  },
});
```

Using the code above one must see the message **WAMP onConnect** on Console and **Connected** in the middle of the screen

Closes https://github.com/facebook/react-native/issues/24796

Differential Revision: D15938870

Pulled By: cpojer

fbshipit-source-id: 10a0a9b40c2a69e484ead37149abc2b1158a4ffc
2019-06-21 03:46:54 -07:00
Sam Mathias Weggersen 73c5a8ec1b Keyboard accessibility follow up (#25274)
Summary:
This is a follow up PR to https://github.com/facebook/react-native/issues/24359. There's a good thread in the mentioned PR for more background for why I'm doing this change. Essentially `focusable` makes more sense since it is about whether a view can receive user-initiated focus from a pointer or keyboard.
Pull Request resolved: https://github.com/facebook/react-native/pull/25274

Differential Revision: D15873739

Pulled By: cpojer

fbshipit-source-id: 0f526bb99ecdc68131dfc10200a5d44c2ef75b33
2019-06-21 03:13:38 -07:00
aamalric d010fc3bf4 Add key action info to Android EventHandler events. (#25300)
Summary:
Add event key action for Android EventHandler events, helps to know if the key event is a up (key release, value is 1) or down (key pressed, value is 0) action.

## Changelog

[ANDROID] [ADDED] - Add event key action to EventHandler events.
Pull Request resolved: https://github.com/facebook/react-native/pull/25300

Test Plan: No test added

Differential Revision: D15897484

Pulled By: cpojer

fbshipit-source-id: fdb3d5413d9da3dd5f46d41e31ac60f0b341f3eb
2019-06-21 03:00:32 -07:00
Eli White 09fe15910e Android SwipeRefreshLayout now supports strings for size
Summary:
Previously SwipeRefreshLayout (RefreshControl on Android) required taking an int as the size. This required a complex dance of pulling these constant values off of the native view config. As we are going to stop sending view configs from native and instead hardcode them in JS we can't do that anymore.

We will change the type of size from:
```
size?: ?(
  | typeof RefreshLayoutConsts.SIZE.DEFAULT
  | typeof RefreshLayoutConsts.SIZE.LARGE
),
```

to:
```
size?: ?('default' | 'large')
```

In this commit we are supporting the old style as well as the new style. The old way of specifying the sizes will go away in a future release.

Changelog:
[Android] [Added] - RefreshControl now supports strings and not just numbers for size.

Reviewed By: mdvacca

Differential Revision: D15909582

fbshipit-source-id: 1849edc980e1698de147e88d710e0f28d0fdc8d8
2019-06-20 10:58:27 -07:00
Kudo Chien cbf1b39c66 Fix Android Picker ArrayOutOfBoundsException during Picker.Item update from a long list (#25276)
Summary:
axe-fb reported this side effect from my previous commit in https://github.com/facebook/react-native/pull/24793#issuecomment-502202082
After revisited the implementation of Android Spinner, it seems the formal way to update existing adapter is mutating it, i.e. `arrayAdapter.clear()` & `arrayAdapter.addAll()` to update a Spinner Adapter.
`setAdapter()` will reset everything including `mDataChanged`.
A race condition may happens between rendering a long picker list and reseting adapter.
Here is a code snippet: https://snack.expo.io/kudochien/80f810
To reproduce the issue, please select large item (e.g. 500) first and click the button right hand side.
Please not to verify this on Expo directly in the meantime, because Expo with RN 0.59 does not include my previous commit.

## Changelog

[Android] [Fixed] - Fix Picker ArrayOutOfBoundsException during Picker.Item update from a long list
Pull Request resolved: https://github.com/facebook/react-native/pull/25276

Test Plan:
1. Check the test case https://snack.expo.io/kudochien/80f810 will have exception or not.
2. Regression of https://snack.expo.io/Sy1JClEag from https://github.com/facebook/react-native/issues/13351
3. Regression of https://snack.expo.io/kudochien/android-picker-issue from https://github.com/facebook/react-native/issues/22821
4. RNTester Picker example

Reviewed By: mdvacca

Differential Revision: D15857426

Pulled By: axe-fb

fbshipit-source-id: 8ef902447fdd1b8aeab50ad061545cd14c735e51
2019-06-20 07:48:20 -07:00
Oleksandr Melnykov 3a8b988cb2 Release underlying resources when JS instance is GC'ed on Android
Summary:
[Android] [Added] - Release underlying resources when JS instance is GC'ed on Android

D15279651 introduced a crash for Oculus Twilight on Android (T45199437), so it was reverted by D15611385.

This diff fixes the crash and re-applies D15279651. The problem was that ProGuard renamed BlobModule.remove() to BlobModule.release(), but the C++ code in `BlobCollector.cpp` still expected the old name. I confirmed this by looking at the Extracted Symbols file for the build which introduces the crash (https://fburl.com/mobile/ud40od3i):

```
com.facebook.react.modules.blob.BlobModule -> com.facebook.react.modules.blob.BlobModule:
...
8190:8193:void remove(java.lang.String):190:193 -> release
...
```

See the full log file here: https://fburl.com/pn02bwkb.

The solution is to annotate the method with `DoNotStrip` so that ProGuard doesn't rename it.

Reviewed By: mdvacca, cpojer

Differential Revision: D15826082

fbshipit-source-id: f7470d394666cd34c1acae5c6ffaecc84d5ca5a3
2019-06-20 02:49:19 -07:00
Valentin Shergin 99ece27897 Fabric: Setting up correct `pointScaleFactor` in `Binding::startSurface`
Summary: Previously, we didn't provide any LayoutContext to the very first commit (aka startSurface); apparently it causes problems.

Reviewed By: mdvacca

Differential Revision: D15891472

fbshipit-source-id: b2a785bdad5764eb97b41f5bf5679807107bd8a0
2019-06-18 19:35:35 -07:00
Kevin Gozali e6f28bb4f7 Android TM: create TurboModuleManager earlier
Summary: Some TM lookup from native will fail assertion if done too early, because TM Manager is not initialized yet.

Reviewed By: mdvacca

Differential Revision: D15872776

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

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

Reviewed By: JoshuaGross

Differential Revision: D15872777

fbshipit-source-id: 9c2de7ef1e88ef3a6dff5888d644f9d8963af2a3
2019-06-18 16:22:17 -07:00
Emily Janzer 0d971f97d5 Fix weird formatting in FabricUIManager
Summary: I added this function in D15810990, not sure why lint didn't complain about this...

Reviewed By: zackargyle

Differential Revision: D15880129

fbshipit-source-id: 4d207ba26be46186dc3904c82d82a4a83d4d4eb7
2019-06-18 12:09:47 -07:00
Joshua Gross 4a5060f4cb Binding.cpp will use locks to guard access to scheduler and UIManager
Summary:
It is possible that race conditions exist in access of scheduler and UIManager in Binding.cpp, such that deallocated or null schedulers/UIManagers could be passed as arguments into various functions, causing strange and exotic crashes down the line once garbage memory (or null pointers) are dereferenced.

I think it's possible that navigating away from a Fabric screen while there's high memory pressure could cause things to get deallocated more aggressively and cause scheduler and/or UIManager to disappear while mounting instructions are being created, for instance.

Reviewed By: mdvacca

Differential Revision: D15863193

fbshipit-source-id: a85cb71d88ea54826b40f44e788931dfc422f045
2019-06-18 10:37:45 -07:00
Kudo Chien ce80a670bd Fix Android native debug build assert crash (#25263)
Summary:
The problem happens only from native debug build, i.e.
`NATIVE_BUILD_TYPE=Debug ./gradlew ...`
During Java exception happens, [only limited methods are allowed](https://developer.android.com/training/articles/perf-jni#exceptions_1).
RN uses smart pointer to manage JNI reference.
There is an assert() in smart pointer constructor that will call other JNI method and lead to VM crash.
Since assert() do things in debug build by default, the problem will not happens on native release build.

### Crash backtrace
Java exception happens:

```
java_vm_ext.cc:534] JNI DETECTED ERROR IN APPLICATION: JNI GetObjectRefType called with pending exception com.facebook.react.uimanager.IllegalViewOperationException: No ViewManager defined for class Text
java_vm_ext.cc:534]   at com.facebook.react.uimanager.ViewManager com.facebook.react.uimanager.ViewManagerRegistry.get(java.lang.String) (ViewManagerRegistry.java:57)
java_vm_ext.cc:534]   at com.facebook.react.uimanager.ViewManager com.facebook.react.uimanager.UIImplementation.resolveViewManager(java.lang.String) (UIImplementation.java:134)
java_vm_ext.cc:534]   at com.facebook.react.bridge.WritableMap com.facebook.react.uimanager.UIManagerModule.computeConstantsForViewManager(java.lang.String) (UIManagerModule.java:325)
java_vm_ext.cc:534]   at com.facebook.react.bridge.WritableMap com.facebook.react.uimanager.UIManagerModule.getConstantsForViewManager(java.lang.String) (UIManagerModule.java:319)
java_vm_ext.cc:534]   at void com.facebook.react.bridge.queue.NativeRunnable.run() (NativeRunnable.java:-2)
java_vm_ext.cc:534]   at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:790)
java_vm_ext.cc:534]   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:99)
java_vm_ext.cc:534]   at void com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(android.os.Message) (MessageQueueThreadHandler.java:29)
java_vm_ext.cc:534]   at void android.os.Looper.loop() (Looper.java:164)
java_vm_ext.cc:534]   at void com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run() (MessageQueueThreadImpl.java:232)
java_vm_ext.cc:534]   at void java.lang.Thread.run() (Thread.java:764)
```

Native crash backtrace:

```
#00 pc 00000000000276f8  /system/lib64/libc.so (syscall+24)
https://github.com/facebook/react-native/issues/01 pc 0000000000027905  /system/lib64/libc.so (abort+101)
https://github.com/facebook/react-native/issues/02 pc 000000000052f32e  /system/lib64/libart.so (art::Runtime::Abort(char const*)+558)
https://github.com/facebook/react-native/issues/03 pc 00000000006341a8  /system/lib64/libart.so (android::base::LogMessage::~LogMessage()+1016)
https://github.com/facebook/react-native/issues/04 pc 0000000000399339  /system/lib64/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+1657)
https://github.com/facebook/react-native/issues/05 pc 00000000003994c2  /system/lib64/libart.so (art::JavaVMExt::JniAbortV(char const*, char const*, __va_list_tag*)+82)
https://github.com/facebook/react-native/issues/06 pc 0000000000178aab  /system/lib64/libart.so (art::ScopedCheck::AbortF(char const*, ...)+187)
https://github.com/facebook/react-native/issues/07 pc 00000000001785b8  /system/lib64/libart.so (art::ScopedCheck::CheckThread(_JNIEnv*)+472)
https://github.com/facebook/react-native/issues/08 pc 0000000000176871  /system/lib64/libart.so (art::ScopedCheck::Check(art::ScopedObjectAccess&, bool, char const*, art::JniValueType*)+801)
https://github.com/facebook/react-native/issues/09 pc 000000000017614a  /system/lib64/libart.so (art::CheckJNI::GetObjectRefType(_JNIEnv*, _jobject*)+778)
https://github.com/facebook/react-native/issues/10 pc 0000000000123831  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libreactnativejni.so (_JNIEnv::GetObjectRefType(_jobject*)+49)
https://github.com/facebook/react-native/issues/11 pc 00000000001236b1  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libreactnativejni.so (facebook::jni::LocalReferenceAllocator::verifyReference(_jobject*) const+81)
https://github.com/facebook/react-native/issues/12 pc 0000000000046f40  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libfb.so (facebook::jni::base_owned_ref<_jthrowable*, facebook::jni::LocalReferenceAllocator>::base_owned_ref(_jthrowable*)+64)
https://github.com/facebook/react-native/issues/13 pc 0000000000046ef7  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libfb.so (facebook::jni::basic_strong_ref<_jthrowable*, facebook::jni::LocalReferenceAllocator>::basic_strong_ref(_jthrowable*)+39)
https://github.com/facebook/react-native/issues/14 pc 000000000003648b  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libfb.so (_ZN8facebook3jni11adopt_localIP11_jthrowableEENS0_16basic_strong_refIT_NS0_23LocalReferenceAllocatorEEES5_+27)
https://github.com/facebook/react-native/issues/15 pc 0000000000036333  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libfb.so (facebook::jni::throwPendingJniExceptionAsCppException()+99)
https://github.com/facebook/react-native/issues/16 pc 000000000018652f  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libreactnativejni.so (facebook::react::MethodInvoker::invoke(std::__ndk1::weak_ptr<facebook::react::Instance>&, facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::react::JBaseJavaModule, facebook::jni::JObject, void>::_javaobject*>, folly::dynamic const&)+4559)
https://github.com/facebook/react-native/issues/17 pc 00000000001616fa  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libreactnativejni.so (_ZN8facebook5react16JavaNativeModule26callSerializableNativeHookEjON5folly7dynamicE+954)
https://github.com/facebook/react-native/issues/18 pc 000000000021bbd6  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libreactnativejni.so (_ZN8facebook5react14ModuleRegistry26callSerializableNativeHookEjjON5folly7dynamicE+486)
https://github.com/facebook/react-native/issues/19 pc 000000000022d90b  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libreactnativejni.so (_ZN8facebook5react16JsToNativeBridge26callSerializableNativeHookERNS0_10JSExecutorEjjON5folly7dynamicE+75)
https://github.com/facebook/react-native/issues/20 pc 000000000004a6fa  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libjscexecutor.so (facebook::react::JSIExecutor::nativeCallSyncHook(facebook::jsi::Value const*, unsigned long)+202)
https://github.com/facebook/react-native/issues/21 pc 000000000004b7a2  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libjscexecutor.so
https://github.com/facebook/react-native/issues/22 pc 0000000000056475  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libjscexecutor.so
https://github.com/facebook/react-native/issues/23 pc 00000000000c3a0a  /data/app/com.facebook.react.uiapp-NEO_tjqQpFriZwGleZxJeQ==/lib/x86_64/libjsc.so
```

Java exception code from [ViewManagerRegistry.java](https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagerRegistry.java#L45-L58) :

```java
  public ViewManager get(String className) {
    ViewManager viewManager = mViewManagers.get(className);
    if (viewManager != null) {
      return viewManager;
    }
    if (mViewManagerResolver != null) {
      viewManager = mViewManagerResolver.getViewManager(className);
      if (viewManager != null) {
        mViewManagers.put(className, viewManager);
        return viewManager;
      }
    }
    throw new IllegalViewOperationException("No ViewManager defined for class " + className);
  }
```
It is an expected exception as [legacy JS try to find view manager](https://github.com/facebook/react-native/blob/master/Libraries/ReactNative/PaperUIManager.js#L44-L50) and Text has no ViewManager registered in fact.

From C++ assert:
`adopt_local`  will call to base_owned_ref() and [there is an assert to ensure JNI reference type](https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/References-inl.h#L203-L209).

```C++
template<typename T, typename Alloc>
inline facebook::jni::base_owned_ref<T, Alloc>::base_owned_ref(
    javaobject reference) noexcept
  : storage_(reference) {
  assert(Alloc{}.verifyReference(reference));
  internal::dbglog("New wrapped ref=%p this=%p", get(), this);
}
```

In the verifyReference(), [there is a GetObjectRefType() call which is an invalid call at exception pending state](https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/jni/first-party/fb/include/fb/fbjni/ReferenceAllocators-inl.h#L57-L62).

```C++
inline bool LocalReferenceAllocator::verifyReference(jobject reference) const noexcept {
  if (!reference || !internal::doesGetObjectRefTypeWork()) {
    return true;
  }
  return internal::getEnv()->GetObjectRefType(reference) == JNILocalRefType;
}
```

The fix moves `adopt_local()` wrapping after `ExceptionClear()` and we could call `GetObjectRefType()` without problems.

## Changelog

[Android] [Fixed] - Fix Android native debug build assert crash
NOTE this might be ignored in RN release changelog.
Since the problem should exist for years and no user tried native debug build.
Pull Request resolved: https://github.com/facebook/react-native/pull/25263

Test Plan:
Try to run RNTester from native debug build and make sure no crash happens.
(It is a launch crash and should be easy to verify)
`NATIVE_BUILD_TYPE=Debug ./gradlew clean :RNTester:android:app:installDebug`

Differential Revision: D15873691

Pulled By: cpojer

fbshipit-source-id: fb93b85daa1136cdf44e7fd7f217a2767391d8dd
2019-06-18 02:03:58 -07:00
David Vacca f43039da87 Force setConstraints to run in the JS Thread
Summary: This diff forces the method: scheduler.constraintSurfaceLayout to run on the JS thread.

Reviewed By: JoshuaGross

Differential Revision: D15845768

fbshipit-source-id: de2aa69f301770aaf6cb7c3f5670548a3b6110df
2019-06-17 21:42:28 -07:00
Emily Janzer 1de206f36f Pass layout constraints in to startSurface()
Summary: Scheduler.startSurface accepts LayoutConstraints and LayoutContext, but for some reason we don't use these on Android. This diff adds new methods to Binding and FabricUIManager to start a surface with the provided measurespecs. I created new methods to avoid affecting the functionality of any surfaces already using Fabric, but if we want this behavior everywhere then I can just add it to the existing `addRootView` and `startSurface`.

Reviewed By: JoshuaGross, shergin

Differential Revision: D15810990

fbshipit-source-id: 6cd9a58b125461f91253458905405298cfb723ce
2019-06-17 13:03:05 -07:00
Joshua Gross 8957637364 Add a few Fabric systrace sections
Summary: Just adding a few systrace sections to add perf visibility in a few more areas.

Reviewed By: ejanzer

Differential Revision: D15823394

fbshipit-source-id: 6ac1773cbd8e01a747ad015726e16c0bf0e8596b
2019-06-14 19:06:56 -07:00
Emily Janzer 616864a2df Focus text input on accessibility tap
Summary:
There's an issue with TextInput on Android where if you have TalkBack enabled, double tapping doesn't focus the text input. It turns out this is because we ignore all focus events that aren't from JS in ReactEditText. This diff makes an exception for the accessibility click event.

I think this should also fix https://github.com/facebook/react-native/issues/17624

Reviewed By: lunaleaps

Differential Revision: D15818103

fbshipit-source-id: 354728b58f1023c4d44edd48337c8daa8ea15c0c
2019-06-14 10:45:29 -07:00
Luna Wei 545b084cc8 Back out "[RN] Layout Animation fix for normalized indices"
Summary:
Original commit changeset: 43e57dffa807

[Errors are growing and very ominious](https://our.intern.facebook.com/intern/logview/details/facebook_android_crashes/6acac038d7dd9d8ca95d1b9bccc4dfaa/?trace_key=39c72364f916998602bd55f091b04682)
I don't have a good idea what's going on.
This will re-introduce this bug: T44343673

Next steps:
* Would be great to try and get a repro to fix.
* Refactor this logic out to its own class and write actual tests.

Reviewed By: mdvacca

Differential Revision: D15822555

fbshipit-source-id: 0a2ec3d5c73420ca56aad93a4323a34cff1cc9c7
2019-06-14 07:43:06 -07:00
David Vacca f95a21539a Create a ReactFeatureFlag to enabled logging in Fabric
Summary: Easy diff to create a ReactFeatureFlag to enabled logging in Fabric

Reviewed By: JoshuaGross

Differential Revision: D15803582

fbshipit-source-id: d735f24850bddf43c27b97d006100cbb8f0cc6e3
2019-06-14 02:52:55 -07:00
Luis Miguel Alvarado 3bf068ac93 Fix a typo in BaseJavaModule (#25245)
Summary:
This PR only fixes a one small orthographic error
Pull Request resolved: https://github.com/facebook/react-native/pull/25245

Differential Revision: D15796478

Pulled By: hramos

fbshipit-source-id: ccb811b43b0d2efc5d97ba335b60531a0fcbda10
2019-06-12 18:22:59 -07:00
Joshua Gross b9d26bbb5b Enable debug FabricUIManager logging for everyone
Summary: Temporarily turn on debug FabricUIManager to gather diagnostics.

Reviewed By: mdvacca

Differential Revision: D15779389

fbshipit-source-id: b38c1a363dbbad9c7dcf6bdbc3f47aff1a834f2f
2019-06-12 07:41:26 -07:00
Charley 5b72ec31ae Modify comment of NativeViewHierarchyManager.java. (#25235)
Summary:
Modify the wrong word in the comment of NativeViewHierarchyManager.java.

Fix the explanation of the code to avoid misunderstanding.

## Changelog

[Android] [Fixed] - Fix the explanation of the code to avoid misunderstanding.
Pull Request resolved: https://github.com/facebook/react-native/pull/25235

Differential Revision: D15779249

Pulled By: cpojer

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

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

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

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

Differential Revision: D14298654

Pulled By: cpojer

fbshipit-source-id: 5cc17539a51154faeb838349b068d92511946f79
2019-06-12 05:11:43 -07:00
Ramanpreet Nara 9cea76072a Make turbomodule/core/jni:jni depend on FBJNI_TARGET
Summary:
`fbsource//xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni:jni` is a shared library that depends on `fbjni` (also another shared library). In dev and prod, I think `turbomodule/core/jni:jni` was pulling in `fbjni` from its `react_native_target("jni/react/jni:jni")` dependency even though `FBJNI_TARGET` wasn't an exported_dep of `react_native_target("jni/react/jni:jni")`. In `android_automation_cameracore_release_build`, however, this wasn't happening, which led to that build failing to compile.

In this diff, I'm explicitly making `FBJNI_TARGET` a dependency of `fbsource//xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni:jni`. This unbreaks `android_automation_cameracore_release_build`.

Reviewed By: fkgozali

Differential Revision: D15758160

fbshipit-source-id: db20c127a888b0cf68aea592de6a2e380c455c1d
2019-06-11 10:15:17 -07:00
David Aurelio 027679336d rm `YogaEventListener`
Reviewed By: SidharthGuglani

Differential Revision: D15742456

fbshipit-source-id: b90a221e177e936e141c582500dccf0ac38027c2
2019-06-11 01:41:21 -07:00
Emily Janzer 5c399a9f74 Workaround to avoid bridge access from ReactTextView for Venice
Summary:
D14014668 introduced support for nesting views within Text on Android. Part of the implementation involved accessing the UIManagerModule from ReactTextView through context. This doesn't work in bridgeless RN because we have no UIManagerModule, and the ReactContext has no Catalyst instance. Trying to access the Catalyst instance from ReactContext throws an exception if it doesn't exist, so i'm just adding a simple check here to make sure the instance exists before proceeding.

This means that this feature won't work in bridgeless mode, but that's ok for now - eventually we want to change the way this works so that it doesn't rely on accessing views in Java, which is potentially unsafe (there's nothing to stop you from mutating the views, and cpp/js would never know about it).

Reviewed By: mdvacca

Differential Revision: D15703100

fbshipit-source-id: 0448d55b8345fc707a25210a505cb6ac520c708a
2019-06-10 13:54:55 -07:00
Ramanpreet Nara 72be568666 Reland "[RN][TurboModule] Enable TurboModules for FB4A"
Summary:
These changes were originally landed in D15327683. Unfortunately, I had to back these out because they revelaled problems with our TurboModules infra. Those problems have since been fixed, so I think it's safe for us to re-land these changes.

Please refer to D15327683 for a description.

Differential Revision: D15739355

fbshipit-source-id: 69bb3cec0731ba325f60c6c8459426546c79b54d
2019-06-10 10:58:20 -07:00
Ramanpreet Nara 608cf6fe09 Make CompositeReactPackage support TurboReactPackage
Summary:
## Description
CompositeReactPackage will now eagerly initialize all NativeModules inside the TurboReactPackages. Before it would just crash the program because calling `createNativeModules()` on the TurboReactPackage instance. Longer term, we should make CompositeReactPackage a TurboReactPackage.

## Why am I making this change?
I made MainReactPackage into a TurboReactPackge. But ExpressWifiTechnician uses MainReactPackage to create a CompositeReactPackage:

**java/com/expresswifi/technician/MainActivity.java**
```
protected ReactPackage getPackage() {
  ReactInstanceManager reactInstanceManager = getReactInstanceManager();
  Nullable DevSupportManager devSupportManager = null;
  if (reactInstanceManager != null) {
    devSupportManager = reactInstanceManager.getDevSupportManager();
  }

  return new CompositeReactPackage(
      super.getPackage(),
      mXWFTechnicianReactPackage,
      new RNFusedLocationPackage(),
      mXWFTechnicialMobileConfigPackageProvider.get(devSupportManager));
}
```

**java/com/facebook/catalyst/shell/MainReactActivity.java**
```
public abstract class MainReactActivity extends AbstractReactActivity {
  protected ReactPackage getPackage() {
    return new MainReactPackage();
  }
}
```

Reviewed By: fkgozali

Differential Revision: D15738677

fbshipit-source-id: 3220dfe6434de56f2917c77fb21acef4cfc79278
2019-06-10 10:52:46 -07:00
Aditya Sharat 1f3e4df6a7 Back out "[litho] Adds check to unset a YogaNode's parent during reconciliation."
Summary: Removes `unsetOwner` from Yoga. This was temporarily for patching a crash.

Reviewed By: colriot

Differential Revision: D15737613

fbshipit-source-id: 8ab93ecf7ffb913df6207fe5db47a8cc93eded2c
2019-06-10 06:56:19 -07:00
Onti Vals ae231c8322 Scrolling fixes (#25105)
Summary:
Scrolling improvements in ReactAndroid:

1.
Issue: With current ReactHorizontalScrollView behavior, it treats all views as focusable, regardless of if they are in view or not. This is fine for non-paged horizontal scroll view, but when paged this allows focus on elements that are not within the current page. Combined with logic to scroll to the focused view, this breaks the paging for ReactHorizontalScrollView.

Fix: limit the focusable elements to only elements that are currently in view when ReactHorizontalScrollView has paging enabled

2.
Issue: When keyboard is attached and user tries to navigate through Tab key, Scroll views do not scroll to the focused child.
Since ReactScrollView handles layout changes on JS side, it does not call super.onlayout due to which mIsLayoutDirty flag in android ScrollView remains true and prevents scrolling to child when requestChildFocus is called.

Fix: To fix the focus navigation, we are overriding requestChildFocus method in ReactScrollView. We are not checking any dirty layout flag and scrolling to child directly. This will fix focus navigation issue for KeyEvents which are not handled by android's ScrollView, for example: KEYCODE_TAB. Same applies to ReactHorizontalScrollView.

3.
Set Android ScrollView to be non-focusable when scroll is disabled. Prior to this change, non-scrollable Scrollview would still be focusable, causing a poor keyboarding experience

## Changelog

[Android] [Fixed] Scrolling improvements in ReactAndroid
Pull Request resolved: https://github.com/facebook/react-native/pull/25105

Differential Revision: D15737563

Pulled By: mdvacca

fbshipit-source-id: 0d57563415c68668dc1acb05fb3399e6645c9595
2019-06-10 03:49:38 -07:00
David Vacca d0792d4b8a Add ReactFragment for Android
Summary:
React Native on Android has currently been focused and targeted at using an Activity 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
Release Notes
[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.

Reviewed By: cpojer

Differential Revision: D15731340

fbshipit-source-id: 74b7aaedcfd6ad6e074ff911cd7f18a5111caf5c
2019-06-10 03:40:38 -07:00
Sidharth Guglani b6dc9587e6 add node layout event and pass it java layer
Summary: Listen to NodeLayout event and passes this event callback to java layer along with the information whether layout or measure was done in this pass

Reviewed By: davidaurelio

Differential Revision: D15696021

fbshipit-source-id: 8c5ca69330a9baca26b77052d4965cc67fe97c75
2019-06-10 01:48:59 -07:00
David Vacca 6236798a3f Create feature flag to log extra data in ReactWebView
Summary: This diff creates a new react feature flag to enable extra logging on React Web Views

Reviewed By: RSNara

Differential Revision: D15729871

fbshipit-source-id: 931d4a1b022c6a405228bf896b50ecc7a44478d1
2019-06-09 15:24:09 -07:00
Ramanpreet Nara 9c76e14b07 Turn FBMainReactPackage into a TurboReactPackage
Summary: `ReactTurboModuleManagerDelegate` only understands `TurboReactPackage`s. So, we need to convert `FBMainReactPackage` and all its dependent packages into `TurboReactPackage`.

Reviewed By: fkgozali

Differential Revision: D15711546

fbshipit-source-id: df626d542a6477b116c867299219156423c6364a
2019-06-09 15:24:09 -07:00
Ramanpreet Nara 3312146ced Make NativeModule names public
Summary: To implement the `getModule` method of `TurboReactPackages`, we need to be able to access the JS Names of NativeModule classes.

Reviewed By: fkgozali

Differential Revision: D15711544

fbshipit-source-id: 51a649d08410557a4bdbf20d065bf98646a8d18a
2019-06-07 13:11:55 -07:00
Ramanpreet Nara e5a8e3a53e Initialize TurboModules after creation
Summary:
When `ModuleHolder` instantiates `NativeModules`, it calls the `initialize()` method. We should replicate this call in the TurboModule system.

`NativeModule.initialize()` is meant to be called after ReactApplicationContext is initialized. TurboModuleManager is initialized after ReactApplicationContext is initialized. Therefore, after we create the TurboModule, it should be safe to call `initialize()` on it.

Reviewed By: mdvacca

Differential Revision: D15711540

fbshipit-source-id: c2ef1a2ab164996bfc5716d81b3b3c716bf0e120
2019-06-07 13:11:55 -07:00
Valentin Shergin 205de0538c Fabric: New names for ContextContainer methods
Summary:
... and slighly new behaviour for one of them.

The method does nothing if given `key` already exists in the container.

This diff finishes the transition of ContextContainer from an internal bag of things with unclear yet ownership into a legit dedicated dependency injection container for the product code.

The original names of methods imply that the container can have only one object of a given type which is no longer true. The new API is much more generic and idiomatic to C++, it mimics `std:map` API which is intuitive to anyone who familiar with C++ containers.

Besides the naming, `insert` method changed the semantic a bit; now it does nothing in case of inserting an object with a key that already exists. That might seem counterintuitive for "normal" people, but C++ has some wired reasons for that and, hopefully, it's expected behavior in the C++ community.

Fun fact: We need this to fix hot-reload.

Reviewed By: sahrens

Differential Revision: D15681736

fbshipit-source-id: 194f342528446a911eaf072ba3a94a5d8af3cb52
2019-06-07 12:03:57 -07:00
Valentin Shergin a19cfc2273 Fabric: Scheduler-specific dependencies were moved to a separate class from ContextContainer
Summary: ContextContainer should contain only product/component-specific dependencies and stay unchanged during VM/Scheduler reloading.

Reviewed By: JoshuaGross

Differential Revision: D15636656

fbshipit-source-id: fe5de1b6c92f659b28d31eba901c04c5b23fe1d1
2019-06-07 12:03:57 -07:00