Skip to content

Commit

Permalink
Applying fix for react-native-maps#1150
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Rossetti committed Mar 24, 2017
1 parent 3bd1b00 commit 96acb18
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public class AirMapManager extends ViewGroupManager<AirMapView> {
"none", GoogleMap.MAP_TYPE_NONE
);

private ReactContext reactContext;

private final ReactApplicationContext appContext;

protected GoogleMapOptions googleMapOptions;
Expand All @@ -61,24 +59,15 @@ public String getName() {

@Override
protected AirMapView createViewInstance(ThemedReactContext context) {
reactContext = context;

try {
MapsInitializer.initialize(this.appContext);
} catch (RuntimeException e) {
e.printStackTrace();
emitMapError("Map initialize error", "map_init_error");
}

return new AirMapView(context, this.appContext.getCurrentActivity(), this, this.googleMapOptions);
return new AirMapView(context, this, googleMapOptions);
}

private void emitMapError(String message, String type) {
private void emitMapError(ThemedReactContext context, String message, String type) {
WritableMap error = Arguments.createMap();
error.putString("message", message);
error.putString("type", type);

reactContext
context
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("onError", error);
}
Expand Down Expand Up @@ -297,9 +286,9 @@ public void updateExtraData(AirMapView view, Object extraData) {
view.updateExtraData(extraData);
}

void pushEvent(View view, String name, WritableMap data) {
reactContext.getJSModule(RCTEventEmitter.class)
.receiveEvent(view.getId(), name, data);
void pushEvent(ThemedReactContext context, View view, String name, WritableMap data) {
context.getJSModule(RCTEventEmitter.class)
.receiveEvent(view.getId(), name, data);
}

@Override
Expand Down
39 changes: 20 additions & 19 deletions android/src/main/java/com/airbnb/android/react/maps/AirMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ public class AirMapView extends MapView implements GoogleMap.InfoWindowAdapter,
private final ThemedReactContext context;
private final EventDispatcher eventDispatcher;

public AirMapView(ThemedReactContext reactContext, Context appContext, AirMapManager manager,
public AirMapView(ThemedReactContext reactContext, AirMapManager manager,
GoogleMapOptions googleMapOptions) {
super(appContext, googleMapOptions);
super(reactContext, googleMapOptions);

this.manager = manager;
this.context = reactContext;

super.onCreate(null);
// TODO(lmr): what about onStart????
super.onResume();
super.getMapAsync(this);

Expand Down Expand Up @@ -143,7 +144,7 @@ public void onMapReady(final GoogleMap map) {
this.map.setInfoWindowAdapter(this);
this.map.setOnMarkerDragListener(this);

manager.pushEvent(this, "onMapReady", new WritableNativeMap());
manager.pushEvent(context, this, "onMapReady", new WritableNativeMap());

final AirMapView view = this;

Expand All @@ -154,11 +155,11 @@ public boolean onMarkerClick(Marker marker) {

event = makeClickEventData(marker.getPosition());
event.putString("action", "marker-press");
manager.pushEvent(view, "onMarkerPress", event);
manager.pushEvent(context, view, "onMarkerPress", event);

event = makeClickEventData(marker.getPosition());
event.putString("action", "marker-press");
manager.pushEvent(markerMap.get(marker), "onPress", event);
manager.pushEvent(context, markerMap.get(marker), "onPress", event);

// Return false to open the callout info window and center on the marker
// https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnMarkerClickListener
Expand All @@ -176,7 +177,7 @@ public boolean onMarkerClick(Marker marker) {
public void onPolygonClick(Polygon polygon) {
WritableMap event = makeClickEventData(polygon.getPoints().get(0));
event.putString("action", "polygon-press");
manager.pushEvent(polygonMap.get(polygon), "onPress", event);
manager.pushEvent(context, polygonMap.get(polygon), "onPress", event);
}
});

Expand All @@ -185,7 +186,7 @@ public void onPolygonClick(Polygon polygon) {
public void onPolylineClick(Polyline polyline) {
WritableMap event = makeClickEventData(polyline.getPoints().get(0));
event.putString("action", "polyline-press");
manager.pushEvent(polylineMap.get(polyline), "onPress", event);
manager.pushEvent(context, polylineMap.get(polyline), "onPress", event);
}
});

Expand All @@ -196,17 +197,17 @@ public void onInfoWindowClick(Marker marker) {

event = makeClickEventData(marker.getPosition());
event.putString("action", "callout-press");
manager.pushEvent(view, "onCalloutPress", event);
manager.pushEvent(context, view, "onCalloutPress", event);

event = makeClickEventData(marker.getPosition());
event.putString("action", "callout-press");
AirMapMarker markerView = markerMap.get(marker);
manager.pushEvent(markerView, "onCalloutPress", event);
manager.pushEvent(context, markerView, "onCalloutPress", event);

event = makeClickEventData(marker.getPosition());
event.putString("action", "callout-press");
AirMapCallout infoWindow = markerView.getCalloutView();
if (infoWindow != null) manager.pushEvent(infoWindow, "onPress", event);
if (infoWindow != null) manager.pushEvent(context, infoWindow, "onPress", event);
}
});

Expand All @@ -215,7 +216,7 @@ public void onInfoWindowClick(Marker marker) {
public void onMapClick(LatLng point) {
WritableMap event = makeClickEventData(point);
event.putString("action", "press");
manager.pushEvent(view, "onPress", event);
manager.pushEvent(context, view, "onPress", event);
}
});

Expand All @@ -224,7 +225,7 @@ public void onMapClick(LatLng point) {
public void onMapLongClick(LatLng point) {
WritableMap event = makeClickEventData(point);
event.putString("action", "long-press");
manager.pushEvent(view, "onLongPress", makeClickEventData(point));
manager.pushEvent(context, view, "onLongPress", makeClickEventData(point));
}
});

Expand Down Expand Up @@ -675,31 +676,31 @@ public void run() {
@Override
public void onMarkerDragStart(Marker marker) {
WritableMap event = makeClickEventData(marker.getPosition());
manager.pushEvent(this, "onMarkerDragStart", event);
manager.pushEvent(context, this, "onMarkerDragStart", event);

AirMapMarker markerView = markerMap.get(marker);
event = makeClickEventData(marker.getPosition());
manager.pushEvent(markerView, "onDragStart", event);
manager.pushEvent(context, markerView, "onDragStart", event);
}

@Override
public void onMarkerDrag(Marker marker) {
WritableMap event = makeClickEventData(marker.getPosition());
manager.pushEvent(this, "onMarkerDrag", event);
manager.pushEvent(context, this, "onMarkerDrag", event);

AirMapMarker markerView = markerMap.get(marker);
event = makeClickEventData(marker.getPosition());
manager.pushEvent(markerView, "onDrag", event);
manager.pushEvent(context, markerView, "onDrag", event);
}

@Override
public void onMarkerDragEnd(Marker marker) {
WritableMap event = makeClickEventData(marker.getPosition());
manager.pushEvent(this, "onMarkerDragEnd", event);
manager.pushEvent(context, this, "onMarkerDragEnd", event);

AirMapMarker markerView = markerMap.get(marker);
event = makeClickEventData(marker.getPosition());
manager.pushEvent(markerView, "onDragEnd", event);
manager.pushEvent(context, markerView, "onDragEnd", event);
}

private ProgressBar getMapLoadingProgressBar() {
Expand Down Expand Up @@ -792,6 +793,6 @@ public void onPanDrag(MotionEvent ev) {
Point point = new Point((int) ev.getX(), (int) ev.getY());
LatLng coords = this.map.getProjection().fromScreenLocation(point);
WritableMap event = makeClickEventData(coords);
manager.pushEvent(this, "onPanDrag", event);
manager.pushEvent(context, this, "onPanDrag", event);
}
}
13 changes: 13 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import com.android.build.OutputFile

apply from: "react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
Expand All @@ -76,6 +78,17 @@ android {
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
Expand Down

0 comments on commit 96acb18

Please sign in to comment.