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

ToolbarAndroid Actions Disappear On Change With Input Focus #11209

Closed
ionactual opened this issue Nov 30, 2016 · 9 comments
Closed

ToolbarAndroid Actions Disappear On Change With Input Focus #11209

ionactual opened this issue Nov 30, 2016 · 9 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@ionactual
Copy link

Description

The actions seem to disappear when they are updated if an input is focused. Updating the actions seem to work as long as no inputs are focused.

This did not happen on version 0.29 but breaks on 0.38. I think that there is a related crash on 0.37, but it's more difficult to recreate.

Reproduction

https://rnplay.org/apps/jFEJew

Solution

Unknown.

Additional Information

  • React Native version: 0.38
  • Platform: Android
  • Operating System: MacOS & Linux
@vonovak
Copy link
Contributor

vonovak commented Dec 3, 2016

Not sure exactly why, but this works :D https://rnplay.org/apps/5TeqFg

have you tried not re-creating a new array every time, but change the array in-place?

@ionactual
Copy link
Author

I don't think so: https://rnplay.org/apps/rEcEWw (unless I misunderstood what you meant).

@vonovak
Copy link
Contributor

vonovak commented Dec 5, 2016

the link I attached does work for me, ie. the toolbar gets updated correctly. just by adding the <Text/> but the bug is definitely there and it is in RN itself

@vonovak
Copy link
Contributor

vonovak commented Dec 7, 2016

@DanielMSchmidt you were mentioned in the linked issues, so maybe you'd interested in this one since it provides a nicely isolated repro

In my case the bug shows when I go through a guide that spans several screens - in one there is a textinput and if the user writes something into it, the right action icons will not be displayed on the next screen. If the user skips editing the textinput, the icons are there. I'm 100% sure this is not a problem with my code.

@chenvan
Copy link

chenvan commented Jan 23, 2017

@jaystramel Do you find a solution?

@hirviid
Copy link

hirviid commented Feb 15, 2017

Had the same problem. Don't know why, but a hack like this seems to work:

    <View style={style.root}>
        <ToolbarAndroid
          navIcon={leftItem && leftItem.icon}
          onIconClicked={leftItem && leftItem.onPress}
          title={title}
          titleColor={textColor}
          actions={actions}
          onActionSelected={this.handleActionSelected}
          overflowIcon={require('assets/mobile/more_vert.png')}
          style={style.toolbar}
        >
            {children}
        </ToolbarAndroid>
        {/* Added this Text component ↓ */}
        <Text style={{ height: 0, opacity: 0 }}>
            {JSON.stringify(actions)}
        </Text>
    </View>

@ionactual
Copy link
Author

@chenvan No. I wrote a custom component for the two places we need this. (Sorry the delay, never saw the notification.)

@chenvan
Copy link

chenvan commented Mar 7, 2017

@jaystramel Never mind. I just write a component which is similar to ToolbarAndroid to avoid this problem.

@hramos
Copy link
Contributor

hramos commented Jul 20, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@hramos hramos added the Icebox label Jul 20, 2017
@hramos hramos closed this as completed Jul 20, 2017
facebook-github-bot pushed a commit that referenced this issue Jul 24, 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
grabbou pushed a commit that referenced this issue 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
@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants