Skip to content

Commit

Permalink
Merge pull request #1 from nammayatri/scroll-map
Browse files Browse the repository at this point in the history
Scroll map
  • Loading branch information
spravinkumar9952 authored Oct 11, 2024
2 parents a169d3e + 9151b72 commit 1d47154
Show file tree
Hide file tree
Showing 62 changed files with 4,212 additions and 64 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ yarn-error.log
.vscode

# ts outDir
lib/

example/vendor/bundle/

Expand Down
4 changes: 0 additions & 4 deletions .husky/commit-msg

This file was deleted.

7 changes: 0 additions & 7 deletions .husky/pre-commit

This file was deleted.

97 changes: 55 additions & 42 deletions android/src/main/java/com/rnmaps/maps/MapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public void setInitialCamera(MapView view, ReadableMap initialCamera) {
@ReactProp(name = "mapType")
public void setMapType(MapView view, @Nullable String mapType) {
int typeId = MAP_TYPES.get(mapType);
view.map.setMapType(typeId);
if (view.map != null)
view.map.setMapType(typeId);
}

@ReactProp(name = "customMapStyleString")
Expand Down Expand Up @@ -193,7 +194,8 @@ public void setMapPadding(MapView view, @Nullable ReadableMap padding) {
}

view.applyBaseMapPadding(left, top, right, bottom);
view.map.setPadding(left, top, right, bottom);
if (view.map != null)
view.map.setPadding(left, top, right, bottom);
}

