Skip to content

Commit

Permalink
Request toolbar layout after drawable loads
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Benjamin-Dobell authored and facebook-github-bot committed Jul 24, 2017
1 parent 4de9d64 commit 63c2ab3
Showing 1 changed file with 1 addition and 0 deletions.
Expand Up @@ -99,6 +99,7 @@ private class ActionIconControllerListener extends IconControllerListener {
@Override @Override
protected void setDrawable(Drawable d) { protected void setDrawable(Drawable d) {
mItem.setIcon(d); mItem.setIcon(d);
ReactToolbar.this.requestLayout();
} }
} }


Expand Down

0 comments on commit 63c2ab3

Please sign in to comment.