From 8a86e9899dc5674516e5fea374ae307d59732bdc Mon Sep 17 00:00:00 2001 From: Yann Pringault Date: Thu, 6 Jul 2017 18:26:40 +0200 Subject: [PATCH 01/20] Add onMapReady callback (#1369) * Add onMapReady callback Fix #246 * Call onMapReady when state has changed * Add onMapReady callback on iOS --- docs/mapview.md | 1 + lib/components/MapView.js | 11 +++++++++-- lib/ios/AirGoogleMaps/AIRGoogleMap.h | 2 ++ lib/ios/AirGoogleMaps/AIRGoogleMap.m | 4 ++++ lib/ios/AirGoogleMaps/AIRGoogleMapManager.m | 6 ++++++ lib/ios/AirMaps/AIRMap.h | 1 + lib/ios/AirMaps/AIRMapManager.m | 3 +++ 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/mapview.md b/docs/mapview.md index 3df5640c3b..e8b86aee65 100644 --- a/docs/mapview.md +++ b/docs/mapview.md @@ -40,6 +40,7 @@ To access event data, you will need to use `e.nativeEvent`. For example, `onPres | Event Name | Returns | Notes |---|---|---| +| `onMapReady` | | Callback that is called once the map is fully loaded. | `onRegionChange` | `Region` | Callback that is called continuously when the region changes, such as when a user is dragging the map. | `onRegionChangeComplete` | `Region` | Callback that is called once when the region changes, such as when the user is done moving the map. | `onPress` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user taps on the map. diff --git a/lib/components/MapView.js b/lib/components/MapView.js index 2e8ba4e845..e3763f8f3b 100644 --- a/lib/components/MapView.js +++ b/lib/components/MapView.js @@ -318,6 +318,11 @@ const propTypes = { */ legalLabelInsets: EdgeInsetsPropType, + /** + * Callback that is called once the map is fully loaded. + */ + onMapReady: PropTypes.func, + /** * Callback that is called continuously when the user is dragging the map. */ @@ -441,14 +446,16 @@ class MapView extends React.Component { } _onMapReady() { - const { region, initialRegion } = this.props; + const { region, initialRegion, onMapReady } = this.props; if (region) { this.map.setNativeProps({ region }); } else if (initialRegion) { this.map.setNativeProps({ region: initialRegion }); } this._updateStyle(); - this.setState({ isReady: true }); + this.setState({ isReady: true }, () => { + if (onMapReady) onMapReady(); + }); } _onLayout(e) { diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMap.h b/lib/ios/AirGoogleMaps/AIRGoogleMap.h index 0e9554eb69..0d47b72b14 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMap.h +++ b/lib/ios/AirGoogleMaps/AIRGoogleMap.h @@ -18,6 +18,7 @@ @property (nonatomic, assign) MKCoordinateRegion initialRegion; @property (nonatomic, assign) MKCoordinateRegion region; @property (nonatomic, assign) NSString *customMapStyleString; +@property (nonatomic, copy) RCTBubblingEventBlock onMapReady; @property (nonatomic, copy) RCTBubblingEventBlock onPress; @property (nonatomic, copy) RCTBubblingEventBlock onLongPress; @property (nonatomic, copy) RCTBubblingEventBlock onMarkerPress; @@ -40,6 +41,7 @@ @property (nonatomic, assign) BOOL showsUserLocation; @property (nonatomic, assign) BOOL showsMyLocationButton; +- (void)didFinishTileRendering; - (BOOL)didTapMarker:(GMSMarker *)marker; - (void)didTapPolyline:(GMSPolyline *)polyline; - (void)didTapPolygon:(GMSPolygon *)polygon; diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMap.m b/lib/ios/AirGoogleMaps/AIRGoogleMap.m index f87d34c633..48b5ff4461 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMap.m +++ b/lib/ios/AirGoogleMaps/AIRGoogleMap.m @@ -155,6 +155,10 @@ - (void)setRegion:(MKCoordinateRegion)region { self.camera = [AIRGoogleMap makeGMSCameraPositionFromMap:self andMKCoordinateRegion:region]; } +- (void)didFinishTileRendering { + if (self.onMapReady) self.onMapReady(@{}); +} + - (BOOL)didTapMarker:(GMSMarker *)marker { AIRGMSMarker *airMarker = (AIRGMSMarker *)marker; diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m b/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m index c482305b87..53157e99a5 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m +++ b/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m @@ -59,6 +59,7 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsMyLocationButton, BOOL) RCT_EXPORT_VIEW_PROPERTY(customMapStyleString, NSString) +RCT_EXPORT_VIEW_PROPERTY(onMapReady, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) @@ -222,6 +223,11 @@ - (UIView *)view } +- (void)mapViewDidFinishTileRendering:(GMSMapView *)mapView { + AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView; + [googleMapView didFinishTileRendering]; +} + - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker { AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView; return [googleMapView didTapMarker:marker]; diff --git a/lib/ios/AirMaps/AIRMap.h b/lib/ios/AirMaps/AIRMap.h index 4a88617e65..48a07ddb26 100644 --- a/lib/ios/AirMaps/AIRMap.h +++ b/lib/ios/AirMaps/AIRMap.h @@ -46,6 +46,7 @@ extern const CGFloat AIRMapZoomBoundBuffer; @property (nonatomic, assign) BOOL ignoreRegionChanges; +@property (nonatomic, copy) RCTBubblingEventBlock onMapReady; @property (nonatomic, copy) RCTBubblingEventBlock onChange; @property (nonatomic, copy) RCTBubblingEventBlock onPress; @property (nonatomic, copy) RCTBubblingEventBlock onPanDrag; diff --git a/lib/ios/AirMaps/AIRMapManager.m b/lib/ios/AirMaps/AIRMapManager.m index 8ea2472445..e99249ace7 100644 --- a/lib/ios/AirMaps/AIRMapManager.m +++ b/lib/ios/AirMaps/AIRMapManager.m @@ -85,6 +85,7 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(minDelta, CGFloat) RCT_EXPORT_VIEW_PROPERTY(legalLabelInsets, UIEdgeInsets) RCT_EXPORT_VIEW_PROPERTY(mapType, MKMapType) +RCT_EXPORT_VIEW_PROPERTY(onMapReady, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onPanDrag, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock) @@ -662,6 +663,8 @@ - (void)mapViewDidFinishRenderingMap:(AIRMap *)mapView fullyRendered:(BOOL)fully { [mapView finishLoading]; [mapView cacheViewIfNeeded]; + + mapView.onMapReady(@{}); } #pragma mark Private From 3202602d2becb1a0cfeea2e8ca839d6f5cb0c82d Mon Sep 17 00:00:00 2001 From: Frank Rowe Date: Thu, 6 Jul 2017 12:27:22 -0400 Subject: [PATCH 02/20] add MKTileOverlayRenderer (#1357) --- lib/ios/AirMaps/AIRMapManager.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ios/AirMaps/AIRMapManager.m b/lib/ios/AirMaps/AIRMapManager.m index e99249ace7..41b124aae8 100644 --- a/lib/ios/AirMaps/AIRMapManager.m +++ b/lib/ios/AirMaps/AIRMapManager.m @@ -482,6 +482,8 @@ - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id Date: Tue, 18 Jul 2017 16:41:52 +1000 Subject: [PATCH 03/20] Handle Android RN 0.47 breaking change (#1481) --- .../main/java/com/airbnb/android/react/maps/MapsPackage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/android/src/main/java/com/airbnb/android/react/maps/MapsPackage.java b/lib/android/src/main/java/com/airbnb/android/react/maps/MapsPackage.java index da59849b36..6ecc551658 100644 --- a/lib/android/src/main/java/com/airbnb/android/react/maps/MapsPackage.java +++ b/lib/android/src/main/java/com/airbnb/android/react/maps/MapsPackage.java @@ -24,7 +24,7 @@ public List createNativeModules(ReactApplicationContext reactConte return Arrays.asList(new AirMapModule(reactContext)); } - @Override + // Deprecated RN 0.47 public List> createJSModules() { return Collections.emptyList(); } From 7f182ddc9c209bd9f9dbd27f7f93c5e5f14e6a5e Mon Sep 17 00:00:00 2001 From: Mike Lambert Date: Thu, 27 Jul 2017 12:49:18 -0400 Subject: [PATCH 04/20] Attempt to fix crashes. A variant of https://github.com/airbnb/react-native-maps/pull/1403 but for another lifecycle method, as proposed by @Nelrohd. (#1464) --- .../main/java/com/airbnb/android/react/maps/AirMapView.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java index 11e5786346..c1606eebbc 100644 --- a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java +++ b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java @@ -304,7 +304,9 @@ public void onHostResume() { map.setMyLocationEnabled(showUserLocation); } synchronized (AirMapView.this) { - AirMapView.this.onResume(); + if (!destroyed) { + AirMapView.this.onResume(); + } paused = false; } } From dd1b8aa9499769dda008cbba464ea9b7a5c21369 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Fri, 28 Jul 2017 02:50:59 +1000 Subject: [PATCH 05/20] Zoom level fixes (#1485) --- lib/ios/AirMaps/AIRMap.h | 1 + lib/ios/AirMaps/AIRMap.m | 4 ++++ lib/ios/AirMaps/AIRMapManager.h | 1 - lib/ios/AirMaps/AIRMapManager.m | 12 ++++++------ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ios/AirMaps/AIRMap.h b/lib/ios/AirMaps/AIRMap.h index 48a07ddb26..1d5f92cdcc 100644 --- a/lib/ios/AirMaps/AIRMap.h +++ b/lib/ios/AirMaps/AIRMap.h @@ -17,6 +17,7 @@ extern const CLLocationDegrees AIRMapDefaultSpan; extern const NSTimeInterval AIRMapRegionChangeObserveInterval; extern const CGFloat AIRMapZoomBoundBuffer; +extern const NSInteger AIRMapMaxZoomLevel; @interface AIRMap: MKMapView diff --git a/lib/ios/AirMaps/AIRMap.m b/lib/ios/AirMaps/AIRMap.m index a9db64ab45..647be4b8a5 100644 --- a/lib/ios/AirMaps/AIRMap.m +++ b/lib/ios/AirMaps/AIRMap.m @@ -21,6 +21,7 @@ const CLLocationDegrees AIRMapDefaultSpan = 0.005; const NSTimeInterval AIRMapRegionChangeObserveInterval = 0.1; const CGFloat AIRMapZoomBoundBuffer = 0.01; +const NSInteger AIRMapMaxZoomLevel = 20; @interface MKMapView (UIGestureRecognizer) @@ -79,6 +80,9 @@ - (instancetype)init // be identical to the built-in callout view (which has a private API) self.calloutView = [SMCalloutView platformCalloutView]; self.calloutView.delegate = self; + + self.minZoomLevel = 0; + self.maxZoomLevel = AIRMapMaxZoomLevel; } return self; } diff --git a/lib/ios/AirMaps/AIRMapManager.h b/lib/ios/AirMaps/AIRMapManager.h index 29df98bfc8..1d73b405e7 100644 --- a/lib/ios/AirMaps/AIRMapManager.h +++ b/lib/ios/AirMaps/AIRMapManager.h @@ -12,7 +12,6 @@ #define MERCATOR_RADIUS 85445659.44705395 #define MERCATOR_OFFSET 268435456 -#define MAX_GOOGLE_LEVELS 20 @interface AIRMapManager : RCTViewManager diff --git a/lib/ios/AirMaps/AIRMapManager.m b/lib/ios/AirMaps/AIRMapManager.m index 41b124aae8..76aef88fe7 100644 --- a/lib/ios/AirMaps/AIRMapManager.m +++ b/lib/ios/AirMaps/AIRMapManager.m @@ -637,10 +637,10 @@ - (void)mapView:(AIRMap *)mapView regionDidChangeAnimated:(__unused BOOL)animate [self _regionChanged:mapView]; - if (mapView.minZoomLevel != nil && zoomLevel < mapView.minZoomLevel) { + if (zoomLevel < mapView.minZoomLevel) { [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.minZoomLevel animated:TRUE mapView:mapView]; } - else if (mapView.maxZoomLevel != nil && zoomLevel > mapView.maxZoomLevel) { + else if (zoomLevel > mapView.maxZoomLevel) { [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.maxZoomLevel animated:TRUE mapView:mapView]; } @@ -814,7 +814,7 @@ - (MKCoordinateSpan)coordinateSpanWithMapView:(AIRMap *)mapView double centerPixelY = [AIRMapManager latitudeToPixelSpaceY:centerCoordinate.latitude]; // determine the scale value from the zoom level - double zoomExponent = 20 - zoomLevel; + double zoomExponent = AIRMapMaxZoomLevel - zoomLevel; double zoomScale = pow(2, zoomExponent); // scale the map’s size in pixel space @@ -850,7 +850,7 @@ - (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate mapView:(AIRMap *)mapView { // clamp large numbers to 28 - zoomLevel = MIN(zoomLevel, 28); + zoomLevel = MIN(zoomLevel, AIRMapMaxZoomLevel); // use the zoom level to compute the region MKCoordinateSpan span = [self coordinateSpanWithMapView:mapView centerCoordinate:centerCoordinate andZoomLevel:zoomLevel]; @@ -874,7 +874,7 @@ -(MKCoordinateRegion)coordinateRegionWithMapView:(AIRMap *)mapView double centerPixelY = [AIRMapManager latitudeToPixelSpaceY:centerCoordinate.latitude]; // determine the scale value from the zoom level - double zoomExponent = 20 - zoomLevel; + double zoomExponent = AIRMapMaxZoomLevel - zoomLevel; double zoomScale = pow(2, zoomExponent); // scale the map’s size in pixel space @@ -928,7 +928,7 @@ - (double) zoomLevel:(AIRMap *)mapView { CGSize mapSizeInPixels = mapView.bounds.size; double zoomScale = scaledMapWidth / mapSizeInPixels.width; double zoomExponent = log(zoomScale) / log(2); - double zoomLevel = 20 - zoomExponent; + double zoomLevel = AIRMapMaxZoomLevel - zoomExponent; return zoomLevel; } From db0d617c0e13a549c5d99b1758a00b6988db6e7b Mon Sep 17 00:00:00 2001 From: Matt Shen Date: Fri, 28 Jul 2017 02:54:50 +1000 Subject: [PATCH 06/20] skip region monitoring if map object is null (#1443) This happen if google play services version is lower than required --- .../main/java/com/airbnb/android/react/maps/AirMapView.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java index c1606eebbc..cfe581bd0b 100644 --- a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java +++ b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java @@ -701,13 +701,13 @@ public boolean dispatchTouchEvent(MotionEvent ev) { // Timer Implementation public void startMonitoringRegion() { - if (isMonitoringRegion) return; + if (map == null || isMonitoringRegion) return; timerHandler.postDelayed(timerRunnable, 100); isMonitoringRegion = true; } public void stopMonitoringRegion() { - if (!isMonitoringRegion) return; + if (map == null || !isMonitoringRegion) return; timerHandler.removeCallbacks(timerRunnable); isMonitoringRegion = false; } From 3235a341ccb74f1b156ee19eed69656ff5de40d0 Mon Sep 17 00:00:00 2001 From: Nikolay Radkov Date: Thu, 27 Jul 2017 19:57:19 +0300 Subject: [PATCH 07/20] Fix crashing the application when a user presses on the map and the Google Play Services need to be updated or at the moment of the process of updating (#1469) --- .../airbnb/android/react/maps/AirMapView.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java index cfe581bd0b..c8b016ce19 100644 --- a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java +++ b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java @@ -720,18 +720,20 @@ public void stopMonitoringRegion() { @Override public void run() { - Projection projection = map.getProjection(); - VisibleRegion region = (projection != null) ? projection.getVisibleRegion() : null; - LatLngBounds bounds = (region != null) ? region.latLngBounds : null; - - if ((bounds != null) && - (lastBoundsEmitted == null || - LatLngBoundsUtils.BoundsAreDifferent(bounds, lastBoundsEmitted))) { - LatLng center = map.getCameraPosition().target; - lastBoundsEmitted = bounds; - eventDispatcher.dispatchEvent(new RegionChangeEvent(getId(), bounds, center, true)); + if (map != null) { + Projection projection = map.getProjection(); + VisibleRegion region = (projection != null) ? projection.getVisibleRegion() : null; + LatLngBounds bounds = (region != null) ? region.latLngBounds : null; + + if ((bounds != null) && + (lastBoundsEmitted == null || + LatLngBoundsUtils.BoundsAreDifferent(bounds, lastBoundsEmitted))) { + LatLng center = map.getCameraPosition().target; + lastBoundsEmitted = bounds; + eventDispatcher.dispatchEvent(new RegionChangeEvent(getId(), bounds, center, true)); + } } - + timerHandler.postDelayed(this, 100); } }; From 28388a73e209ae30083e466dd3dc64fe1c441d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20B=C3=B8ving?= Date: Thu, 27 Jul 2017 19:10:06 +0200 Subject: [PATCH 08/20] Fix timing function used in AnimatedRegion.spring (#1479) --- lib/components/AnimatedRegion.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/components/AnimatedRegion.js b/lib/components/AnimatedRegion.js index 29356ca9e3..ad18c5e077 100644 --- a/lib/components/AnimatedRegion.js +++ b/lib/components/AnimatedRegion.js @@ -111,25 +111,25 @@ export default class AnimatedMapRegion extends AnimatedWithChildren { spring(config) { var animations = []; config.hasOwnProperty('latitude') && - animations.push(Animated.timing(this.latitude, { + animations.push(Animated.spring(this.latitude, { ...config, toValue: config.latitude })); config.hasOwnProperty('longitude') && - animations.push(Animated.timing(this.longitude, { + animations.push(Animated.spring(this.longitude, { ...config, toValue: config.longitude })); config.hasOwnProperty('latitudeDelta') && - animations.push(Animated.timing(this.latitudeDelta, { + animations.push(Animated.spring(this.latitudeDelta, { ...config, toValue: config.latitudeDelta })); config.hasOwnProperty('longitudeDelta') && - animations.push(Animated.timing(this.longitudeDelta, { + animations.push(Animated.spring(this.longitudeDelta, { ...config, toValue: config.longitudeDelta })); From 6357776523cf1d423f8d579b079bdfdecb7b24e6 Mon Sep 17 00:00:00 2001 From: Andre Shonubi Date: Wed, 9 Aug 2017 17:53:45 -0400 Subject: [PATCH 09/20] Document MapView min/max zoom properties (#1538) --- docs/mapview.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/mapview.md b/docs/mapview.md index e8b86aee65..a73e123b8c 100644 --- a/docs/mapview.md +++ b/docs/mapview.md @@ -22,6 +22,8 @@ | `showsIndoors` | `Boolean` | `true` | A Boolean indicating whether indoor maps should be enabled. | `showsIndoorLevelPicker` | `Boolean` | `false` | A Boolean indicating whether indoor level picker should be enabled. **Note:** Android only. | `zoomEnabled` | `Boolean` | `true` | If `false` the user won't be able to pinch/zoom the map. +| `minZoomLevel` | `Number` | `0` | Minimum zoom value for the map, must be between 0 and 20 +| `maxZoomLevel` | `Number` | `20` | Maximum zoom value for the map, must be between 0 and 20 | `rotateEnabled` | `Boolean` | `true` | If `false` the user won't be able to pinch/rotate the map. | `scrollEnabled` | `Boolean` | `true` | If `false` the user won't be able to change the map region being displayed. | `pitchEnabled` | `Boolean` | `true` | If `false` the user won't be able to adjust the camera’s pitch angle. From 4cc4e45f6275ade05c7e0da3141e4a5d3983b6dc Mon Sep 17 00:00:00 2001 From: Christopher Dro Date: Wed, 9 Aug 2017 15:07:10 -0700 Subject: [PATCH 10/20] v0.16.0 --- CHANGELOG.md | 7 +++++++ lib/android/gradle.properties | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50b2027bc2..45c5bd082f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 0.16.0 (August 9, 2017) +* Android: [#1481](https://github.com/airbnb/react-native-maps/pull/#1481) Handle Android RN 0.47 breaking change +* iOS: [#1357](https://github.com/airbnb/react-native-maps/pull/1357) add MKTileOverlayRenderer +* iOS: [#1369](https://github.com/airbnb/react-native-maps/pull/1369) Add onMapReady callback +* Android/iOS/JS: [#1360](https://github.com/airbnb/react-native-maps/pull/1360) Add minZoom and maxZoom properties for android and ios +* JS: [#1479](https://github.com/airbnb/react-native-maps/pull/1479) Fix timing function used in AnimatedRegion.spring + ## 0.15.3 (June 27, 2017) * iOS: [#1362](https://github.com/airbnb/react-native-maps/pull/1362) Updates for React 0.43-0.45 and React 16. diff --git a/lib/android/gradle.properties b/lib/android/gradle.properties index 1a5d3021b8..ddc39b69d6 100644 --- a/lib/android/gradle.properties +++ b/lib/android/gradle.properties @@ -1,5 +1,5 @@ VERSION_CODE=4 -VERSION_NAME=0.15.3 +VERSION_NAME=0.16.0 GROUP=com.airbnb.android POM_DESCRIPTION=React Native Map view component for Android diff --git a/package.json b/package.json index 7cb48301ba..408db6b031 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "React Native Mapview component for iOS + Android", "main": "index.js", "author": "Leland Richardson ", - "version": "0.15.3", + "version": "0.16.0", "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "run:packager": "./node_modules/react-native/packager/packager.sh", From c9c52ab9ccb0e8f446f457be54e04f151b6a2f47 Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Tue, 15 Aug 2017 08:35:08 -0700 Subject: [PATCH 11/20] fix `Archive` configuration for iOS builds (#1550) --- example/ios/Podfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/example/ios/Podfile b/example/ios/Podfile index 656f283e1f..66771a383e 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -36,5 +36,9 @@ post_install do |installer| config.build_settings['CLANG_ENABLE_MODULES'] = 'No' end end + + if target.name == "React" + target.remove_from_project + end end end From fd8dc08ffaa0fadbaa73d9e29033a16f808e318f Mon Sep 17 00:00:00 2001 From: foyarash Date: Tue, 15 Aug 2017 17:37:10 +0200 Subject: [PATCH 12/20] Fix initial region native prop (#1546) * Fix initial region bug * Remove useless change --- lib/components/MapView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/components/MapView.js b/lib/components/MapView.js index e3763f8f3b..f9b974aecb 100644 --- a/lib/components/MapView.js +++ b/lib/components/MapView.js @@ -450,7 +450,7 @@ class MapView extends React.Component { if (region) { this.map.setNativeProps({ region }); } else if (initialRegion) { - this.map.setNativeProps({ region: initialRegion }); + this.map.setNativeProps({ initialRegion }); } this._updateStyle(); this.setState({ isReady: true }, () => { From b908c08ac2367652249918f4f5694eaf17a1eac2 Mon Sep 17 00:00:00 2001 From: "Wanseob (Eric) Kim" Date: Tue, 15 Aug 2017 11:35:13 -0700 Subject: [PATCH 13/20] Issue1176 improve ios marker performance by X100 (#1187) * Issue1176 attempt to fix UI lag success by re-using UIImage * Now use NSMutableDictionary instead of single UIImage * appearAnimation happen at init rather than setIcon * Init NSMutableDictionary * Remove reference to other app --- lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m | 80 +++++----------------- lib/ios/AirGoogleMaps/GlobalVars.h | 22 ++++++ lib/ios/AirGoogleMaps/GlobalVars.m | 54 +++++++++++++++ 3 files changed, 92 insertions(+), 64 deletions(-) create mode 100644 lib/ios/AirGoogleMaps/GlobalVars.h create mode 100644 lib/ios/AirGoogleMaps/GlobalVars.m diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m b/lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m index c41be55bbb..9d96dfafc1 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m +++ b/lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m @@ -12,6 +12,7 @@ #import "AIRGMSMarker.h" #import "AIRGoogleMapCallout.h" #import "DummyView.h" +#import "GlobalVars.h" CGRect unionRect(CGRect a, CGRect b) { return CGRectMake( @@ -36,6 +37,7 @@ - (instancetype)init if ((self = [super init])) { _realMarker = [[AIRGMSMarker alloc] init]; _realMarker.fakeMarker = self; + _realMarker.appearAnimation = kGMSMarkerAnimationPop; } return self; } @@ -92,6 +94,18 @@ - (void)insertReactSubview:(id)subview atIndex:(NSInteger)atIndex [super insertReactSubview:(UIView*)dummySubview atIndex:atIndex]; } +- (void)setIcon:(UIImage*)image { + CGImageRef cgref = [image CGImage]; + CIImage *cim = [image CIImage]; + + if (cim == nil && cgref == NULL) { + // image does not contain image data + _realMarker.icon = [GMSMarker markerImageWithColor:UIColor.blueColor]; + } else { + _realMarker.icon = image; + } +} + - (void)removeReactSubview:(id)dummySubview { UIView* subview = ((DummyView*)dummySubview).view; @@ -188,70 +202,8 @@ - (void)setOpacity:(double)opacity - (void)setImageSrc:(NSString *)imageSrc { - _imageSrc = imageSrc; - - if (_reloadImageCancellationBlock) { - _reloadImageCancellationBlock(); - _reloadImageCancellationBlock = nil; - } - - if (!_imageSrc) { - if (_iconImageView) [_iconImageView removeFromSuperview]; - return; - } - - if (!_iconImageView) { - // prevent glitch with marker (cf. https://github.com/airbnb/react-native-maps/issues/738) - UIImageView *empyImageView = [[UIImageView alloc] init]; - _iconImageView = empyImageView; - [self iconViewInsertSubview:_iconImageView atIndex:0]; - } - - _reloadImageCancellationBlock = [_bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc] - size:self.bounds.size - scale:RCTScreenScale() - clipped:YES - resizeMode:RCTResizeModeCenter - progressBlock:nil - partialLoadBlock:nil - completionBlock:^(NSError *error, UIImage *image) { - if (error) { - // TODO(lmr): do something with the error? - NSLog(@"%@", error); - } - dispatch_async(dispatch_get_main_queue(), ^{ - - // TODO(gil): This way allows different image sizes - if (_iconImageView) [_iconImageView removeFromSuperview]; - - // ... but this way is more efficient? -// if (_iconImageView) { -// [_iconImageView setImage:image]; -// return; -// } - - UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; - - // TODO: w,h or pixel density could be a prop. - float density = 1; - float w = image.size.width/density; - float h = image.size.height/density; - CGRect bounds = CGRectMake(0, 0, w, h); - - imageView.contentMode = UIViewContentModeScaleAspectFit; - [imageView setFrame:bounds]; - - // NOTE: sizeToFit doesn't work instead. Not sure why. - // TODO: Doing it this way is not ideal because it causes things to reshuffle - // when the image loads IF the image is larger than the UIView. - // Shouldn't required images have size info automatically via RN? - CGRect selfBounds = unionRect(bounds, self.bounds); - [self setFrame:selfBounds]; - - _iconImageView = imageView; - [self iconViewInsertSubview:imageView atIndex:0]; - }); - }]; + UIImage * image = [[GlobalVars sharedInstance] getSharedUIImage:imageSrc]; + [self setIcon:image]; } - (void)setTitle:(NSString *)title { diff --git a/lib/ios/AirGoogleMaps/GlobalVars.h b/lib/ios/AirGoogleMaps/GlobalVars.h new file mode 100644 index 0000000000..86c3555f7a --- /dev/null +++ b/lib/ios/AirGoogleMaps/GlobalVars.h @@ -0,0 +1,22 @@ +// +// GlobalVars.h +// +// Created by Eric Kim on 2017-04-04. +// Copyright © 2017 Apply Digital. All rights reserved. +// + +#import +#import + +@interface GlobalVars : NSObject +{ + NSMutableDictionary *dict; +} + ++ (GlobalVars *)sharedInstance; + +- (UIImage *)getSharedUIImage:(NSString *)imageSrc; + +@property(strong, nonatomic, readwrite) NSMutableDictionary *dict; + +@end diff --git a/lib/ios/AirGoogleMaps/GlobalVars.m b/lib/ios/AirGoogleMaps/GlobalVars.m new file mode 100644 index 0000000000..7a541dab41 --- /dev/null +++ b/lib/ios/AirGoogleMaps/GlobalVars.m @@ -0,0 +1,54 @@ +// +// GlobalVars.m +// +// Created by Eric Kim on 2017-04-04. +// Copyright © 2017 Apply Digital. All rights reserved. +// + +#import "GlobalVars.h" + +@implementation GlobalVars + +@synthesize dict = _dict; + ++ (GlobalVars *)sharedInstance { + static dispatch_once_t onceToken; + static GlobalVars *instance = nil; + dispatch_once(&onceToken, ^{ + instance = [[GlobalVars alloc] init]; + }); + return instance; +} + +- (UIImage *)getSharedUIImage:(NSString *)imageSrc { + + UIImage* cachedImage = dict[imageSrc]; + + CGImageRef cgref = [cachedImage CGImage]; + CIImage *cim = [cachedImage CIImage]; + + if (cim == nil && cgref == NULL) { + UIImage *newImage; + if ([imageSrc hasPrefix:@"http://"] || [imageSrc hasPrefix:@"https://"]){ + NSURL *url = [NSURL URLWithString:imageSrc]; + NSData *data = [NSData dataWithContentsOfURL:url]; + newImage = [UIImage imageWithData:data scale:[UIScreen mainScreen].scale]; + } else { + newImage = [UIImage imageWithContentsOfFile:imageSrc]; + } + dict[imageSrc] = newImage; + return newImage; + } else { + return cachedImage; + } +} + +- (id)init { + self = [super init]; + if (self) { + dict = [[NSMutableDictionary alloc] init]; + } + return self; +} + +@end From 75a38eab271b83d37a7f4089de806acac1a4865d Mon Sep 17 00:00:00 2001 From: Ben Speakman Date: Tue, 15 Aug 2017 19:36:25 +0100 Subject: [PATCH 14/20] Add legalNotice constant (#1458) --- .../com/airbnb/android/react/maps/AirMapModule.java | 11 +++++++++++ lib/ios/AirGoogleMaps/AIRGoogleMapManager.m | 3 +++ 2 files changed, 14 insertions(+) diff --git a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapModule.java b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapModule.java index 1a096255e6..bd1fb6ed0f 100644 --- a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapModule.java +++ b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapModule.java @@ -15,6 +15,7 @@ import com.facebook.react.uimanager.UIBlock; import com.facebook.react.uimanager.UIManagerModule; import com.google.android.gms.maps.GoogleMap; +import com.google.android.gms.common.GoogleApiAvailability; import java.io.ByteArrayOutputStream; import java.io.Closeable; @@ -22,6 +23,9 @@ import java.io.FileOutputStream; import java.io.IOException; +import java.util.Map; +import java.util.HashMap; + import javax.annotation.Nullable; public class AirMapModule extends ReactContextBaseJavaModule { @@ -40,6 +44,13 @@ public String getName() { return "AirMapModule"; } + @Override + public Map getConstants() { + final Map constants = new HashMap<>(); + constants.put("legalNotice", GoogleApiAvailability.getInstance().getOpenSourceSoftwareLicenseInfo(getReactApplicationContext())); + return constants; + } + public Activity getActivity() { return getCurrentActivity(); } diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m b/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m index 53157e99a5..086822b73a 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m +++ b/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m @@ -222,6 +222,9 @@ - (UIView *)view }]; } +- (NSDictionary *)constantsToExport { + return @{ @"legalNotice": [GMSServices openSourceLicenseInfo] }; +} - (void)mapViewDidFinishTileRendering:(GMSMapView *)mapView { AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView; From 971d91e522d7ad517a0d944b57c873483b78f9e2 Mon Sep 17 00:00:00 2001 From: foyarash Date: Tue, 15 Aug 2017 20:39:50 +0200 Subject: [PATCH 15/20] Update marker component (#1428) --- lib/components/MapMarker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/components/MapMarker.js b/lib/components/MapMarker.js index 6e2b8585dd..b81bab87af 100644 --- a/lib/components/MapMarker.js +++ b/lib/components/MapMarker.js @@ -257,7 +257,7 @@ class MapMarker extends React.Component { let image; if (this.props.image) { image = resolveAssetSource(this.props.image) || {}; - image = image.uri; + image = image.uri || this.props.image; } const AIRMapMarker = this.getAirComponent(); From a3b15c6466570bb58cc23b4868bb7124e891e020 Mon Sep 17 00:00:00 2001 From: Guilherme Pontes Date: Tue, 15 Aug 2017 20:41:53 +0200 Subject: [PATCH 16/20] Enhance Podfile. (#1252) --- example/ios/Podfile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/example/ios/Podfile b/example/ios/Podfile index 66771a383e..fd01b85a01 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -5,9 +5,10 @@ platform :ios, '8.0' # Change 'AirMapsExplorer' to match the target in your Xcode project. target 'AirMapsExplorer' do + rn_path = '../../node_modules/react-native' - pod 'Yoga', :path => '../../node_modules/react-native/ReactCommon/yoga/Yoga.podspec' - pod 'React', path: '../../node_modules/react-native', :subspecs => [ + pod 'Yoga', path: "#{rn_path}/ReactCommon/yoga/Yoga.podspec" + pod 'React', path: rn_path, subspecs: [ 'Core', 'RCTActionSheet', 'RCTAnimation', @@ -22,16 +23,14 @@ target 'AirMapsExplorer' do 'BatchedBridge' ] - pod 'GoogleMaps' # <~~ remove this line if you do not want to support GoogleMaps on iOS + pod 'GoogleMaps' # Remove this line if you don't want to support GoogleMaps on iOS pod 'react-native-maps', path: '../../' - pod 'react-native-google-maps', path: '../../' # <~~ if you need GoogleMaps support on iOS - + pod 'react-native-google-maps', path: '../../' # If you need GoogleMaps support on iOS end - post_install do |installer| installer.pods_project.targets.each do |target| - if target.name == "react-native-google-maps" + if target.name == 'react-native-google-maps' target.build_configurations.each do |config| config.build_settings['CLANG_ENABLE_MODULES'] = 'No' end From f953252223c119d61522d9923197b79575458a81 Mon Sep 17 00:00:00 2001 From: Christopher Dro Date: Tue, 15 Aug 2017 11:47:11 -0700 Subject: [PATCH 17/20] v0.16.1 --- CHANGELOG.md | 8 +++++++- lib/android/gradle.properties | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45c5bd082f..5ae94159d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ # Change Log +## 0.16.1 (August 15, 2017) +* Android: [#1428](https://github.com/airbnb/react-native-maps/pull/#1428) Add ability to load marker image from drawable +* iOS: [#1187](https://github.com/airbnb/react-native-maps/pull/1187) Improve marker performance +* iOS/Android: [#1458](https://github.com/airbnb/react-native-maps/pull/1458) Add Google Maps legalNotice constant +* JS: [#1546](https://github.com/airbnb/react-native-maps/pull/1546) Fix initial region native prop + ## 0.16.0 (August 9, 2017) -* Android: [#1481](https://github.com/airbnb/react-native-maps/pull/#1481) Handle Android RN 0.47 breaking change +* Android: [#1481](https://github.com/airbnb/react-native-maps/pull/1481) Handle Android RN 0.47 breaking change * iOS: [#1357](https://github.com/airbnb/react-native-maps/pull/1357) add MKTileOverlayRenderer * iOS: [#1369](https://github.com/airbnb/react-native-maps/pull/1369) Add onMapReady callback * Android/iOS/JS: [#1360](https://github.com/airbnb/react-native-maps/pull/1360) Add minZoom and maxZoom properties for android and ios diff --git a/lib/android/gradle.properties b/lib/android/gradle.properties index ddc39b69d6..04d072cc5d 100644 --- a/lib/android/gradle.properties +++ b/lib/android/gradle.properties @@ -1,5 +1,5 @@ VERSION_CODE=4 -VERSION_NAME=0.16.0 +VERSION_NAME=0.16.1 GROUP=com.airbnb.android POM_DESCRIPTION=React Native Map view component for Android diff --git a/package.json b/package.json index 408db6b031..104be9b045 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "React Native Mapview component for iOS + Android", "main": "index.js", "author": "Leland Richardson ", - "version": "0.16.0", + "version": "0.16.1", "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "run:packager": "./node_modules/react-native/packager/packager.sh", From 4376c97304b47033bbd3562aeff8da451a4f520d Mon Sep 17 00:00:00 2001 From: foyarash Date: Thu, 17 Aug 2017 18:38:38 +0200 Subject: [PATCH 18/20] Fix initial region android (#1563) * Fix initial region on android * Fix initial region for android --- .../com/airbnb/android/react/maps/AirMapManager.java | 5 +++++ .../java/com/airbnb/android/react/maps/AirMapView.java | 10 +++++++++- lib/components/MapView.js | 5 ++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java index e8f98a7663..9ba6295cd1 100644 --- a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java +++ b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java @@ -75,6 +75,11 @@ public void setRegion(AirMapView view, ReadableMap region) { view.setRegion(region); } + @ReactProp(name = "initialRegion") + public void setInitialRegion(AirMapView view, ReadableMap initialRegion) { + view.setInitialRegion(initialRegion); + } + @ReactProp(name = "mapType") public void setMapType(AirMapView view, @Nullable String mapType) { int typeId = MAP_TYPES.get(mapType); diff --git a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java index c8b016ce19..14983dc79d 100644 --- a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java +++ b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java @@ -70,6 +70,7 @@ public class AirMapView extends MapView implements GoogleMap.InfoWindowAdapter, private boolean handlePanDrag = false; private boolean moveOnMarkerPress = true; private boolean cacheEnabled = false; + private boolean initialRegionSet = false; private static final String[] PERMISSIONS = new String[]{ "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"}; @@ -360,6 +361,13 @@ public synchronized void doDestroy() { onDestroy(); } + public void setInitialRegion(ReadableMap initialRegion) { + if (!initialRegionSet && initialRegion != null) { + setRegion(initialRegion); + initialRegionSet = true; + } + } + public void setRegion(ReadableMap region) { if (region == null) return; @@ -733,7 +741,7 @@ public void run() { eventDispatcher.dispatchEvent(new RegionChangeEvent(getId(), bounds, center, true)); } } - + timerHandler.postDelayed(this, 100); } }; diff --git a/lib/components/MapView.js b/lib/components/MapView.js index f9b974aecb..a0f3fa02c5 100644 --- a/lib/components/MapView.js +++ b/lib/components/MapView.js @@ -462,10 +462,13 @@ class MapView extends React.Component { const { layout } = e.nativeEvent; if (!layout.width || !layout.height) return; if (this.state.isReady && !this.__layoutCalled) { - const region = this.props.region || this.props.initialRegion; + const { region, initialRegion } = this.props; if (region) { this.__layoutCalled = true; this.map.setNativeProps({ region }); + } else if (initialRegion) { + this.__layoutCalled = true; + this.map.setNativeProps({ initialRegion }); } } if (this.props.onLayout) { From cbdeeafca8f7fc38a398ac105bda94713342c5ae Mon Sep 17 00:00:00 2001 From: Christopher Dro Date: Thu, 17 Aug 2017 09:50:54 -0700 Subject: [PATCH 19/20] Revert "Issue1176 improve ios marker performance by X100 (#1187)" This reverts commit b908c08ac2367652249918f4f5694eaf17a1eac2. --- lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m | 80 +++++++++++++++++----- lib/ios/AirGoogleMaps/GlobalVars.h | 22 ------ lib/ios/AirGoogleMaps/GlobalVars.m | 54 --------------- 3 files changed, 64 insertions(+), 92 deletions(-) delete mode 100644 lib/ios/AirGoogleMaps/GlobalVars.h delete mode 100644 lib/ios/AirGoogleMaps/GlobalVars.m diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m b/lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m index 9d96dfafc1..c41be55bbb 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m +++ b/lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m @@ -12,7 +12,6 @@ #import "AIRGMSMarker.h" #import "AIRGoogleMapCallout.h" #import "DummyView.h" -#import "GlobalVars.h" CGRect unionRect(CGRect a, CGRect b) { return CGRectMake( @@ -37,7 +36,6 @@ - (instancetype)init if ((self = [super init])) { _realMarker = [[AIRGMSMarker alloc] init]; _realMarker.fakeMarker = self; - _realMarker.appearAnimation = kGMSMarkerAnimationPop; } return self; } @@ -94,18 +92,6 @@ - (void)insertReactSubview:(id)subview atIndex:(NSInteger)atIndex [super insertReactSubview:(UIView*)dummySubview atIndex:atIndex]; } -- (void)setIcon:(UIImage*)image { - CGImageRef cgref = [image CGImage]; - CIImage *cim = [image CIImage]; - - if (cim == nil && cgref == NULL) { - // image does not contain image data - _realMarker.icon = [GMSMarker markerImageWithColor:UIColor.blueColor]; - } else { - _realMarker.icon = image; - } -} - - (void)removeReactSubview:(id)dummySubview { UIView* subview = ((DummyView*)dummySubview).view; @@ -202,8 +188,70 @@ - (void)setOpacity:(double)opacity - (void)setImageSrc:(NSString *)imageSrc { - UIImage * image = [[GlobalVars sharedInstance] getSharedUIImage:imageSrc]; - [self setIcon:image]; + _imageSrc = imageSrc; + + if (_reloadImageCancellationBlock) { + _reloadImageCancellationBlock(); + _reloadImageCancellationBlock = nil; + } + + if (!_imageSrc) { + if (_iconImageView) [_iconImageView removeFromSuperview]; + return; + } + + if (!_iconImageView) { + // prevent glitch with marker (cf. https://github.com/airbnb/react-native-maps/issues/738) + UIImageView *empyImageView = [[UIImageView alloc] init]; + _iconImageView = empyImageView; + [self iconViewInsertSubview:_iconImageView atIndex:0]; + } + + _reloadImageCancellationBlock = [_bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc] + size:self.bounds.size + scale:RCTScreenScale() + clipped:YES + resizeMode:RCTResizeModeCenter + progressBlock:nil + partialLoadBlock:nil + completionBlock:^(NSError *error, UIImage *image) { + if (error) { + // TODO(lmr): do something with the error? + NSLog(@"%@", error); + } + dispatch_async(dispatch_get_main_queue(), ^{ + + // TODO(gil): This way allows different image sizes + if (_iconImageView) [_iconImageView removeFromSuperview]; + + // ... but this way is more efficient? +// if (_iconImageView) { +// [_iconImageView setImage:image]; +// return; +// } + + UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; + + // TODO: w,h or pixel density could be a prop. + float density = 1; + float w = image.size.width/density; + float h = image.size.height/density; + CGRect bounds = CGRectMake(0, 0, w, h); + + imageView.contentMode = UIViewContentModeScaleAspectFit; + [imageView setFrame:bounds]; + + // NOTE: sizeToFit doesn't work instead. Not sure why. + // TODO: Doing it this way is not ideal because it causes things to reshuffle + // when the image loads IF the image is larger than the UIView. + // Shouldn't required images have size info automatically via RN? + CGRect selfBounds = unionRect(bounds, self.bounds); + [self setFrame:selfBounds]; + + _iconImageView = imageView; + [self iconViewInsertSubview:imageView atIndex:0]; + }); + }]; } - (void)setTitle:(NSString *)title { diff --git a/lib/ios/AirGoogleMaps/GlobalVars.h b/lib/ios/AirGoogleMaps/GlobalVars.h deleted file mode 100644 index 86c3555f7a..0000000000 --- a/lib/ios/AirGoogleMaps/GlobalVars.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// GlobalVars.h -// -// Created by Eric Kim on 2017-04-04. -// Copyright © 2017 Apply Digital. All rights reserved. -// - -#import -#import - -@interface GlobalVars : NSObject -{ - NSMutableDictionary *dict; -} - -+ (GlobalVars *)sharedInstance; - -- (UIImage *)getSharedUIImage:(NSString *)imageSrc; - -@property(strong, nonatomic, readwrite) NSMutableDictionary *dict; - -@end diff --git a/lib/ios/AirGoogleMaps/GlobalVars.m b/lib/ios/AirGoogleMaps/GlobalVars.m deleted file mode 100644 index 7a541dab41..0000000000 --- a/lib/ios/AirGoogleMaps/GlobalVars.m +++ /dev/null @@ -1,54 +0,0 @@ -// -// GlobalVars.m -// -// Created by Eric Kim on 2017-04-04. -// Copyright © 2017 Apply Digital. All rights reserved. -// - -#import "GlobalVars.h" - -@implementation GlobalVars - -@synthesize dict = _dict; - -+ (GlobalVars *)sharedInstance { - static dispatch_once_t onceToken; - static GlobalVars *instance = nil; - dispatch_once(&onceToken, ^{ - instance = [[GlobalVars alloc] init]; - }); - return instance; -} - -- (UIImage *)getSharedUIImage:(NSString *)imageSrc { - - UIImage* cachedImage = dict[imageSrc]; - - CGImageRef cgref = [cachedImage CGImage]; - CIImage *cim = [cachedImage CIImage]; - - if (cim == nil && cgref == NULL) { - UIImage *newImage; - if ([imageSrc hasPrefix:@"http://"] || [imageSrc hasPrefix:@"https://"]){ - NSURL *url = [NSURL URLWithString:imageSrc]; - NSData *data = [NSData dataWithContentsOfURL:url]; - newImage = [UIImage imageWithData:data scale:[UIScreen mainScreen].scale]; - } else { - newImage = [UIImage imageWithContentsOfFile:imageSrc]; - } - dict[imageSrc] = newImage; - return newImage; - } else { - return cachedImage; - } -} - -- (id)init { - self = [super init]; - if (self) { - dict = [[NSMutableDictionary alloc] init]; - } - return self; -} - -@end From fad3aabba4c65047ae7c8d12019ec0818b9556be Mon Sep 17 00:00:00 2001 From: Christopher Dro Date: Thu, 17 Aug 2017 09:55:00 -0700 Subject: [PATCH 20/20] v0.16.2 --- CHANGELOG.md | 4 ++++ lib/android/gradle.properties | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae94159d4..f9ae8057e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 0.16.2 (August 17, 2017) +* Android: [#1563](https://github.com/airbnb/react-native-maps/pull/#1563) Add missing native method for setting initial region +* iOS: [#1187](https://github.com/airbnb/react-native-maps/pull/1187) Reverted due to build issues + ## 0.16.1 (August 15, 2017) * Android: [#1428](https://github.com/airbnb/react-native-maps/pull/#1428) Add ability to load marker image from drawable * iOS: [#1187](https://github.com/airbnb/react-native-maps/pull/1187) Improve marker performance diff --git a/lib/android/gradle.properties b/lib/android/gradle.properties index 04d072cc5d..9b4cf86c94 100644 --- a/lib/android/gradle.properties +++ b/lib/android/gradle.properties @@ -1,5 +1,5 @@ VERSION_CODE=4 -VERSION_NAME=0.16.1 +VERSION_NAME=0.16.2 GROUP=com.airbnb.android POM_DESCRIPTION=React Native Map view component for Android diff --git a/package.json b/package.json index 104be9b045..6914f242bb 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "React Native Mapview component for iOS + Android", "main": "index.js", "author": "Leland Richardson ", - "version": "0.16.1", + "version": "0.16.2", "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "run:packager": "./node_modules/react-native/packager/packager.sh",