Skip to content

Modal not hiding when setState updates are done in try / catch and the response is quick #28753

@lucastonon

Description

@lucastonon

Hi, I would like to reopen #10417

I am having this problem for a while and the only solution that worked for me was to create a timeout big enough that even in slow devices it works.

When using try/catch, if the work is finished quickly (quick api responses for instance), when we setState({showLoader: false}) it won't remove the Modal and we will have to close and run the app again to clear it.

I am going to use the same example as the issue link mentioned

makeRequest = () => {
  this.setState({ loading: true })
  Media.request(url)
  .then(response => {
    // todo
  }, e => {
    this.setState({ loading: false })
  })
}

render() {
  return(
    <View>
      <Modal
          animationType={'slide'}
          transparent={false}
          visible={this.state.loading}
          onRequestClose={() => {} }
       >
        <View></View>
      </Modal>
      <Text onPress={this.makeRequest}>Do Magic</Text>
    </View>
  )
}

e7a3ffba-9406-11e6-9731-bfbe503324b2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ModalNeeds: Author FeedbackNeeds: Environment InfoPlease run `react-native info` and edit your issue with that command's output.StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions