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

[iOS] [MapView] Make the region prop only an initial region #5130

Closed
jedlau opened this issue Jan 5, 2016 · 8 comments
Closed

[iOS] [MapView] Make the region prop only an initial region #5130

jedlau opened this issue Jan 5, 2016 · 8 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@jedlau
Copy link
Contributor

jedlau commented Jan 5, 2016

Use case: Annotations are displayed on a map, and the initial map region is set so that all of the annotations are visible. Annotations are moving around, which triggers re-renders. In addition, the user should be able to pan/zoom around the map, so onRegionChange and onRegionChangeComplete attempt to capture region changes and set those in the state; in this way, the map region doesn't reset to the initial map region whenever a re-render occurs.

render: function() {
   ...
    return (
      <MapView
        style={styles.map}
        region={this.state.region}
        annotations={annotations}
        showsPointsOfInterest={false}
        onRegionChange={this.onRegionChange}
        onRegionChangeComplete={this.onRegionChangeComplete}
      />
    );
  },

  onRegionChange: function(region) {
    this.setState({ region });
  },

  onRegionChangeComplete: function(region) {
    this.setState({ region });
  },

Problem: Setting the updated region in the state doesn't allow for a smooth panning/scrolling experience on the map, due to the delay in updating the state. After a couple of pans or zooms, the map freezes, presumably because it is using the current region saved in the state, and not a more updated region. Wait 1-2 seconds, and the map can be panned/zoomed again, presumably because the region has now been updated in the state.

Suggestion: Make the MapView's region prop an initial region. That way, only annotation updates trigger re-renders. onRegionChange and onRegionChangeComplete can then be used as delegate methods to perform work on the new region (analogous to MKMapViewDelegate's mapView:regionWillChangeAnimated:), rather than saving the region itself for the purposes of map rendering.

@facebook-github-bot
Copy link
Contributor

Hey jedlau, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If you don't know how to do something or something is not working as you expect but not sure it's a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!

@pedro
Copy link

pedro commented Mar 17, 2016

+1, having the same issue – if I use onRegionChange to save the current region and feed that back into the <MapView> things get super slow/broken.

@charpeni
Copy link
Contributor

charpeni commented Jun 2, 2016

I would recommend you to use react-native-maps as it is more feature-complete than our internal implementation.

@charpeni
Copy link
Contributor

charpeni commented Jun 2, 2016

@facebook-github-bot bugfix

@charpeni
Copy link
Contributor

charpeni commented Jun 2, 2016

@facebook-github-bot close

@facebook-github-bot
Copy link
Contributor

Hey @jedlau, we're a small team and rely on the community to fix issues that don't affect fb apps. If you're sure this is a bug can you send a pull request with a fix?

@charpeni
Copy link
Contributor

charpeni commented Jun 6, 2016

@facebook-github-bot close

@ghost
Copy link

ghost commented Jun 6, 2016

@charpeni tells me to close this issue. If you think it should still be opened let us know why.

@ghost ghost closed this as completed Jun 6, 2016
@facebook facebook locked as resolved and limited conversation to collaborators Jun 6, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
This issue was closed.
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

No branches or pull requests

5 participants