-
Notifications
You must be signed in to change notification settings - Fork 117
[annotation] Update DraggableAnnotationController for multiple draggable managers (#863, #883) #1125
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
[annotation] Update DraggableAnnotationController for multiple draggable managers (#863, #883) #1125
Conversation
|
Hey @Ph0tonic, thanks for your contribution again! Unfortunately, I don't think this is an approach that we'd like to take. Having multiple detectors running is going to get inefficient. To resolve the issue, I'd rather explore the option of having one, public instance of the draggable controller into which we can inject multiple annotation managers, instead of each annotation manager creating its own draggable controller. |
|
Ok, I see, I will try to turn draggable controller into a singleton such has to minimize the number of detectors. |
|
@LukasPaczos Here is a completely new implementation which turns DraggableController into a singleton. Would this be closer to an approach you would take ? The tests are failing because I'm not able to run |
c60d6d3 to
84e258d
Compare
|
I had a look at the // This file is generated.I let those like they currently are. Please let me know if I can do anything else @langsmith and @LukasPaczos. Thanks |
|
The limitations resolved by this PR would really help me for one of my side project. If we find a viable solution, do you think we might be able to do a release for those next weeks ? |
|
When can we expect this fix in production? |
|
Any updates about this PR ? @LukasPaczos and @langsmith |
I wrote a seperate PR for this issue such as to simplify the review of mapbox#1125. - Fixes mapbox#883 Any review and comment would be much appreciated 👍 @LukasPaczos and @langsmith.
LukasPaczos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for a delayed response, this looks great @Ph0tonic!
Would you also be able to add one test to the DraggableAnnotationControllerTest that runs multiple managers at once? When this and the last comment below is addressed I can rerun the code generation for you to make the CI pass.
| public static synchronized DraggableAnnotationController getInstance(MapView mapView, MapboxMap mapboxMap) { | ||
| if(INSTANCE == null){ | ||
| INSTANCE = new DraggableAnnotationController(mapView, mapboxMap); | ||
| } | ||
| return INSTANCE; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An issue with this singleton approach might occur when the map is recreated, for example in a recycler view, or when transitioning between fragments/activites.
We might need to do something like this, to additionally ensure that we're using the correct instance:
| public static synchronized DraggableAnnotationController getInstance(MapView mapView, MapboxMap mapboxMap) { | |
| if(INSTANCE == null){ | |
| INSTANCE = new DraggableAnnotationController(mapView, mapboxMap); | |
| } | |
| return INSTANCE; | |
| } | |
| public static synchronized DraggableAnnotationController getInstance(MapView mapView, MapboxMap mapboxMap) { | |
| if(INSTANCE == null || this.mapView != mapview || this.mapboxMap != mapboxMap){ | |
| INSTANCE = new DraggableAnnotationController(mapView, mapboxMap); | |
| } | |
| return INSTANCE; | |
| } |
The strong references to mapView and mapboxMap should be dropped when the last removeAnnotationManager is called and the instance is nullified so we shouldn't leak. It'd be great to test this scenario though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right I did not think about that 👍. I updated the code to reflect what you said. Regarding the testing of the last part of your remark, I'm not sure how I can do it.
I wrote a seperate PR for this issue such as to simplify the review of #1125. - Fixes #883 Any review and comment would be much appreciated 👍 @LukasPaczos and @langsmith.
a88bb8d to
0c13d6f
Compare
This is a proposal for fixing #863 and #883.
They are kind of linked together and I foud the solution of the second one during my work so I added it in this PR.
I know that it's not perfect but at least is a simple solution which allow multiple manager to be draggable.
@LukasPaczos and @langsmith I would be happy to have your feedback. 👍