-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
onRegionChangeComplete props Callback triggering infinitely without any user input on Android. #846
Comments
if you use region prop along with onRegionChangeComplete , the onRegionChangeComplete is called as a callback. onRegionChangeComplete is called whenever onChange event occurs natively. it could be due to user dragging map, animation on map or even setting up of gps location. If possible another prop should be added like onPanDragComplete so that we get callback only when user drags map and finishes dragging it. |
Did you make it work and how? i am also having problem with infinite loop. Since i need both region and onRegionChangeComplete props |
This is my new mapComponent. It turns out i was using region prop and was only setting state of region. removing it also works.
The _onChange method is called whenever any event happens.If whatever you write in onRegionChangeComplete triggers a call to region prop , region prop in itself triggers an _onChange event which causes onRegionChangeComplete to call. This quickly spirals to an infinite loop each callback trigering each other. You can put logs in MapView.js file to see it for yourself. I think something like a panDragComplete in this case would do the trick. I am not sure if mapkit or google maps provider provide a native event for this or not. But until then make sure onRegionChangeComplete has code without any side effects. Or if you can't do that, remove region prop, it worked for me |
Thanks for the input i will try to edit the component so i might get something (or will at the do without region change until they make something like you suggested). But as you said we need something like panDragComplete since everytime i click on the marker it triggers onRegionChangeComplete and re-renders. I have to find a workaround. But i think you should leave this issue open. |
I have an app flow like so:
On iOS this works normally. OnRegionChangeComplete gets called twice, as you would expect. On android, as @akshay2604 mentioned, if a re-render or state change happens during an onRegionChangeComplete callback, then onRegionChangeComplete callbacks get called repeatedly causing an infinite loop. In order to work around this for now I implemented a check in my onRegionChangeComplete callback to determine if the region has actually changed. If not, return early instead of dispatching actions. This at least eliminates multiple HTTP requests or re-renders occurring. Example Code:
|
I just had the same problem i.e.:
and what fixed it was setting the "region" state variable in my onRegionChangeComplete() callback. I am now setting it to the argument being passed to onRegionChangeComplete(). I'm not entirely sure why this fixes it, but I assume it has something to do with the state being the same so it doesn't trigger additional render() calls? I'm curious if this works for anyone else. Cheers |
I'm use |
Should be fixed by PR #1710 |
I discourage controlling region state. Try this: #209 (comment) Anyway it should be fixed with the PR above. |
I found that when you zoom to max. The region from onRegionChangeComplete will be continue changing. The change is so small and about 15/16 significant decimal digits. Is it related to the precision? |
@tsangwailam did u find a solution? I have the same problem, it only moves by itself when zoom is on max |
Yes, you're right. Adding |
Did you get a fix for this? |
For anyone using GoogleMaps, this is how I fixed it (version 1.2.0):
note: gesture.isGesture indicates if the change was made by user or animation. |
Thanks |
i am not using fitToSuppliedMarkers as another issue mentioned, only plain MapComponent . For some reason on Android onRegionChangeComplete is being called infinitely many times. However it is working correctly on IOS.
React native - 0.35
react-native-maps - 0.10.4
The text was updated successfully, but these errors were encountered: