From d075462a494c822b5146e77ba19ac00490e041af Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Fri, 17 Nov 2017 08:49:00 +0200 Subject: [PATCH] Fixed onMapReady event on iOS to resemble onMapReady on Android (Closes #1793) Also: Closes #1776, Closes #1696, Closes #1680, Closes #1605) Probably closes more issues related to iOS, panning and scrolling. --- lib/ios/AirGoogleMaps/AIRGoogleMap.h | 2 +- lib/ios/AirGoogleMaps/AIRGoogleMap.m | 2 +- lib/ios/AirGoogleMaps/AIRGoogleMapManager.m | 18 ++++++++++-------- lib/ios/AirMaps/AIRMapManager.m | 14 ++++++++++---- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMap.h b/lib/ios/AirGoogleMaps/AIRGoogleMap.h index d2a8e3e6f..fa0293ae3 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMap.h +++ b/lib/ios/AirGoogleMaps/AIRGoogleMap.h @@ -42,7 +42,7 @@ @property (nonatomic, assign) BOOL showsMyLocationButton; @property (nonatomic, assign) BOOL showsIndoorLevelPicker; -- (void)didFinishTileRendering; +- (void)didPrepareMap; - (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 f10238531..4c1976fe7 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMap.m +++ b/lib/ios/AirGoogleMaps/AIRGoogleMap.m @@ -155,7 +155,7 @@ - (void)setRegion:(MKCoordinateRegion)region { self.camera = [AIRGoogleMap makeGMSCameraPositionFromMap:self andMKCoordinateRegion:region]; } -- (void)didFinishTileRendering { +- (void)didPrepareMap { if (self.onMapReady) self.onMapReady(@{}); } diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m b/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m index 867b41803..559b6be3d 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m +++ b/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m @@ -32,7 +32,10 @@ @interface AIRGoogleMapManager() - +{ + BOOL didCallOnMapReady; +} + @end @implementation AIRGoogleMapManager @@ -263,13 +266,12 @@ - (NSDictionary *)constantsToExport { return @{ @"legalNotice": [GMSServices openSourceLicenseInfo] }; } -+ (BOOL)requiresMainQueueSetup { - return YES; -} - -- (void)mapViewDidFinishTileRendering:(GMSMapView *)mapView { - AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView; - [googleMapView didFinishTileRendering]; +- (void)mapViewDidStartTileRendering:(GMSMapView *)mapView { + if (didCallOnMapReady) return; + didCallOnMapReady = YES; + + AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView; + [googleMapView didPrepareMap]; } - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker { diff --git a/lib/ios/AirMaps/AIRMapManager.m b/lib/ios/AirMaps/AIRMapManager.m index 483834369..1124c440c 100644 --- a/lib/ios/AirMaps/AIRMapManager.m +++ b/lib/ios/AirMaps/AIRMapManager.m @@ -36,7 +36,10 @@ @interface AIRMapManager() @end @implementation AIRMapManager - +{ + BOOL didCallOnMapReady; +} + RCT_EXPORT_MODULE() - (UIView *)view @@ -708,6 +711,12 @@ - (void)mapView:(AIRMap *)mapView regionDidChangeAnimated:(__unused BOOL)animate - (void)mapViewWillStartRenderingMap:(AIRMap *)mapView { + if (!didCallOnMapReady) + { + didCallOnMapReady = YES; + mapView.onMapReady(@{}); + } + mapView.hasStartedRendering = YES; [mapView beginLoading]; [self _emitRegionChangeEvent:mapView continuous:NO]; @@ -716,9 +725,6 @@ - (void)mapViewWillStartRenderingMap:(AIRMap *)mapView - (void)mapViewDidFinishRenderingMap:(AIRMap *)mapView fullyRendered:(BOOL)fullyRendered { [mapView finishLoading]; - [mapView cacheViewIfNeeded]; - - mapView.onMapReady(@{}); } #pragma mark Private