Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[e2e-testing][Appium] Adding support for android:id #9942

Closed

Conversation

jsdevel
Copy link
Contributor

@jsdevel jsdevel commented Sep 16, 2016

  • Calling view.setId() with the matching resource-id of an id found in R.class when BaseViewManager.setTestId is called.
  • Adding TestIdUtil in common to store mappings for testID with attributed views and their original react tag value.
  • Changing the signature for Event Classes to require the View instead of the viewTag. This reduces the number of locations where TestIdUtil.getOriginalReactTag is called.
  • Overriding BaseViewManager.onDropViewInstance to perform TestIdUtil mapping cleanup.
  • This closes Add support for resource-id #9777.
  • In order for this to work properly, an id resource needs to be manually added to android/app/src/main/res/values/ids.xml. Here's the contents of that file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="something" type="id"/>
</resources>

@ghost
Copy link

ghost commented Sep 16, 2016

By analyzing the blame information on this pull request, we identified @kmagiera and @sebmarkbage to be potential reviewers.

@ghost ghost added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Sep 16, 2016
@jsdevel
Copy link
Contributor Author

jsdevel commented Sep 16, 2016

@ide what's the best way I could test this change?

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 16, 2016
@ide
Copy link
Contributor

ide commented Sep 17, 2016

Building from source and running the UIExplorer + temporarily modifying its code to invoke your new code is a reasonable path forward.

@jsdevel
Copy link
Contributor Author

jsdevel commented Sep 18, 2016

Thanks @ide !

I've verified locally that it works!

working

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 18, 2016
@jsdevel
Copy link
Contributor Author

jsdevel commented Sep 18, 2016

I've also verified that non-existent ids in ids.xml don't have any side effects i.e. testID="some-id-not-in-ids.xml" doesn't break anything.

@jsdevel
Copy link
Contributor Author

jsdevel commented Sep 18, 2016

cc @mkonicek @bestander

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 18, 2016
@jsdevel jsdevel force-pushed the adding-support-for-resource-id branch from 738f346 to 580888e Compare September 19, 2016 11:04
@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2016
@jsdevel jsdevel force-pushed the adding-support-for-resource-id branch from 580888e to ee453d3 Compare September 19, 2016 18:19
@jsdevel
Copy link
Contributor Author

jsdevel commented Sep 19, 2016

Looks like the tests for HMR are failing on most PRs.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2016
@bestander
Copy link
Contributor

Yeah, trunk was broken over weekend.
Should be fixed now

