-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add onPress for polygons and polylines on iOS and Android #760
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,15 @@ | |
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReadableArray; | ||
import com.facebook.react.common.MapBuilder; | ||
import com.facebook.react.uimanager.ThemedReactContext; | ||
import com.facebook.react.uimanager.ViewGroupManager; | ||
import com.facebook.react.uimanager.annotations.ReactProp; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
|
||
public class AirMapPolylineManager extends ViewGroupManager<AirMapPolyline> { | ||
private final DisplayMetrics metrics; | ||
|
||
|
@@ -62,4 +67,13 @@ public void setGeodesic(AirMapPolyline view, boolean geodesic) { | |
public void setZIndex(AirMapPolyline view, float zIndex) { | ||
view.setZIndex(zIndex); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public Map getExportedCustomDirectEventTypeConstants() { | ||
Map map = MapBuilder.of( | ||
"onPress", MapBuilder.of("registrationName", "onPress") | ||
); | ||
return map; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ | |
import com.google.android.gms.maps.model.LatLng; | ||
import com.google.android.gms.maps.model.LatLngBounds; | ||
import com.google.android.gms.maps.model.Marker; | ||
import com.google.android.gms.maps.model.Polygon; | ||
import com.google.android.gms.maps.model.Polyline; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
@@ -72,6 +74,8 @@ public class AirMapView extends MapView implements GoogleMap.InfoWindowAdapter, | |
|
||
private final List<AirMapFeature> features = new ArrayList<>(); | ||
private final Map<Marker, AirMapMarker> markerMap = new HashMap<>(); | ||
private final Map<Polyline, AirMapPolyline> polylineMap = new HashMap<>(); | ||
private final Map<Polygon, AirMapPolygon> polygonMap = new HashMap<>(); | ||
private final ScaleGestureDetector scaleDetector; | ||
private final GestureDetectorCompat gestureDetector; | ||
private final AirMapManager manager; | ||
|
@@ -165,6 +169,26 @@ public boolean onMarkerClick(Marker marker) { | |
} | ||
}); | ||
|
||
map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() { | ||
@Override | ||
public void onPolygonClick(Polygon polygon) { | ||
WritableMap event; | ||
event = makeClickEventData(polygon.getPoints().get(0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
event.putString("action", "polygon-press"); | ||
manager.pushEvent(polygonMap.get(polygon), "onPress", event); | ||
} | ||
}); | ||
|
||
map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() { | ||
@Override | ||
public void onPolylineClick(Polyline polyline) { | ||
WritableMap event; | ||
event = makeClickEventData(polyline.getPoints().get(0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
event.putString("action", "polyline-press"); | ||
manager.pushEvent(polylineMap.get(polyline), "onPress", event); | ||
} | ||
}); | ||
|
||
map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { | ||
@Override | ||
public void onInfoWindowClick(Marker marker) { | ||
|
@@ -381,10 +405,14 @@ public void addFeature(View child, int index) { | |
AirMapPolyline polylineView = (AirMapPolyline) child; | ||
polylineView.addToMap(map); | ||
features.add(index, polylineView); | ||
Polyline polyline = (Polyline) polylineView.getFeature(); | ||
polylineMap.put(polyline, polylineView); | ||
} else if (child instanceof AirMapPolygon) { | ||
AirMapPolygon polygonView = (AirMapPolygon) child; | ||
polygonView.addToMap(map); | ||
features.add(index, polygonView); | ||
Polygon polygon = (Polygon) polygonView.getFeature(); | ||
polygonMap.put(polygon, polygonView); | ||
} else if (child instanceof AirMapCircle) { | ||
AirMapCircle circleView = (AirMapCircle) child; | ||
circleView.addToMap(map); | ||
|
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.
return MapBuilder.of()
directly, no need to declare a variable 👍