Android custom annotation bugfixes.

- Custom annotations would sometimes not get rendered on the screen.
  Haven't nailed down the exact problem, but it was some sort of
  interleaving of operations from adding children and computing custom
  marker views. Moving the marker view stuff to when the map finishes
  loading resolves this.
- The adapter for the react native marker views now handles the caching
  behaviour correctly and re-uses views when they are available.
- Make sure each layout actually gets the height and width of the react
  native views from the correct shadow nodes so that they don't all have
  the same measurements by accident.
- Update locations of annotations when they are changed.
- Split annotation views into a map. The manager is a singleton and all
  the existing map views go through it so the children need to be kep
  separately.
- Safeguard against relayout being called after onDrop(), resulting in a
  null pointer exception.
This commit is contained in:
gcole
2017-04-21 15:12:08 -07:00
parent 11aa29b4cd
commit 156d3f9cf8
7 changed files with 224 additions and 112 deletions
@@ -7,8 +7,9 @@ import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.mapbox.mapboxsdk.geometry.LatLng;
import java.util.HashMap;
public class RNMGLAnnotationViewManager extends ViewGroupManager<RNMGLAnnotationView> {
private LayoutShadowNode _shadowNode;
private static final String NAME = "RCTMapboxAnnotation";
@@ -19,17 +20,17 @@ public class RNMGLAnnotationViewManager extends ViewGroupManager<RNMGLAnnotation
@Override
protected RNMGLAnnotationView createViewInstance(ThemedReactContext reactContext) {
return new RNMGLAnnotationView(reactContext, this);
return new RNMGLAnnotationView(reactContext);
}
@Override
public Class<? extends LayoutShadowNode> getShadowNodeClass() {
return SizeReportingShadowNode.class;
}
@Override
public LayoutShadowNode createShadowNodeInstance() {
_shadowNode = super.createShadowNodeInstance();
return _shadowNode;
}
public LayoutShadowNode getShadowNode() {
return _shadowNode;
return new SizeReportingShadowNode();
}
// Props
@@ -46,4 +47,15 @@ public class RNMGLAnnotationViewManager extends ViewGroupManager<RNMGLAnnotation
coordinate.setLongitude(map.getDouble("longitude"));
view.setCoordinate(coordinate);
}
@Override
public void updateExtraData(RNMGLAnnotationView view, Object extraData) {
// This is called from the {@link SizeReportingShadowNode}. We cache
// the width and height so that we can set the correct size on the marker
// view annotations in ReactNativeMapboxGLView RNMGLCustomMarkerViewAdapter.
HashMap<String, Float> data = (HashMap<String, Float>) extraData;
float width = data.get("width");
float height = data.get("height");
view.setLayoutDimensions(width, height);
}
}