Files
react-native-mapbox-gl/android/src/main/java/com/mapbox/reactnativemapboxgl/RNMGLAnnotationViewManager.java
T
gcole 156d3f9cf8 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.
2017-04-21 15:12:08 -07:00

62 lines
2.0 KiB
Java

package com.mapbox.reactnativemapboxgl;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.ThemedReactContext;
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 static final String NAME = "RCTMapboxAnnotation";
@Override
public String getName() {
return NAME;
}
@Override
protected RNMGLAnnotationView createViewInstance(ThemedReactContext reactContext) {
return new RNMGLAnnotationView(reactContext);
}
@Override
public Class<? extends LayoutShadowNode> getShadowNodeClass() {
return SizeReportingShadowNode.class;
}
@Override
public LayoutShadowNode createShadowNodeInstance() {
return new SizeReportingShadowNode();
}
// Props
@ReactProp(name = "id")
public void setAnnotationId(RNMGLAnnotationView view, String value) {
view.setAnnotationId(value);
}
@ReactProp(name = "coordinate")
public void setCoordinate(RNMGLAnnotationView view, ReadableMap map) {
LatLng coordinate = new LatLng();
coordinate.setLatitude(map.getDouble("latitude"));
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);
}
}