@ReactProp(name = "showsUserLocation", defaultBoolean = false)
Expand Down Expand Up @@ -235,22 +237,26 @@ public void setHandlePanDrag(MapView view, boolean handlePanDrag) {

@ReactProp(name = "showsTraffic", defaultBoolean = false)
public void setShowTraffic(MapView view, boolean showTraffic) {
view.map.setTrafficEnabled(showTraffic);
if (view.map != null)
view.map.setTrafficEnabled(showTraffic);
}

@ReactProp(name = "showsBuildings", defaultBoolean = false)
public void setShowBuildings(MapView view, boolean showBuildings) {
view.map.setBuildingsEnabled(showBuildings);
if (view.map != null)
view.map.setBuildingsEnabled(showBuildings);
}

@ReactProp(name = "showsIndoors", defaultBoolean = false)
public void setShowIndoors(MapView view, boolean showIndoors) {
view.map.setIndoorEnabled(showIndoors);
if (view.map != null)
view.map.setIndoorEnabled(showIndoors);
}

@ReactProp(name = "showsIndoorLevelPicker", defaultBoolean = false)
public void setShowsIndoorLevelPicker(MapView view, boolean showsIndoorLevelPicker) {
view.map.getUiSettings().setIndoorLevelPickerEnabled(showsIndoorLevelPicker);
if (view.map != null)
view.map.getUiSettings().setIndoorLevelPickerEnabled(showsIndoorLevelPicker);
}

@ReactProp(name = "showsCompass", defaultBoolean = false)
Expand All @@ -260,27 +266,33 @@ public void setShowsCompass(MapView view, boolean showsCompass) {

@ReactProp(name = "scrollEnabled", defaultBoolean = false)
public void setScrollEnabled(MapView view, boolean scrollEnabled) {
view.map.getUiSettings().setScrollGesturesEnabled(scrollEnabled);
if (view.map != null)
view.map.getUiSettings().setScrollGesturesEnabled(scrollEnabled);
}

@ReactProp(name = "zoomEnabled", defaultBoolean = false)
public void setZoomEnabled(MapView view, boolean zoomEnabled) {
view.map.getUiSettings().setZoomGesturesEnabled(zoomEnabled);
if (view.map != null)
view.map.getUiSettings().setZoomGesturesEnabled(zoomEnabled);
}

@ReactProp(name = "zoomControlEnabled", defaultBoolean = true)
public void setZoomControlEnabled(MapView view, boolean zoomControlEnabled) {
view.map.getUiSettings().setZoomControlsEnabled(zoomControlEnabled);
if (view.map != null)
view.map.getUiSettings().setZoomControlsEnabled(zoomControlEnabled);
}

@ReactProp(name = "rotateEnabled", defaultBoolean = false)
public void setRotateEnabled(MapView view, boolean rotateEnabled) {
view.map.getUiSettings().setRotateGesturesEnabled(rotateEnabled);
if (view.map != null)
view.map.getUiSettings().setRotateGesturesEnabled(rotateEnabled);
}

@ReactProp(name = "scrollDuringRotateOrZoomEnabled", defaultBoolean = true)
public void setScrollDuringRotateOrZoomEnabled(MapView view, boolean scrollDuringRotateOrZoomEnabled) {
view.map.getUiSettings().setScrollGesturesEnabledDuringRotateOrZoom(scrollDuringRotateOrZoomEnabled);
if(view.map != null) {
view.map.getUiSettings().setScrollGesturesEnabledDuringRotateOrZoom(scrollDuringRotateOrZoomEnabled);
}
}

@ReactProp(name = "cacheEnabled", defaultBoolean = false)
Expand Down Expand Up @@ -310,17 +322,20 @@ public void setLoadingIndicatorColor(MapView view, @Nullable Integer loadingIndi

@ReactProp(name = "pitchEnabled", defaultBoolean = false)
public void setPitchEnabled(MapView view, boolean pitchEnabled) {
view.map.getUiSettings().setTiltGesturesEnabled(pitchEnabled);
if (view.map != null)
view.map.getUiSettings().setTiltGesturesEnabled(pitchEnabled);
}

@ReactProp(name = "minZoomLevel")
public void setMinZoomLevel(MapView view, float minZoomLevel) {
view.map.setMinZoomPreference(minZoomLevel);
if (view.map != null)
view.map.setMinZoomPreference(minZoomLevel);
}

@ReactProp(name = "maxZoomLevel")
public void setMaxZoomLevel(MapView view, float maxZoomLevel) {
view.map.setMaxZoomPreference(maxZoomLevel);
if (view.map != null)
view.map.setMaxZoomPreference(maxZoomLevel);
}

@ReactProp(name = "kmlSrc")
Expand Down Expand Up @@ -380,6 +395,12 @@ public void receiveCommand(@NonNull MapView view, String commandId, @Nullable Re
view.animateToRegion(bounds, duration);
break;

case "scrollMap":
if (args == null) {
break;
}
view.scrollMap((float) args.getDouble(0), (float) args.getDouble(1), args.getBoolean(2));

case "fitToElements":
if (args == null) {
break;
Expand Down Expand Up @@ -420,34 +441,26 @@ public void receiveCommand(@NonNull MapView view, String commandId, @Nullable Re
@Override
@Nullable
public Map getExportedCustomDirectEventTypeConstants() {
Map<String, Map<String, String>> map = MapBuilder.of(
"onMapReady", MapBuilder.of("registrationName", "onMapReady"),
"onPress", MapBuilder.of("registrationName", "onPress"),
"onLongPress", MapBuilder.of("registrationName", "onLongPress"),
"onMarkerPress", MapBuilder.of("registrationName", "onMarkerPress"),
"onCalloutPress", MapBuilder.of("registrationName", "onCalloutPress")
);

map.putAll(MapBuilder.of(
"onUserLocationChange", MapBuilder.of("registrationName", "onUserLocationChange"),
"onMarkerDragStart", MapBuilder.of("registrationName", "onMarkerDragStart"),
"onMarkerDrag", MapBuilder.of("registrationName", "onMarkerDrag"),
"onMarkerDragEnd", MapBuilder.of("registrationName", "onMarkerDragEnd"),
"onPanDrag", MapBuilder.of("registrationName", "onPanDrag"),
"onKmlReady", MapBuilder.of("registrationName", "onKmlReady"),
"onPoiClick", MapBuilder.of("registrationName", "onPoiClick")
));

map.putAll(MapBuilder.of(
"onIndoorLevelActivated", MapBuilder.of("registrationName", "onIndoorLevelActivated"),
"onIndoorBuildingFocused", MapBuilder.of("registrationName", "onIndoorBuildingFocused"),
"onDoublePress", MapBuilder.of("registrationName", "onDoublePress"),
"onMapLoaded", MapBuilder.of("registrationName", "onMapLoaded"),
"onMarkerSelect", MapBuilder.of("registrationName", "onMarkerSelect"),
"onMarkerDeselect", MapBuilder.of("registrationName", "onMarkerDeselect")
));

return map;
return MapBuilder.<String, Map<String, String>>builder()
.put("onMapReady", MapBuilder.of("registrationName", "onMapReady"))
.put("onPress", MapBuilder.of("registrationName", "onPress"))
.put("onLongPress", MapBuilder.of("registrationName", "onLongPress"))
.put("onMarkerPress", MapBuilder.of("registrationName", "onMarkerPress"))
.put("onCalloutPress", MapBuilder.of("registrationName", "onCalloutPress"))
.put("onUserLocationChange", MapBuilder.of("registrationName", "onUserLocationChange"))
.put("onMarkerDragStart", MapBuilder.of("registrationName", "onMarkerDragStart"))
.put("onMarkerDrag", MapBuilder.of("registrationName", "onMarkerDrag"))
.put("onMarkerDragEnd", MapBuilder.of("registrationName", "onMarkerDragEnd"))
.put("onPanDrag", MapBuilder.of("registrationName", "onPanDrag"))
.put("onKmlReady", MapBuilder.of("registrationName", "onKmlReady"))
.put("onPoiClick", MapBuilder.of("registrationName", "onPoiClick"))
.put("onIndoorLevelActivated", MapBuilder.of("registrationName", "onIndoorLevelActivated"))
.put("onIndoorBuildingFocused", MapBuilder.of("registrationName", "onIndoorBuildingFocused"))
.put("onDoublePress", MapBuilder.of("registrationName", "onDoublePress"))
.put("onMapLoaded", MapBuilder.of("registrationName", "onMapLoaded"))
.put("onMarkerSelect", MapBuilder.of("registrationName", "onMarkerSelect"))
.put("onMarkerDeselect", MapBuilder.of("registrationName", "onMarkerDeselect"))
.build();
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions android/src/main/java/com/rnmaps/maps/MapMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,10 @@ private BitmapDescriptor getBitmapDescriptorByName(String name) {
return BitmapDescriptorFactory.fromResource(getDrawableResourceByName(name));
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
this.height = b-t;
this.width = r-l;
}
}
13 changes: 13 additions & 0 deletions android/src/main/java/com/rnmaps/maps/MapPolyline.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rnmaps.maps;

import android.content.Context;
import android.graphics.Color;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
Expand All @@ -13,6 +14,8 @@
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import com.google.android.gms.maps.model.RoundCap;
import com.google.android.gms.maps.model.StrokeStyle;
import com.google.android.gms.maps.model.StyleSpan;
import com.google.maps.android.collections.PolylineManager;

import java.util.ArrayList;
Expand All @@ -32,6 +35,7 @@ public class MapPolyline extends MapFeature {
private Cap lineCap = new RoundCap();
private ReadableArray patternValues;
private List<PatternItem> pattern;
private StyleSpan styleSpan = null;

public MapPolyline(Context context) {
super(context);
Expand Down Expand Up @@ -124,6 +128,14 @@ private void applyPattern() {
}
}

public void setStrokeColors(ReadableArray colors){
if(colors.size() < 1) return;
int n = colors.size();
int start = Color.parseColor(colors.getString(0));
int end = Color.parseColor(colors.getString(n-1));
this.styleSpan = new StyleSpan(StrokeStyle.gradientBuilder(start, end).build());
}

public PolylineOptions getPolylineOptions() {
if (polylineOptions == null) {
polylineOptions = createPolylineOptions();
Expand All @@ -141,6 +153,7 @@ private PolylineOptions createPolylineOptions() {
options.startCap(lineCap);
options.endCap(lineCap);
options.pattern(this.pattern);
if(this.styleSpan != null) options.addSpan(styleSpan);
return options;
}

Expand Down
5 changes: 5 additions & 0 deletions android/src/main/java/com/rnmaps/maps/MapPolylineManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public void setLineDashPattern(MapPolyline view, ReadableArray patternValues) {
view.setLineDashPattern(patternValues);
}

@ReactProp(name = "strokeColors")
public void setStrokeColors(MapPolyline view, ReadableArray colors){
view.setStrokeColors(colors);
}

@Override
@Nullable
public Map getExportedCustomDirectEventTypeConstants() {
Expand Down
22 changes: 20 additions & 2 deletions android/src/main/java/com/rnmaps/maps/MapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

public class MapView extends com.google.android.gms.maps.MapView implements GoogleMap.InfoWindowAdapter,
GoogleMap.OnMarkerDragListener, OnMapReadyCallback, GoogleMap.OnPoiClickListener, GoogleMap.OnIndoorStateChangeListener {
Expand Down Expand Up @@ -135,6 +137,7 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
private final ViewAttacherGroup attacherGroup;
private LatLng tapLocation;


private static boolean contextHasBug(Context context) {
return context == null ||
context.getResources() == null ||
Expand Down Expand Up @@ -198,6 +201,12 @@ public boolean onDoubleTap(MotionEvent ev) {
onDoublePress(ev);
return false;
}

@Override
public boolean onDoubleTapEvent(MotionEvent e){
map.animateCamera(CameraUpdateFactory.zoomIn(), 400, null);
return true;
}
});

this.addOnLayoutChangeListener(new OnLayoutChangeListener() {
Expand Down Expand Up @@ -650,13 +659,13 @@ public void setUserLocationFastestInterval(int interval){
}

public void setShowsMyLocationButton(boolean showMyLocationButton) {
if (hasPermissions() || !showMyLocationButton) {
if ((hasPermissions() || !showMyLocationButton) && map != null) {
map.getUiSettings().setMyLocationButtonEnabled(showMyLocationButton);
}
}

public void setToolbarEnabled(boolean toolbarEnabled) {
if (hasPermissions() || !toolbarEnabled) {
if ((hasPermissions() || !toolbarEnabled) && map != null) {
map.getUiSettings().setMapToolbarEnabled(toolbarEnabled);
}
}
Expand Down Expand Up @@ -905,6 +914,15 @@ public void animateToRegion(LatLngBounds bounds, int duration) {
}
}

public void scrollMap(float xPixel, float yPixel, boolean animated) {
if (map == null) return;
if (animated) {
map.animateCamera(CameraUpdateFactory.scrollBy(xPixel, yPixel), 400, null );
} else {
map.moveCamera(CameraUpdateFactory.scrollBy(xPixel, yPixel));
}
}

public void fitToElements(ReadableMap edgePadding, boolean animated) {
if (map == null) return;

Expand Down
21 changes: 21 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,27 @@ - (UIView *)view
}];
}

RCT_EXPORT_METHOD(scrollMap:(nonnull NSNumber *)reactTag
xPixel:(CGFloat)xPixel
yPixel:(CGFloat)yPixel
animated:(BOOL)animated)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
id view = viewRegistry[reactTag];
if (![view isKindOfClass:[AIRGoogleMap class]]) {
RCTLogError(@"Invalid view returned from registry, expecting AIRGoogleMap, got: %@", view);
} else {
AIRGoogleMap *mapView = (AIRGoogleMap *)view;
GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate scrollByX:xPixel Y:yPixel];
if (animated) {
[mapView animateWithCameraUpdate:cameraUpdate];
} else {
[mapView moveCamera:cameraUpdate];
}
}
}];
}

RCT_EXPORT_METHOD(fitToElements:(nonnull NSNumber *)reactTag
edgePadding:(nonnull NSDictionary *)edgePadding
animated:(BOOL)animated)
Expand Down
7 changes: 7 additions & 0 deletions ios/AirMaps/AIRMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ - (UIView *)view
}];
}

RCT_EXPORT_METHOD(scrollMap:(nonnull NSNumber *)reactTag
xPixel:(CGFloat)xPixel
yPixel:(CGFloat)yPixel
animated:(BOOL)animated)
{
}

RCT_EXPORT_METHOD(fitToElements:(nonnull NSNumber *)reactTag
edgePadding:(nonnull NSDictionary *)edgePadding
animated:(BOOL)animated)
Expand Down
19 changes: 19 additions & 0 deletions lib/AnimatedRegion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Animated } from 'react-native';
import { Region } from './sharedTypes';
declare const AnimatedWithChildren: any;
type Props = Partial<Region> | undefined;
export default class AnimatedMapRegion extends AnimatedWithChildren {
constructor(valueIn?: Props);
setValue(value: Region): void;
setOffset(offset: Region): void;
flattenOffset(): void;
private __getValue;
private __attach;
private __detach;
stopAnimation(callback: (region: Region) => void): void;
addListener(callback: (region: Region) => void): string;
removeListener(id: string): void;
spring(config: Animated.SpringAnimationConfig & Region): Animated.CompositeAnimation;
timing(config: Animated.TimingAnimationConfig & Region): Animated.CompositeAnimation;
}
export {};
Loading

0 comments on commit 1d47154

Please sign in to comment.