Skip to content
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

Update react-native-maps to 0.27.1 #8495

Merged
merged 3 commits into from May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@ Package-specific changes not released in any SDK will be added here just before
- Updated `react-native-reanimated` from `1.7.0` to `1.9.0`. ([#8424](https://github.com/expo/expo/pull/8424) by [@sjchmiela](https://github.com/sjchmiela))
- Updated `react-native-safe-area-context` from `0.7.3` to `2.0.1`. ([#8459](https://github.com/expo/expo/pull/8459) by [@brentvatne](https://github.com/brentvatne) and [#8479](https://github.com/expo/expo/pull/8479) by [@tsapeta](https://github.com/tsapeta))
- Updated `@react-native-community/datetimepicker` from `2.2.2` to `2.4.0`. ([#8476](https://github.com/expo/expo/pull/8476) by [@tsapeta](https://github.com/tsapeta))
- Updated `react-native-maps` from `0.26.1` to `0.27.1`. ([#8495](https://github.com/expo/expo/pull/8495) by [@esamelson](https://github.com/esamelson))

### 🛠 Breaking changes

Expand Down
Expand Up @@ -14,6 +14,7 @@
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.model.LatLng;
Expand Down Expand Up @@ -50,6 +51,13 @@ public class AirMapManager extends ViewGroupManager<AirMapView> {
"none", GoogleMap.MAP_TYPE_NONE
);

private final Map<String, Integer> MY_LOCATION_PRIORITY = MapBuilder.of(
"balanced", LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY,
"high", LocationRequest.PRIORITY_HIGH_ACCURACY,
"low", LocationRequest.PRIORITY_LOW_POWER,
"passive", LocationRequest.PRIORITY_NO_POWER
);

private final ReactApplicationContext appContext;
private AirMapMarkerManager markerManager;

Expand Down Expand Up @@ -152,6 +160,21 @@ public void setShowsUserLocation(AirMapView view, boolean showUserLocation) {
view.setShowsUserLocation(showUserLocation);
}

@ReactProp(name = "userLocationPriority")
public void setUserLocationPriority(AirMapView view, @Nullable String accuracy) {
view.setUserLocationPriority(MY_LOCATION_PRIORITY.get(accuracy));
}

@ReactProp(name = "userLocationUpdateInterval", defaultInt = 5000)
public void setUserLocationUpdateInterval(AirMapView view, int updateInterval) {
view.setUserLocationUpdateInterval(updateInterval);
}

@ReactProp(name = "userLocationFastestInterval", defaultInt = 5000)
public void setUserLocationFastestInterval(AirMapView view, int fastestInterval) {
view.setUserLocationFastestInterval(fastestInterval);
}

@ReactProp(name = "showsMyLocationButton", defaultBoolean = true)
public void setShowsMyLocationButton(AirMapView view, boolean showMyLocationButton) {
view.setShowsMyLocationButton(showMyLocationButton);
Expand Down
Expand Up @@ -50,12 +50,12 @@ public void setZIndex(float zIndex) {
}
}

// public void setTransparency(float transparency) {
// this.transparency = transparency;
// if (groundOverlay != null) {
// groundOverlay.setTransparency(transparency);
// }
// }
public void setTransparency(float transparency) {
this.transparency = transparency;
if (groundOverlay != null) {
groundOverlay.setTransparency(transparency);
}
}

public void setImage(String uri) {
this.mImageReader.setImage(uri);
Expand Down Expand Up @@ -138,6 +138,7 @@ public void update() {
if (this.groundOverlay != null) {
this.groundOverlay.setVisible(true);
this.groundOverlay.setImage(this.iconBitmapDescriptor);
this.groundOverlay.setTransparency(this.transparency);
this.groundOverlay.setClickable(this.tappable);
}
}
Expand Down
Expand Up @@ -51,10 +51,10 @@ public void setZIndex(AirMapOverlay view, float zIndex) {
view.setZIndex(zIndex);
}

// @ReactProp(name = "transparency", defaultFloat = 1.0f)
// public void setTransparency(AirMapOverlay view, float transparency) {
// view.setTransparency(transparency);
// }
@ReactProp(name = "opacity", defaultFloat = 1.0f)
public void setOpacity(AirMapOverlay view, float opacity) {
view.setTransparency(1 - opacity);
}

@ReactProp(name = "image")
public void setImage(AirMapOverlay view, @Nullable String source) {
Expand Down
Expand Up @@ -112,6 +112,7 @@ public class AirMapView extends MapView implements GoogleMap.InfoWindowAdapter,
private boolean destroyed = false;
private final ThemedReactContext context;
private final EventDispatcher eventDispatcher;
private FusedLocationSource fusedLocationSource;

private ViewAttacherGroup attacherGroup;

Expand Down Expand Up @@ -161,6 +162,8 @@ public AirMapView(ThemedReactContext reactContext, ReactApplicationContext appCo

final AirMapView view = this;

fusedLocationSource = new FusedLocationSource(context);

gestureDetector =
new GestureDetectorCompat(reactContext, new GestureDetector.SimpleOnGestureListener() {

Expand Down Expand Up @@ -385,6 +388,7 @@ public void onHostResume() {
if (hasPermissions()) {
//noinspection MissingPermission
map.setMyLocationEnabled(showUserLocation);
map.setLocationSource(fusedLocationSource);
}
synchronized (AirMapView.this) {
if (!destroyed) {
Expand Down Expand Up @@ -513,11 +517,24 @@ public void setCamera(ReadableMap camera) {
public void setShowsUserLocation(boolean showUserLocation) {
this.showUserLocation = showUserLocation; // hold onto this for lifecycle handling
if (hasPermissions()) {
map.setLocationSource(fusedLocationSource);
//noinspection MissingPermission
map.setMyLocationEnabled(showUserLocation);
}
}

public void setUserLocationPriority(int priority){
fusedLocationSource.setPriority(priority);
}

public void setUserLocationUpdateInterval(int interval){
fusedLocationSource.setInterval(interval);
}

public void setUserLocationFastestInterval(int interval){
fusedLocationSource.setFastestInterval(interval);
}

public void setShowsMyLocationButton(boolean showMyLocationButton) {
if (hasPermissions() || !showMyLocationButton) {
map.getUiSettings().setMyLocationButtonEnabled(showMyLocationButton);
Expand Down
@@ -0,0 +1,66 @@
package versioned.host.exp.exponent.modules.api.components.maps;

import android.content.Context;
import android.location.Location;
import android.os.Looper;

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.LocationSource;
import com.google.android.gms.tasks.OnSuccessListener;

public class FusedLocationSource implements LocationSource {

private final FusedLocationProviderClient fusedLocationClientProviderClient;
private final LocationRequest locationRequest;
private LocationCallback locationCallback;

public FusedLocationSource(Context context){
fusedLocationClientProviderClient =
LocationServices.getFusedLocationProviderClient(context);
locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(5000);
}

public void setPriority(int priority){
locationRequest.setPriority(priority);
}

public void setInterval(int interval){
locationRequest.setInterval(interval);
}

public void setFastestInterval(int fastestInterval){
locationRequest.setFastestInterval(fastestInterval);
}

@Override
public void activate(final OnLocationChangedListener onLocationChangedListener) {
fusedLocationClientProviderClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
onLocationChangedListener.onLocationChanged(location);
}
}
});
locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
onLocationChangedListener.onLocationChanged(location);
}
}
};
fusedLocationClientProviderClient.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper());
}

@Override
public void deactivate() {
fusedLocationClientProviderClient.removeLocationUpdates(locationCallback);
}
}
2 changes: 1 addition & 1 deletion apps/native-component-list/package.json
Expand Up @@ -86,7 +86,7 @@
"react-native-branch": "4.2.1",
"react-native-gesture-handler": "~1.6.0",
"react-native-is-iphonex": "^1.0.1",
"react-native-maps": "0.26.1",
"react-native-maps": "0.27.1",
"react-native-paper": "github:brentvatne/react-native-paper#@brent/fix-bottom-navigation-rn-57",
"react-native-platform-touchable": "^1.1.1",
"react-native-reanimated": "~1.9.0",
Expand Down
2 changes: 1 addition & 1 deletion home/package.json
Expand Up @@ -50,7 +50,7 @@
"react-native-fade-in-image": "^1.5.0",
"react-native-gesture-handler": "~1.6.0",
"react-native-infinite-scroll-view": "^0.4.5",
"react-native-maps": "0.26.1",
"react-native-maps": "0.27.1",
"react-native-safe-area-context": "2.0.1",
"react-navigation": "4.1.0-alpha.1",
"react-navigation-material-bottom-tabs": "1.1.1",
Expand Down
Expand Up @@ -48,7 +48,7 @@ - (UIView *)view
AIRGoogleMap *map = [AIRGoogleMap new];
map.bridge = self.bridge;
map.delegate = self;
map.isAccessibilityElement = YES;
map.isAccessibilityElement = NO;
map.accessibilityElementsHidden = NO;
map.settings.consumesGesturesInView = NO;
map.indoorDisplay.delegate = self;
Expand All @@ -65,6 +65,7 @@ - (UIView *)view
return map;
}

RCT_EXPORT_VIEW_PROPERTY(isAccessibilityElement, BOOL)
RCT_REMAP_VIEW_PROPERTY(testID, accessibilityIdentifier, NSString)
RCT_EXPORT_VIEW_PROPERTY(initialCamera, GMSCameraPosition)
RCT_REMAP_VIEW_PROPERTY(camera, cameraProp, GMSCameraPosition)
Expand Down
Expand Up @@ -9,7 +9,7 @@

#import "AIRGoogleMapMarker.h"
#import <GoogleMaps/GoogleMaps.h>
#import <React/RCTImageLoader.h>
#import <React/RCTImageLoaderProtocol.h>
#import <React/RCTUtils.h>
#import "AIRGMSMarker.h"
#import "AIRGoogleMapCallout.h"
Expand Down Expand Up @@ -117,9 +117,9 @@ - (void)hideCalloutView {

- (void)redraw {
if (!_realMarker.iconView) return;

BOOL oldValue = _realMarker.tracksViewChanges;

if (oldValue == YES)
{
// Immediate refresh, like right now. Not waiting for next frame.
Expand Down Expand Up @@ -270,7 +270,7 @@ - (void)setImageSrc:(NSString *)imageSrc
[self iconViewInsertSubview:_iconImageView atIndex:0];
}

_reloadImageCancellationBlock = [_bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc]
_reloadImageCancellationBlock = [[_bridge moduleForName:@"ImageLoader"] loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc]
size:self.bounds.size
scale:RCTScreenScale()
clipped:YES
Expand Down Expand Up @@ -327,7 +327,7 @@ - (void)setIconSrc:(NSString *)iconSrc
}

_reloadImageCancellationBlock =
[_bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:_iconSrc]
[[_bridge moduleForName:@"ImageLoader"] loadImageWithURLRequest:[RCTConvert NSURLRequest:_iconSrc]
size:self.bounds.size
scale:RCTScreenScale()
clipped:YES
Expand Down
Expand Up @@ -18,6 +18,7 @@
@property (nonatomic, copy) NSString *imageSrc;
@property (nonatomic, strong, readonly) UIImage *overlayImage;
@property (nonatomic, copy) NSArray *boundsRect;
@property (nonatomic, assign) CGFloat opacity;
@property (nonatomic, readonly) GMSCoordinateBounds *overlayBounds;

@property (nonatomic, weak) RCTBridge *bridge;
Expand Down
Expand Up @@ -8,7 +8,7 @@
#import "AIRGoogleMapOverlay.h"

#import <React/RCTEventDispatcher.h>
#import <React/RCTImageLoader.h>
#import <React/RCTImageLoaderProtocol.h>
#import <React/RCTUtils.h>
#import <React/UIView+React.h>

Expand Down Expand Up @@ -42,7 +42,7 @@ - (void)setImageSrc:(NSString *)imageSrc
}

__weak typeof(self) weakSelf = self;
_reloadImageCancellationBlock = [_bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc]
_reloadImageCancellationBlock = [[_bridge moduleForName:@"ImageLoader"] loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc]
size:weakSelf.bounds.size
scale:RCTScreenScale()
clipped:YES
Expand Down Expand Up @@ -75,6 +75,11 @@ - (void)setBoundsRect:(NSArray *)boundsRect
_overlay.bounds = _overlayBounds;
}

- (void)setOpacity:(CGFloat)opacity
{
_overlay.opacity = opacity;
}

@end

#endif
Expand Up @@ -18,5 +18,6 @@ - (UIView *)view

RCT_REMAP_VIEW_PROPERTY(bounds, boundsRect, NSArray)
RCT_REMAP_VIEW_PROPERTY(image, imageSrc, NSString)
RCT_REMAP_VIEW_PROPERTY(opacity, opacity, CGFloat)

@end
2 changes: 2 additions & 0 deletions ios/Exponent/Versioned/Core/Api/Components/Maps/AIRMap.h
Expand Up @@ -45,6 +45,7 @@ extern const NSInteger AIRMapMaxZoomLevel;
@property (nonatomic, assign) CGFloat minZoomLevel;
@property (nonatomic, assign) CGFloat maxZoomLevel;
@property (nonatomic, assign) CGPoint compassOffset;
@property (nonatomic, assign) UIEdgeInsets mapPadding;

@property (nonatomic, assign) CLLocationCoordinate2D pendingCenter;
@property (nonatomic, assign) MKCoordinateSpan pendingSpan;
Expand All @@ -66,6 +67,7 @@ extern const NSInteger AIRMapMaxZoomLevel;
@property (nonatomic, copy) RCTDirectEventBlock onMarkerDragEnd;
@property (nonatomic, copy) RCTDirectEventBlock onCalloutPress;
@property (nonatomic, copy) RCTDirectEventBlock onRegionChange;
@property (nonatomic, copy) RCTBubblingEventBlock onUserLocationChange;

- (void)cacheViewIfNeeded;
- (void)beginLoading;
Expand Down
18 changes: 18 additions & 0 deletions ios/Exponent/Versioned/Core/Api/Components/Maps/AIRMap.m
Expand Up @@ -358,6 +358,11 @@ - (void)setShowsUserLocation:(BOOL)showsUserLocation
}
}

- (void)setTintColor:(UIColor *)tintColor
{
super.tintColor = tintColor;
}

- (void)setFollowsUserLocation:(BOOL)followsUserLocation
{
_followUserLocation = followsUserLocation;
Expand Down Expand Up @@ -526,6 +531,11 @@ - (void)updateZoomEnabled {
}

- (void)cacheViewIfNeeded {
// https://github.com/react-native-community/react-native-maps/issues/3100
// Do nothing if app is not active
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
return;
}
if (self.hasShownInitialLoading) {
if (!self.cacheEnabled) {
if (_cacheImageView != nil) {
Expand Down Expand Up @@ -581,6 +591,14 @@ - (void)setLegalLabelInsets:(UIEdgeInsets)legalLabelInsets {
[self updateLegalLabelInsets];
}

- (void)setMapPadding:(UIEdgeInsets)mapPadding {
self.layoutMargins = mapPadding;
}

- (UIEdgeInsets)mapPadding {
return self.layoutMargins;
}

- (void)beginLoading {
if ((!self.hasShownInitialLoading && self.loadingEnabled) || (self.cacheEnabled && self.cacheImageView.image == nil)) {
self.loadingView.hidden = NO;
Expand Down