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

Request toolbar layout after drawable loads #13876

Closed

Conversation

Benjamin-Dobell
Copy link
Contributor

@Benjamin-Dobell Benjamin-Dobell commented May 9, 2017

Motivation

Fixes #11209

Updating action items in a ToolbarAndroid, or more specifically the native ReactToolbar, after the initial render presently will not always work as expected - typically manifesting itself as new action items not being displayed at all (under certain circumstances).

This seems to be happening because Fresco gets back to us asynchronously and updates the MenuItem in a listener. However when a keyboard is displayed the Toolbar is in a weird state where updating the MenuItem doesn't automatically trigger a layout.

The solution is to trigger one manually.

Test Plan

This is a bit wacky, so I created a sample project:

https://github.com/Benjamin-Dobell/DynamicToolbar

master demonstrates the problem. Run the project, the toolbar action item is scheduled to update every 2 seconds. It works fine until you give the TextInput focus. Once you give it focus the action item disappears and it never recovers (despite on-going renders due to state changes).

You can then checkout the fixed branch, run yarn again, and see that problem is fixed. This branch is using a prebuilt version of React Native with this patch applied. Of course you could (and probably should) also modify master to use a version of RN built by the Facebook CI (assuming that's a thing you guys do).

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: review-needed labels May 9, 2017
@smallpath
Copy link

Works like a charm in my case! thanks very much.

@Benjamin-Dobell
Copy link
Contributor Author

I would really appreciate it if someone from Facebook could take a look at this.

This issue has been present for as long as I've been using React Native and it's a show stopper when trying to update the action bar dynamically on Android e.g. displaying/enabling a "check" (confirm) action item in response to valid text being entered in a text field.

It's just a simple single line fix. The test repository doesn't do anything complicated, I just needed to bundle up some action item images somewhere for testing. All the relevant test code is contained in one file:

https://github.com/Benjamin-Dobell/DynamicToolbar/blob/master/index.android.js

I've been having a lot of trouble making release builds with my current patched master-based fork (nothing to do with this patch, just seems to be due to master being a WIP), so I'd love to see this merged into an official release that I can rely on.

Thanks

@Benjamin-Dobell
Copy link
Contributor Author

Awww, 0.45 was released without this being considered. Please don't let this fix slip into obscurity...

@shergin
Copy link
Contributor

shergin commented Jun 27, 2017

@Benjamin-Dobell Could you please rebase it on master?

@Benjamin-Dobell
Copy link
Contributor Author

@shergin Done.

@forki
Copy link
Contributor

forki commented Jul 20, 2017

any news why this isn't merged?

@forki
Copy link
Contributor

forki commented Jul 20, 2017

I can verify that this change also fixes #13780 - Please please please merge it.

@forki
Copy link
Contributor

forki commented Jul 20, 2017

@Benjamin-Dobell one question:

using your repro works well when I use the apk. but with "reac-native.cmd run-android" I get:

image

we see the same thing when we try to use your fork against our app. Do you know what that issue might be?

@forki
Copy link
Contributor

forki commented Jul 20, 2017

In #15120 I verified that this commit cherry-picked on master is green on CI. Please consider to merge and release it. It's really important for us

@forki
Copy link
Contributor

forki commented Jul 20, 2017

Something is flaky with the Travis build. But seems unrelated

@Benjamin-Dobell
Copy link
Contributor Author

@forki Yeah, I just rebased in hope I'd see some green lights. 1 out of 2, that's not too bad 😉

Regarding the packager issue you encountered; maybe just make sure you're using yarn (there's a yarn.lock but no npm-shrinkwrap.json) and clear the packager cache - otherwise I'm not too sure.

@forki
Copy link
Contributor

forki commented Jul 20, 2017

We use yarn and we did git clean -xdf
Anyway try to close and reopen the PR to rerun the Travis

@hramos
Copy link
Contributor

hramos commented Jul 21, 2017

@Benjamin-Dobell have you pushed your changes after rebasing? I don't see any new commits here. That should trigger Travis to run again.

@forki
Copy link
Contributor

forki commented Jul 21, 2017

Yes he did. But Travis is flaky with unrelated issues

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Jul 22, 2017
@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@forki
Copy link
Contributor

forki commented Jul 24, 2017

@shergin what is the status here? Anything we can do to help?

@facebook-github-bot
Copy link
Contributor

@shergin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@forki
Copy link
Contributor

forki commented Jul 25, 2017

💋

@forki
Copy link
Contributor

forki commented Jul 31, 2017

any chance this can be merge into 0.47-stable? It's still not in RN 047-rc5

@hramos
Copy link
Contributor

hramos commented Jul 31, 2017

@forki you should comment on #14840

grabbou pushed a commit that referenced this pull request Aug 1, 2017
Summary:
Fixes #11209

Updating action items in a `ToolbarAndroid`, or more specifically the native `ReactToolbar`, after the initial render presently will not always work as expected - typically manifesting itself as new action items not being displayed at all (under certain circumstances).

This seems to be happening because Fresco gets back to us asynchronously and updates the `MenuItem` in a listener. However when a keyboard is displayed the `Toolbar` is in a weird state where updating the `MenuItem` doesn't automatically trigger a layout.

The solution is to trigger one manually.

This is a bit wacky, so I created a sample project:

https://github.com/Benjamin-Dobell/DynamicToolbar

`master` demonstrates the problem. Run the project, the toolbar action item is scheduled to update every 2 seconds. It works fine _until_ you give the `TextInput` focus. Once you give it focus the action item disappears and it never recovers (despite on-going renders due to state changes).

You can then checkout the `fixed` branch, run `yarn` again, and see that problem is fixed. This branch is using a prebuilt version of React Native with this patch applied. Of course you could (and probably should) also modify `master` to use a version of RN built by the Facebook CI (assuming that's a thing you guys do).
Closes #13876

Differential Revision: D5476858

Pulled By: shergin

fbshipit-source-id: 6634d8cb3ee18fd99f7dc4e1eef348accc1c45ad
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. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ToolbarAndroid Actions Disappear On Change With Input Focus
6 participants