Permalink
Browse files

Request toolbar layout after drawable loads

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 63c2ab3eb13c50e1cdd686b1f8913d569a7af53a
Showing with 1 addition and 0 deletions.
  1. +1 −0 ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbar.java
@@ -99,6 +99,7 @@ public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable
@Override
protected void setDrawable(Drawable d) {
mItem.setIcon(d);
ReactToolbar.this.requestLayout();
}
}

0 comments on commit 63c2ab3

Please sign in to comment.