@@ -84,6 +87,13 @@ public void setRenderToHardwareTexture(T view, boolean useHWTexture) {

@ReactProp(name = PROP_TEST_ID)
public void setTestId(T view, String testId) {
if (!testIDs.containsKey(testId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this and line 94 checking the same thing? can you combine this logic?

Copy link
Contributor Author

@jsdevel jsdevel Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view.getResources().getIdentifier(testId, "id", view.getContext().getPackageName()) will return 0 if no matching identifier is found. I wanted to avoid calling it more than once for a given testID if possible which is why there are 2 checks:

  • The first check is for caching purposes.
  • The second check is to avoid setting the testId on the View if the user didn't define it.

@aaronechiu
Copy link
Contributor

aaronechiu commented Sep 19, 2016

I'm pretty wary of setting the ids on views because we at least use the ids of the ReactRootViews to track the ReactRootViews so this can break something in a hard to track way...
I can't remember off the top of my head if we use the ids of non-ReactRootViews else where though...

@jsdevel jsdevel force-pushed the adding-support-for-resource-id branch 2 times, most recently from 4a9cf22 to e406eb9 Compare September 19, 2016 20:37
@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2016
@jsdevel
Copy link
Contributor Author

jsdevel commented Sep 19, 2016

I'm pretty wary of setting the ids on views because we at least use the ids of the ReactRootViews to track the ReactRootViews so this can break something in a hard to track way...

  • Is there an example of where a ReactRootView would ever have a testID? I'd like to test that in JSX if possible.
  • I could add a check and only set the id if view.getId() == 0.

@jsdevel jsdevel force-pushed the adding-support-for-resource-id branch from e406eb9 to 5a61912 Compare September 19, 2016 20:47
@jsdevel
Copy link
Contributor Author

jsdevel commented Sep 19, 2016

@AaaChiuuu I added an additional check to avoid setting the id on the View if it currently has an Id.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2016
@jsdevel jsdevel force-pushed the adding-support-for-resource-id branch from 5a61912 to 62f66db Compare September 19, 2016 20:50
@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 19, 2016
@jsdevel jsdevel force-pushed the adding-support-for-resource-id branch from 62f66db to 85dee1d Compare September 19, 2016 21:39
@curioustechizen
Copy link

@jonesdar Thanks for this work-around! Just to point out, I had to use the plural forms of the locator methods for Appium to be able to find my view with the accessibilityLabel on Android: i.e., waitForElementsById instead of waitForElementById and elementsById instead of elementById.

Using the plural form is apparently what tells Appium to try multiple strategies. The clue was in the Appium server debug logs. When I used the singular form, the log had the equivalent of

[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"Email","context":"","multiple":false}}

The "multiple":false prompted me to explore this a bit and I finally found the answer here

jsdevel referenced this pull request in EdtechFoundry/react-native May 24, 2017
* Calling view.setId() with the matching resource-id of an id found in R.class.  Added TestIdUtil to facilitate this.
* Updating the android sample project to include a testID example.  Updating the e2e test to use it.
* Changing the signature for virtually all Event Classes to require the View instead of the viewTag.  This reduces the number of locations where TestIdUtil.getOriginalReactTag is called.
* Minimizing the impact in non __DEV__ environments where testID should not be set by simply returning view.getId() in TestIdUtil.getOriginalReactTag.
* This closes facebook#9777.
@voidgit
Copy link

voidgit commented Sep 26, 2017

@mkonicek Are there any plans to proceed with this issue?
Because tag is not available via Appium on Android (and will be not available in foreseeable futurte) due to UIAutomator2 limitations (appium/appium#6025 (comment))
and only AccessibilityLabel is left and given this is not an id and we are going to use AccessibilityLabel for, actually, accessibility there is no viable way to test react-native applications on Android.

@marlenabowen
Copy link

@mkonicek any ETA for when FB might open-source the internal e2e framework?

@kholiavko-roman
Copy link

Can I now to set resource-id for android from react-native ?
I need it for running pre-launch tests on Goolge Play.

@ThaJay
Copy link

ThaJay commented Jan 23, 2018

I'm afraid not. This should have been handled / merged months ago.

@mkonicek
Copy link
Contributor

mkonicek commented Feb 4, 2018

Hey everyone, so sorry about the long radio silence about this. I left fb in the meantime and went traveling for 4 months and then joined a startup where I'm doing some native Android dev for now, currently playing with integrating React Native to an existing native app.

I feel very sorry about closing this PR and seeing it disappointed so many people. I thought someone from the community would provide a way to look up elements by Android view tags like we did at fb and the issue would be solved. It looks like it's harder to add support to Appium than I thought, but will happen eventually (see appium-espresso-driver, found via a comment on the Appium issue).

At the same time, I'm glad there is the workaround by @jonesdar (#9942 (comment)). To me it looks like a reasonable workaround and I'd use it when testing my app with Appium. I'll copy it here to make it easier to discover (at the end of the comments section). Quoting @jonesdar:

I defined a testProps(id) function which returns an object {testID: id, accessibilityLabel: id}.
It's used in all our RN views e.g.
<View {...testProps('idForThisView')}>

Appium can then find elements by id on both iOS and Android. Yes, the accessibilityLabel is user-visible but testProps is conditional on build type so we only include these props for a test build anyway.
It means we're not quite testing with the exact build we ship, but it's worked well for the last 9-10 months.

@jonestheguitar
Copy link

jonestheguitar commented Feb 4, 2018

Worth pointing out that the workaround needs a few tweaks on newer versions of Android.
Firstly you'll need to specify automationName: 'uiautomator2' in Appium's desired capabilities (I think the default 'uiautomator' has been deprecated from Android 5.0 onwards).

Then you'll notice that waitForElementById, elementById etc. no longer do multiple locator strategy fallbacks (so elementById won't fall back to elementByAcessibilityId etc.) - I fixed that as follows:

    if ('android' === process.env.APPIUM_PLATFORM) {
      // uiautomator2 doesn't seem to do multiple locator strategy fallbacks
      // so map id to accessibility id directly
      wd.addPromiseChainMethod('waitForElementById', id => {
        return this._driver.waitForElementByAccessibilityId(id);
      });

      wd.addPromiseChainMethod('elementById', id => {
        return this._driver.elementByAccessibilityId(id);
      });

      wd.addPromiseChainMethod('elementByIdOrNull', id => {
        return this._driver.elementByAccessibilityIdOrNull(id);
      });

      wd.addElementPromiseChainMethod('elementById', function() {
        return this.elementByAccessibilityId(id);
      });
    }

i.e. centrally map waitForElementById() to waitForElementByAccessibilityId() etc. - to ensure that Appium finds the testIDs we've put into the accessibilityLabels.
Note that you could just use the accessibility id methods on Android and the id methods on iOS but I've always used the same test code on both platforms and I don't want it to diverge now.

I think I read somewhere that you can do multiple locator strategy fallbacks by using plurals (waitForElementsById, elementsById etc.) but I haven't tried that - and it would still require a global find/replace in all test code (or a central mapping as above) anyway to get existing tests working again.

On the plus side, uiautomator2 seems to run my tests twice as fast as uiautomator.

@jsdevel
Copy link
Contributor Author

jsdevel commented Feb 8, 2018

I'd happily get this working again 😄 any takers from the RN team?

@jribeiro
Copy link

I've written a babel plugin to address this issue in the meantime. The idea is to add a property accessibilityLabel every time a testId jsx property is found. Essentially it'll allow you to provide meaningful accesibilityLabels in your application and on an Android specific build replace this by the defined testIDs.
https://github.com/jribeiro/babel-plugin-jsx-property-alias

Hope it helps

@lightboys22
Copy link

lightboys22 commented Mar 23, 2018

I realize that my pull request is very similar to this pull request.

@jsdevel
Copy link
Contributor Author

jsdevel commented Mar 23, 2018

@lightboys22 I'm sorry that you went down this road. I feel your pain 😢

@Mishan999
Copy link

Good

@tylermurry
Copy link

tylermurry commented May 1, 2018

We use Appium to test our applications and I was able to solve this problem very elegantly with react-native-testid.

@lightboys22
Copy link

lightboys22 commented May 1, 2018

@tylermurry react-native-testid will change the accessibilityLabel on Android platform. Our accessibilityLabels won't be unique.

@Frank1234
Copy link

A copy and paste solution using Espresso and the solution from #9942 in this article:

Espresso testing React Native

@jdeff
Copy link
Contributor

jdeff commented Aug 26, 2020

I know this ticket is old and many people have found suitable workarounds, but in case anyone still cares (and is actually using accessibilityLabel for accessibility like one should 😉), I've put up a super simple PR that should fix this. cc @jsdevel @lightboys22

facebook-github-bot pushed a commit that referenced this pull request Jan 6, 2021
Summary:
There has been a long-standing issue where black-box testing frameworks like Appium and Xamarin UITest have not been able to access the `testID` view prop for Android (see #7135). A natural place for this to be exposed is via a view's `resource-id`. The `resource-id` is what I have used when working on UIAutomator-based tests for native Android apps and is a non-localized, development-only identifier. As mentioned in the linked ticket, you can dynamically set the resource-id using the view's AccessibilityNodeInfo. This change simply checks to see if a testID is provided for a view and then exposes it through the view's accessibility node delegate.

## Changelog

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

[Android] [Fixed] - Fixes #7135,  #9942, and #16137. Display the `testID` as the `resource-id` for black-box testing frameworks

Pull Request resolved: #29610

Test Plan:
I used the `uiautomatorviewer` tool to verify that the resource-id is populated with the `testID` of a few different views of the RNTester app.
<img width="912" alt="Screen Shot 2020-08-10 at 3 38 27 PM" src="https://user-images.githubusercontent.com/875498/89838534-55044100-db20-11ea-9be2-ba507a81f6fb.png">
<img width="1096" alt="Screen Shot 2020-08-10 at 3 40 41 PM" src="https://user-images.githubusercontent.com/875498/89838542-5897c800-db20-11ea-9895-462c6fea1130.png">

Reviewed By: JoshuaGross

Differential Revision: D25799550

Pulled By: fkgozali

fbshipit-source-id: e64ff1b90fb66b427fce7af533aa94792cfbcad3
grabbou pushed a commit that referenced this pull request Jan 23, 2021
Summary:
There has been a long-standing issue where black-box testing frameworks like Appium and Xamarin UITest have not been able to access the `testID` view prop for Android (see #7135). A natural place for this to be exposed is via a view's `resource-id`. The `resource-id` is what I have used when working on UIAutomator-based tests for native Android apps and is a non-localized, development-only identifier. As mentioned in the linked ticket, you can dynamically set the resource-id using the view's AccessibilityNodeInfo. This change simply checks to see if a testID is provided for a view and then exposes it through the view's accessibility node delegate.

## Changelog

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

[Android] [Fixed] - Fixes #7135,  #9942, and #16137. Display the `testID` as the `resource-id` for black-box testing frameworks

Pull Request resolved: #29610

Test Plan:
I used the `uiautomatorviewer` tool to verify that the resource-id is populated with the `testID` of a few different views of the RNTester app.
<img width="912" alt="Screen Shot 2020-08-10 at 3 38 27 PM" src="https://user-images.githubusercontent.com/875498/89838534-55044100-db20-11ea-9be2-ba507a81f6fb.png">
<img width="1096" alt="Screen Shot 2020-08-10 at 3 40 41 PM" src="https://user-images.githubusercontent.com/875498/89838542-5897c800-db20-11ea-9895-462c6fea1130.png">

Reviewed By: JoshuaGross

Differential Revision: D25799550

Pulled By: fkgozali

fbshipit-source-id: e64ff1b90fb66b427fce7af533aa94792cfbcad3
@sasmit
Copy link

sasmit commented Apr 15, 2021

@jdeff
I am on react-native 0.62. So I took your changes(commit #29610)) locally to node_modules (path:ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java ) and tried to test my application with UI Automator view and unable to get the vlaues for resource-id. Its always empty.

Am I missing something here ?

@thanveershah
Copy link

Same, resource-id is still empty, any solution yet for this?

HeyImChris pushed a commit to microsoft/react-native-macos that referenced this pull request Oct 26, 2021
* chore: ignore broken Hermes job

* Upgrade metro to 0.64.0

Summary:
Upgrade metro to 0.64.0

Changelog: [Internal]

Reviewed By: cpojer

Differential Revision: D24753886

fbshipit-source-id: af679ec912c5cd8049a998d045ce8a75bf30e5d3

* Build rn-codegen in a temporary directory (facebook#30292)

Summary:
When running yarn install from the codegen directory it will reinstall all dependencies for the react-native workspace inside the react-native package. In my case this caused issues with metro because it would now have 2 copies of it (node_modules/metro and node_modules/react-native/node_modules/metro).

To avoid this copy the react-native-codegen source in a temporary directory and yarn install from there, then copy the built files back.

## Changelog

[Internal] - Build rn-codegen in a temporary directory

Pull Request resolved: facebook#30292

Test Plan: Tested the script in an app with codegen enabled. Fresh install with rn-codegen not built, made sure no extra modules are installed under node_modules/react-native/node_modules.

Reviewed By: yungsters

Differential Revision: D24893216

Pulled By: fkgozali

fbshipit-source-id: 2c372b755632ea6f50ad5d4562248612b349a9a6

* Android OSS: fixed unbound variable error for codegen build script

Summary:
If $FBSOURCE_ENV isn't set, this failed with `/root/react-native/packages/react-native-codegen/android/../scripts/oss/build.sh: line 20: FBSOURCE_ENV: unbound variable`.

This commit fixes https://app.circleci.com/pipelines/github/facebook/react-native/7080/workflows/5cf18a1f-e6d2-4648-8217-d42e9a61fef1/jobs/176451

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24912950

fbshipit-source-id: 113e3dd7f78c75fc3adea0b21c9e38910be8c065

* Use codegen from source in default iOS template apps

Summary:
Add the `react-native-codegen` source to the `react-native` npm package.
Instead of using `react-native-codegen` from npm, the iOS app template will now build the package from source. Doing so removes the need to carefully time `react-native-codegen` npm releases to oss `react-native` releases, as the codegen and the oss release will be cut at the same time.

Changelog: [Internal] - Removed react-native-codegen dependency from iOS app template

Reviewed By: TheSavior

Differential Revision: D24904655

fbshipit-source-id: a07932bc748e2afb9359de584181bcb9dd0810ea

* Fix :ReactAndroid:androidJavadoc task (facebook#30417)

Summary:
Fixes facebook#30415

This is a quick and dirty fix to unblock publish, of excluding a class from Javadoc generation that is importing a class current build logic cannot handle. This is not a long-term fix for the issue.

## Changelog

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

[Internal] [Fixed] - Fix :ReactAndroid:androidJavadoc task

Pull Request resolved: facebook#30417

Test Plan: Tested that the task now completes locally.

Reviewed By: lunaleaps

Differential Revision: D25041282

Pulled By: fkgozali

fbshipit-source-id: f774ab30a09db473178e2a51c77860e4985dd8e3

* fix android npm (facebook#30452)

* fix: pin hermes-engine to 0.7.x

* Use react-native-codegen@0.0.6 in new app template

Summary:
Use pre-built react-native-codegen library from npm in the iOS app template.
Built react-native-codegen from source when used with RNTester.
Published react-native-codegen@0.0.6.

Changelog:
[iOS][Added] - Use react-native-codegen in iOS app template
[Internal] - Bump react-native-codegen: 0.0.6

Reviewed By: fkgozali

Differential Revision: D25128036

fbshipit-source-id: f294c23b9b911aae6f404edc01b62426fb578477

* chore: updated url of deprecated modules (facebook#30422)

Summary:
Part of react-native-community/releases#207

Migrate warnings in index.js to point to new lean core repos

NOTE: some npm modules has been transferred to new nom namespace, such as `react-native-picker/picker` `react-native-async-storage/async-storage` `react-native-masked-view/masked-view`.
Some lean core repo has been transferred to new repo, but its npm namespace remains the same. ex: clipboard module exists in react-native-clipboard/clipboard repo, but npm package name is still `react-native-community/clipboard` (they're planned to be migrated in the future)

## Changelog

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

[General] [Changed] - Migrate warnings in index.js to point to new lean core repos

Pull Request resolved: facebook#30422

Test Plan:
- Updated repo URL can be accessed
- Updated npm package can be installed

Reviewed By: rickhanlonii

Differential Revision: D25077750

Pulled By: cpojer

fbshipit-source-id: b736ea449835bdf3d2a2f85e5c86e5253b90db78

* Add possibility to disable buttons in action sheet ios (facebook#28979)

Summary:
_**Fixed**_ version of [the previous PR](facebook#28792) after reverting [changes](facebook@c8d678a#commitcomment-39299254)

----

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

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

`ActionSheetIOS` documentation - PR facebook/react-native-website#1898

## Changelog

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

Pull Request resolved: facebook#28979

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

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

Reviewed By: sammy-SC

Differential Revision: D21727497

Pulled By: PeteTheHeat

fbshipit-source-id: 749b6c623eb8a44fe2bd96829ce89be5310e2368

* [0.64.0-rc.0] Bump version numbers

* chore: revert changes to test-manual-e2e.sh

* fix: android artifacts in publish-npm.js

* chore: Bump CLI to ^5.0.1-alpha.0 (facebook#30420)

Summary:
Upgrading CLI to latest. This diff is intended to be cherry-picked to 0.64.

cc grabbou kelset alloy

[Internal] [Changed] - Bump CLI to ^5.0.1-alpha.0

Pull Request resolved: facebook#30420

Test Plan: None

Reviewed By: MichaReiser

Differential Revision: D25063261

Pulled By: cpojer

fbshipit-source-id: e1788fd40db2b00daaf888e7b2afaf708ade5451

* [0.64.0-rc.1] Bump version numbers

* Fix cannot working Modal's onDismiss. (facebook#29882)

Summary:
Fixes: facebook#29455

Modal's onDismiss is not called on iOS.
This issue occurred the commit facebook@bd2b7d6 and was fixed the commit facebook@27a3248.
However, the master and stable-0.63 branches do not have this modified commit applied to them.

## Changelog

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

[iOS] [Fixed] - Modal's onDismiss prop will now be called successfully.

Pull Request resolved: facebook#29882

Test Plan:
Tested on iOS with this change:

1. Set function Modal's onDismiss prop.
1. Set Modal's visible props is true. (show Modal)
1. Set Modal's visible props is false. (close Modal)
1. The set function in onDismiss is called.

Reviewed By: shergin

Differential Revision: D24648412

Pulled By: hramos

fbshipit-source-id: acf28fef21420117c845d3aed97e47b5dd4e9390

* Integrate Native Module codegen into Xcode build pipeline (facebook#30449)

Summary:
Move the codegen invocation out of Podfiles and into the FBReactNativeSpec Pod itself. With this change, developers do not need to modify their existing project's Podfiles, and yet the codegen will be integrated into their projects automatically by way of the FBReactNativeSpec Pod.

This is accomplished in part by injecting a script build phase into the Pods Xcode project that is generated by CocoaPods. The build phase will save the output of the codegen script to a log in the derived files directory. The codegen will be executed if the codegen log file is not present, or if the contents of the Libraries directory has changed.

The codegen will thus be invoked in these situations:

**RNTester:**
* When `packages/rn-tester/RNTesterPods.xcworkspace` is built, if the codegen output logfile is not present or if the input files have changed.

**OSS React Native apps:**
* When `ios/AwesomeProject.xcworkspace` is built, if the codegen output file is not present or if the input files have changed. Normally, this should not happen, as we do not expect folks to update the contents of `node_modules/react-native/Libraries`.

Pull Request resolved: facebook#30449

Changelog: [Internal] - Moved codegen invocation out of Podfile and into FBReactNativeSpec Pod

Reviewed By: fkgozali

Differential Revision: D25138896

fbshipit-source-id: 4779f822459cea2c30fd544eee19a49e8d80153d

* Fix Circle CI iOS Tests: Make FBReactNativeSpec dir as needed

Summary:
Quick fix for Circle CI: Ensure FBReactNativeSpec dir exists before touching files.

Changelog:
[Internal]

Reviewed By: fkgozali

Differential Revision: D25285573

fbshipit-source-id: 8dec496856c90accc687648d7068aadfea24d72b

* Fix path to react-native-codegen

Summary:
The wrong value for the path to react-native-codegen was being used. The issue was introduced during the refactoring of this script for use in FBReactNativeSpec.podspec.

Changelog: [Internal]

Motivation:

Reviewed By: fkgozali

Differential Revision: D25290355

fbshipit-source-id: 5a46c680e7ea41157b03cf54a640a8816fb682b3

* Update template devDependencies (facebook#30489)

Summary:
Update template devDependencies before 0.64.0 release

[JavaScript] [Changed] - Update devDependencies (`babel/core` to `7.12.9`, `babel/runtime` to `7.12.5`, `react-native-community/eslint-config` to `2.0.0`, `babel-jest` to `26.6.3`, `eslint` to `7.14.0` and `jest` to `26.6.3`)

Pull Request resolved: facebook#30489

Test Plan:
- [ ] Check babel
- [ ] Check eslint
- [ ] Check jest

Reviewed By: lunaleaps

Differential Revision: D25377357

Pulled By: TheSavior

fbshipit-source-id: fd8e1992860a7fbae710898fbee249e9c36d2229

* Add instructions to template/ios/Podfile for enabling hermes (facebook#30461)

Summary:
Just thought I'd add these instructions so devs don't have to check the docs. Also, it makes iOS match Android with instructions in the configuration files
## Changelog
N/A (in my opinion)

Pull Request resolved: facebook#30461

Test Plan: N/A (because not a code change)

Reviewed By: hramos

Differential Revision: D25309687

Pulled By: TheSavior

fbshipit-source-id: a1907089b9d2e7fe6f2498ce27129c3ae65f7c9a

* Bump Hermes to 0.7.2

https://github.com/facebook/hermes/releases/tag/v0.7.2 is out so we can bump the pod version 🎉

Question:
Is `~> 0.7.2` too strict? Would `>= 0.7.2` be better?
Also, It doesn't look like we are restricting any version on the trunk?

* fix: default template on iOS (facebook#30571)

Summary:
Recently introduced steps to run Hermes accidentally removed `!` from the `use_react_native`, causing `pod install` to fail with an error.

## Changelog

[INTERNAL] [iOS] - Fix Podfle in default template

Pull Request resolved: facebook#30571

Test Plan: Run `pod install` with this file and it should work.

Reviewed By: appden

Differential Revision: D25537263

Pulled By: TheSavior

fbshipit-source-id: da7f21775cbe641e34aded87a92c696539f4d5c3

* fix: building in release mode for simulator (facebook#30543)

Summary:
Fixes facebook#29984

Right now, running a React Native application with Xcode 12 in Release mode on an iPhone Simulator will fail with something like below:

> [some file path], building for iOS Simulator, but linking in object file built for iOS, file '[some file path]' for architecture arm64

The best explanation of this issue has been provided by alloy in facebook#29984:

> This issue has started coming up with Xcode 12 and support for the new ARM based Macs, as `arm64` now no longer can be assumed to _only_ be for iOS devices. This means Xcode 12 will now also build for `arm64` simulator SDKs and it has become ambiguous if an arch slice in a prebuilt binary is meant for a simulator or device.
>
> In any case, for now this means that you can configure your Xcode project to exclude `arm64` when building for any iOS simulator SDK.

This PR implements aforementioned workaround.

## Changelog

[FIX] [IOS] - Fix running React Native project with Xcode 12 in Release on iPhone Simulator

Pull Request resolved: facebook#30543

Test Plan: Switch your scheme to Release and run the app on simulator. Will complete w/o issues.

Reviewed By: appden

Differential Revision: D25537295

Pulled By: TheSavior

fbshipit-source-id: 2dc05cb80e59f1d95d2a84ab55ed6a5b5446411c

* Exclude `i386` from valid architectures when building with Hermes on iOS (facebook#30592)

Summary:
When building React Native application in Release mode for an iPhone Simulator _and_ targeting `armv7`, Xcode will build all architectures (due to `ONLY_ACTIVE_ARCH` set to `false`, unlike in Debug mode). As a result, Xcode will try building for `i386` (32-bit iPhone Simulator), which fails as we don’t build Hermes binaries for `i386`.

Fix is to disable `i386`, since it is not supported by `Hermes` and certain `Folly` features.

## Changelog

[IOS] [BREAKING] - `i386` architecture will be automatically disabled when Hermes is being used. This might be potentially breaking for your workflow if you target `armv7` devices, as you will no longer be able to test on the simulator.
[IOS] [FEATURE] - Replace `flipper_post_install` with `react_native_post_install` hook. Will automatically detect if Flipper is enabled.

Pull Request resolved: facebook#30592

Test Plan: Run React Native application with Hermes enabled (or Flipper) in Release mode and it should work just fine.

Reviewed By: appden

Differential Revision: D25564738

Pulled By: TheSavior

fbshipit-source-id: e786ab73fb0a77de5869cf9e5999726c7d29f1d4

* Fix infinite loop in KeyboardAvoidingView

Summary:
Changelog: [General][Fixed] Fix stalling UI due to a bug in KeyboardAvoidingView

I introduced this bug in D22764192 (facebook@b08fff6).

The stalling was caused by onLayout in JavaScript triggering native layout which called onLayout in JavaScript without terminating condition.

The fix is to only cause native layout once from JavaScript's onLayout function. This makes sure both Fabric and Paper works correctly and UI stall isn't caused.

Resolves:
facebook#30495
facebook#30532

Reviewed By: TheSavior

Differential Revision: D25522362

fbshipit-source-id: 602e540bb1c40ae4f421b3e6ebc5a047cd920c17

* [0.64.0-rc.2] Bump version numbers

* Expose the testID to black-box testing frameworks on Android (facebook#29610)

Summary:
There has been a long-standing issue where black-box testing frameworks like Appium and Xamarin UITest have not been able to access the `testID` view prop for Android (see facebook#7135). A natural place for this to be exposed is via a view's `resource-id`. The `resource-id` is what I have used when working on UIAutomator-based tests for native Android apps and is a non-localized, development-only identifier. As mentioned in the linked ticket, you can dynamically set the resource-id using the view's AccessibilityNodeInfo. This change simply checks to see if a testID is provided for a view and then exposes it through the view's accessibility node delegate.

## Changelog

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

[Android] [Fixed] - Fixes facebook#7135,  facebook#9942, and facebook#16137. Display the `testID` as the `resource-id` for black-box testing frameworks

Pull Request resolved: facebook#29610

Test Plan:
I used the `uiautomatorviewer` tool to verify that the resource-id is populated with the `testID` of a few different views of the RNTester app.
<img width="912" alt="Screen Shot 2020-08-10 at 3 38 27 PM" src="https://user-images.githubusercontent.com/875498/89838534-55044100-db20-11ea-9be2-ba507a81f6fb.png">
<img width="1096" alt="Screen Shot 2020-08-10 at 3 40 41 PM" src="https://user-images.githubusercontent.com/875498/89838542-5897c800-db20-11ea-9895-462c6fea1130.png">

Reviewed By: JoshuaGross

Differential Revision: D25799550

Pulled By: fkgozali

fbshipit-source-id: e64ff1b90fb66b427fce7af533aa94792cfbcad3

* Remove dependency on Folly in TurboModuleUtils.h (facebook#30672)

Summary:
The TurboModuleUtils.h includes "folly/Optional.h" which is not used and creates an unnecessary dependency on Folly.
In this PR we remove this unnecessary include.

It is required for the microsoft/react-native-windows#6804 where we add an experimental support for the C++ TurboModules. While the C++ TurboModules use the same JSI and TurboModule code defined in react-native, we provide a layer that let them to work over the ABI-safe Microsoft.ReactNative.dll boundary. The RNW Nuget distribution with DLL files includes a few source files to create native/turbo modules that work through the ABI-safe API. The TurboModuleUtils.h is one of such files. By removing the dependency on Folly we reduce requirements for the native module code. After this PR is merged we will remove the fork of the TurboModuleUtils.h  added in microsoft/react-native-windows#6804.

## Changelog

[Internal] [Fixed] - Remove dependency on Folly in TurboModuleUtils.h

Pull Request resolved: facebook#30672

Test Plan:
The change does not bring any functional changes. It may only affect code compilation where some code may depend on TurboModuleUtils.h when it needs the "folly/Optional.h". The fix is add the `#include <folly/Optional.h>` there explicitly.

I had run the iOS tests and they passed:
```
yarn
pod install in packages\rn-tester
./scripts/objc-test.sh test
```

Reviewed By: mdvacca

Differential Revision: D25758927

Pulled By: fkgozali

fbshipit-source-id: 347d8f6bc333a3df67095ea0dc7221c818432fab

* Avoid eating clicks/taps into ScrollView when using physical keyboard (facebook#30374)

Summary:
This is an extension of facebook#29798 which was reverted due to cases where the soft keyboard could not be dismissed.

## Changelog

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

[General] [Fixed] - Avoid eating clicks/taps into ScrollView when using physical keyboard

Pull Request resolved: facebook#30374

Test Plan: Validated with iOS simulator that taps on default ScrollView will dismiss soft keyboard and be eaten if open, but taps are not eaten when emulating a connected physical keyboard.

Reviewed By: kacieb

Differential Revision: D24935077

Pulled By: lyahdav

fbshipit-source-id: 19d9cf64547e40a35f9363896e3abbdccb95b546

* Update iOS Fabric-related files to compile on OSS (facebook#29810)

Summary:
Original PR contents:

This pull request updates the Podspecs and associated build scripts, and some source files so they build on OSS. RNTester now compiles with `fabric_enabled` again.

The following changes have been made:

 * Various spots that were pointing to the old `ReactCommon/fabric` location have now been updated to `ReactCommon/react/renderer`
 * Files that were attempting to use internal FB header `FBRCTFabricComponentsPlugins.h` were changed to use `RCTFabricComponentsPlugins.h`
 * `RCTFabricComponentsPlugins` in OSS was updated to include the `Image` fabric component (thanks tsapeta)
 * Replaced old `generate-rncore.sh` build script with new `generate-rncore.js` script which does not require `flow-node` and uses the `react-native-codegen` API directly, so there is no longer any need for an interim `schema-rncore.json` file.
 * Updated Yoga podspec which wasn't fully synced with changes from the main Yoga repo
 * Updated Fabric podspec with additional needed subspecs

Additions to PR by hramos:
* Replaced use of generate-rncore scripts with the original generate-native-modules-specs.sh script, which is now generate-specs.sh and supports both codegen for Native Modules and Components now (TurboModules/Fabric).
* Codegen now runs at build time as part of the Xcode build pipeline instead of as part of `pod install`. The build script is injected by the FBReactNativeSpec pod, as the pod is part of both Fabric and non-Fabric builds.

[General] [Fixed] - RNTester compiles with `fabric_enabled` again

Pull Request resolved: facebook#29810

Test Plan:
RNTester now compiles and runs in the simulator again when `fabric_enabled` is set to `true`.

```
cd xplat/js/react-native-github/packages/rn-tester
USE_FABRIC=1 pod install
open RNTesterPods.xcworkspace
```

Reviewed By: fkgozali

Differential Revision: D24058507

Pulled By: hramos

fbshipit-source-id: 8b2ea3694e6cb9aa23f83f087e2995fd4320e2bb

* Use Fabric builds in iOS tests (facebook#30639)

Summary:
Pull Request resolved: facebook#30639

# Changelog:
[Internal] Enable Fabric builds in iOS tests on Circle CI and Sandcastle.

Reviewed By: fkgozali

Differential Revision: D25700257

fbshipit-source-id: a250dbc9904efec9ded130912a993638f0992373

* Add use_react_native_codegen!

Summary:
Consolidate CocoaPods codegen scripts under a single `use_react_native_codegen!` method in `react_native_pods.rb`.

This is the first step towards making the codegen scripts library-agnostic. There are still a handful of hardcoded assumptions in place (e.g. the output directory structure, the use of a separate directory for components), but with some work one would be able to add codegen support to arbitrary CocoaPods podspecs.

The codegen script no longer takes a CODEGEN_PATH argument, and will instead attempt to use the local react-native-codegen package if available, and fallback to using the node_modules/react-native-codegen package if not.

## Usage

The `use_react_native_codegen!` method has two arguments:

- `spec`, a pod [Specification](https://www.rubydoc.info/github/CocoaPods/Core/Pod/Specification) object.
- `options`, an optional object. Supported keys:
  - `:srcs_dir`, the path to your JavaScript sources. Your native module or component specs should be located somewhere in this directory.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25728053

fbshipit-source-id: feec587b656d5b220598ce6196ea6bb34a9580a9

* Optionally override codegen script defaults via envvars

Summary:
The codegen helper script, `generate-specs.sh`, is being used to generate code for the FBReactNativeSpec and React-Fabric/rncore pods. The script now supports overriding several defaults by setting the following environment variables:

- SRCS_DIR: Path to JavaScript sources, defaults to $RN_DIR/Libraries/
- LIBRARY_NAME: Defaults to FBReactNativeSpec
- MODULES_OUTPUT_DIR: Defaults to Libraries/$LIBRARY_NAME/$LIBRARY_NAME
- COMPONENTS_LIBRARY_NAME: Defaults to rncore
- COMPONENTS_OUTPUT_DIR: Defaults to ReactCommon/react/renderer/components/$COMPONENTS_LIBRARY_NAME

The CocoaPods codegen integration has been updated to take advantage of these.

**Example CocoaPods usage:**

```
# packages/rn-tester/NativeModuleExample/RNTesterSpecs.podspec
Pod::Spec.new do |s|
  s.name = "RNTesterSpec"
  # ...
  use_react_native_codegen!(s, { :srcs_dir => __dir__, :modules_output_dir => __dir__ })
end
```

Changelog:
[Internal]

Reviewed By: fkgozali

Differential Revision: D25738466

fbshipit-source-id: c68f5a3cd0996283a7af287e992e2f973024f44c

* Make codegen more reliable on iOS (facebook#30792)

Summary:
This addesses a few issues I noticed while migrating my app to the new build-time codegen on iOS.

1. I noticed random failures because of codegen on iOS. This is mostly due to the fact the codegen output files are not specified in the xcode script. The only reason it works relatively fine currently is because the codegen output is inside the input files directory. This has the side effect of causing files to be regenerated every build, then causes all core modules to be recompiled which adds up a significant amount of time to rebuilds. To fix this I added the generated files to the script phase output and moved the FBReactNativeSpec dir outside of the codegen source (Libraries). I moved it to the React directory as this seemed to make sense and is where a lot of iOS files are as well as the core modules. Note this might require internal changes. This removes the circular dependency between our build phase input and output so consecutive builds can be cached properly.

2. Add `set -o pipefail` to the xcode script, this helped propagate errors properly to xcode because of the `| tee` pipe so it fails at the script phase and not later with a header not found error. Also add `2>&1` to pipe stderr to stdout so errors are also captured in the log file.

3. Add the `-l` flag to the bash invocation to help finding the yarn binary. With my setup yarn is added to the system PATH in my user .profile. Adding this file will cause bash to source the user environment which xcode scripts does not by default. I think this will help with most setups.

4. If yarn is not found the `command -v yarn` would make the script exit without any output because of the -e flag. I made a change to ignore the return code and check later if YARN_BINARY is set and have an explicit error message if not.

[iOS] [Fixed] - Make codegen more reliable on iOS

Pull Request resolved: facebook#30792

Test Plan:
Tested various project states to make sure the build always succeeds in RN tester:

- Simulate fresh clone, remove all ignored files, install pods, build
- Build, delete FBReactNativeSpec generated files, build again
- Build, build again, make sure FBReactNativeSpec is cached and not rebuilt
- Make the script fail and check that xcode shows the script error logs properly

![image](https://user-images.githubusercontent.com/2677334/105891571-c8badd00-5fde-11eb-839c-259d8e448523.png)

Note: Did not test fabric

Reviewed By: fkgozali

Differential Revision: D26104213

Pulled By: hramos

fbshipit-source-id: e18d9a0b9ada7c0c2e608d29ffe88087f04605b4

* Invoke `node` directly in generate-specs.sh (facebook#30781)

Summary:
Currently, Codegen bash wrapper (`generate-specs.sh`) for Xcode invokes JS-based Codegen tooling via `yarn --silent node <...>`. This breaks both:

- when Yarn is not installed (if NPM is used), for obvious reasons
- when Yarn v2 ("Berry") is active

This PR changes the way `generate-specs.sh` locates `node` executable to the following algorithm:

- use the path provided in the `NODE_BINARY` env var
- if `NODE_BINARY` env var is not defined, find `node` with `command -v node`

## Changelog

[iOS] [Fixed] - Fix Codegen silently failing when Yarn is not installed, or when Yarn v2 is active.

Pull Request resolved: facebook#30781

Test Plan:
### Case 1 (no Yarn installed)

1. Ensure `yarn` is not present in PATH
2. Run Xcode build
3. Check that Codegen artifacts are produced

### Case 2 (Yarn v2 is used)

1. Ensure `yarn` is running in the v2 ("Berry") mode
2. Run Xcode build
3. Check that Codegen artifacts are produced

Reviewed By: fkgozali

Differential Revision: D26187081

Pulled By: hramos

fbshipit-source-id: 77d3089f523b8c976d8223b77ff9553cb6cf68a5

* chore: bump codegen script

* [0.64.0-rc.3] Bump version numbers

* Update flipper in RNTester and template (facebook#31010)

Summary:
allow-large-files

RN Tester is using an old version of Flipper. This will help testing regressions in the latest version (which is installed when starting a new project). This also fixes an issue where libevent is incompatible between the one in flipper and when using hermes on iOS. To fix it I changed to use the version published on cocoapods instead of using a local podspec (see facebook/flipper#1916).

[General] [Changed] - Update flipper

Pull Request resolved: facebook#31010

Test Plan:
- Tested that RN tester builds and flipper works with hermes enabled / disabled and fabric on iOS
- Tested that RN tester builds and flipper works on Android

Reviewed By: fkgozali

Differential Revision: D26592317

Pulled By: PeteTheHeat

fbshipit-source-id: 2cd278c7a51b1859dab0465846b061221f07d3f6

* Generalize node search logic

* fix: React Native CodeGen integration for 0.64-stable (facebook#31027)

* fix: disable fabric

* chore: fix conflict in Podfile.lock

* [0.64.0-rc.4] Bump version numbers

* Fix RefreshControl layout when removed from window (facebook#31024)

Summary:
Since iOS 14 refresh control is sometimes visible when it shouldn't. It seems to happen when it is removed and added back to the window. This repros easily when using react-native-screens with react-navigation tabs. Inactive tabs are detached from the window to save resources.

Calling endRefreshing when refresh control is added to the window fixes the layout. It will also be called on first mount where it is not necessary, but should be a no-op and didn't cause any issues. I also decided to call it for all ios versions, although it is only needed on iOS 14+ to avoid forking behavior more.

## Changelog

[iOS] [Fixed] - Fix RefreshControl layout when removed from window

Pull Request resolved: facebook#31024

Test Plan:
Before:

https://user-images.githubusercontent.com/2677334/108666197-93ea5a80-74a4-11eb-839b-8a4916967bf8.mov

After:

https://user-images.githubusercontent.com/2677334/108666223-9ea4ef80-74a4-11eb-8489-4e5d257299c8.mov

Reviewed By: shergin

Differential Revision: D26590759

Pulled By: PeteTheHeat

fbshipit-source-id: b8c06068a24446b261cbeb88ff166289724031f1

* fix: restore refresh control fix

* chore: Update React.podspec to require cocoapods >= 1.10.1

* Fixing the git attrs for all the people and all the files and all future 🙌

* [0.64.0] Bump version numbers

* Upgrade react-hooks rules

Summary:
Upgrades the `react-hooks` eslint-rules to `4.2.0`

Changelog:
[Internal]

Reviewed By: GijsWeterings

Differential Revision: D26366235

fbshipit-source-id: 04628e8f2a6c56eacba516d877df143c6c81adb8

* Some more changes for bringing up RN64 in devmain Android (#861)

* Build & Packaging changes for bringing up RN64 in devmain

* Fixing gradle clean

* Disable gradle clean in PR builds

* Add explicit dependency on fbjs to RNTester

This is needed after upgrading to v5.0.1-alpha.0 of the CLI tools.

* Fix for submit button disappearing bug in comments (#862)

* Add the missing android folder to files in package.json

* Fix for submit button disappear bug in comments

Co-authored-by: Mayuresh Gharpure <Mayuresh.Gharpure@microsoft.com>

* Update Android patches

Co-authored-by: Mike Grabowski <grabbou@gmail.com>
Co-authored-by: Micha Reiser <mreiser@fb.com>
Co-authored-by: Janic Duplessis <janicduplessis@gmail.com>
Co-authored-by: Kevin Gozali <fkg@fb.com>
Co-authored-by: Nick Gerleman <nick@nickgerleman.com>
Co-authored-by: Dulmandakh <dulmandakh@gmail.com>
Co-authored-by: Héctor Ramos <hramos@fb.com>
Co-authored-by: Jesse Katsumata <jesse.katsumata@gmail.com>
Co-authored-by: Luke Walczak <lukasz.walczak.pwr@gmail.com>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Koichi Nagaoka <emmeleia@me.com>
Co-authored-by: Dmitriy Shishkin <6ast3r@gmail.com>
Co-authored-by: Steven Conaway <steven.conaway@icloud.com>
Co-authored-by: Xuan Huang (黄玄) <jsx@fb.com>
Co-authored-by: Samuel Susla <samuelsusla@fb.com>
Co-authored-by: Jayme Deffenbaugh <jdeffenbaugh@me.com>
Co-authored-by: Vladimir Morozov <vmorozov@microsoft.com>
Co-authored-by: empyrical <empyrical@outlook.com>
Co-authored-by: Ivan Moskalev <ivan.moskalev@gmail.com>
Co-authored-by: Anandraj <anandrag@microsoft.com>
Co-authored-by: Mayuresh Gharpure <gharpuremayuresh@gmail.com>
Co-authored-by: Mayuresh Gharpure <Mayuresh.Gharpure@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for resource-id