@lugg/maps 1.0.0-beta.1 → 1.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -354,7 +354,7 @@ class GoogleMapProvider(private val context: Context) :
354
354
 
355
355
  val point = map.projection.toScreenLocation(marker.position)
356
356
  contentView.translationX = point.x - contentView.width * calloutView.anchorX
357
- contentView.translationY = point.y - contentView.height * calloutView.anchorY
357
+ contentView.translationY = point.y - markerView.contentView.height * markerView.anchorY - contentView.height * calloutView.anchorY
358
358
  }
359
359
 
360
360
  // endregion
@@ -13,6 +13,7 @@
13
13
  @property(nonatomic, copy, nullable) NSString *subtitle;
14
14
  @property(nonatomic, strong) LuggMarkerView *markerView;
15
15
  @property(nonatomic, weak) MKAnnotationView *annotationView;
16
+ @property(nonatomic, copy, nullable) dispatch_block_t pendingScaleAnimation;
16
17
  @end
17
18
 
18
19
  @implementation AppleMarkerAnnotation
@@ -572,6 +573,7 @@
572
573
  [contentView removeFromSuperview];
573
574
 
574
575
  contentView.userInteractionEnabled = YES;
576
+ contentView.hidden = YES;
575
577
  calloutView.delegate = self;
576
578
 
577
579
  AppleMarkerAnnotation *annotation =
@@ -611,8 +613,7 @@
611
613
  if (annotationView && contentView.superview == annotationView) {
612
614
  CGPoint center = CGPointMake(annotationView.bounds.size.width / 2.0 +
613
615
  contentSize.width * (0.5 - anchor.x),
614
- annotationView.bounds.size.height / 2.0 +
615
- contentSize.height * (0.5 - anchor.y));
616
+ contentSize.height * (0.5 - anchor.y));
616
617
  contentView.center = center;
617
618
  } else {
618
619
  CGPoint point =
@@ -622,6 +623,8 @@
622
623
  CGPointMake(point.x + contentSize.width * (0.5 - anchor.x),
623
624
  point.y + contentSize.height * (0.5 - anchor.y));
624
625
  }
626
+
627
+ contentView.hidden = NO;
625
628
  }
626
629
 
627
630
  - (void)dismissNonBubbledCallout {
@@ -784,6 +787,10 @@
784
787
  (AppleMarkerAnnotation *)markerView.marker;
785
788
 
786
789
  if (annotation) {
790
+ if (annotation.pendingScaleAnimation) {
791
+ dispatch_block_cancel(annotation.pendingScaleAnimation);
792
+ annotation.pendingScaleAnimation = nil;
793
+ }
787
794
  annotation.annotationView.transform = CGAffineTransformIdentity;
788
795
  annotation.markerView = nil;
789
796
  annotation.annotationView = nil;
@@ -802,31 +809,65 @@
802
809
  annotationView.transform = CGAffineTransformIdentity;
803
810
 
804
811
  UIView *iconView = markerView.iconView;
805
- CGRect frame = iconView.frame;
806
- if (frame.size.width <= 0 || frame.size.height <= 0)
812
+ iconView.transform = CGAffineTransformIdentity;
813
+
814
+ // Clean up iconView from in-progress rasterize animation
815
+ if (markerView.rasterize && [iconView superview] == annotationView) {
816
+ [iconView removeFromSuperview];
817
+ iconView.layer.anchorPoint = CGPointMake(0.5, 0.5);
818
+ }
819
+
820
+ CGSize size = iconView.bounds.size;
821
+ if (size.width <= 0 || size.height <= 0)
807
822
  return;
808
823
 
809
824
  CGFloat scale = markerView.scale;
810
825
  CGPoint anchor = markerView.anchor;
826
+ CGFloat scaledWidth = size.width * scale;
827
+ CGFloat scaledHeight = size.height * scale;
811
828
 
812
- if (markerView.rasterize) {
813
- annotationView.image = [markerView createScaledIconImage];
814
- } else {
815
- iconView.layer.anchorPoint = anchor;
816
- iconView.transform = CGAffineTransformMakeScale(scale, scale);
817
- iconView.frame =
818
- CGRectMake(frame.size.width * (0.5 - anchor.x) * (scale - 1),
819
- frame.size.height * (0.5 - anchor.y) * (scale - 1),
820
- frame.size.width, frame.size.height);
829
+ AppleMarkerAnnotation *annotation =
830
+ (AppleMarkerAnnotation *)markerView.marker;
831
+
832
+ // Cancel any pending rasterize
833
+ if (annotation.pendingScaleAnimation) {
834
+ dispatch_block_cancel(annotation.pendingScaleAnimation);
835
+ annotation.pendingScaleAnimation = nil;
836
+ }
837
+
838
+ // Use live iconView during rapid updates (skip expensive rasterize per frame)
839
+ if (markerView.rasterize && [iconView superview] != annotationView) {
840
+ annotationView.image = nil;
841
+ [annotationView addSubview:iconView];
821
842
  }
822
843
 
823
- annotationView.bounds =
824
- CGRectMake(0, 0, frame.size.width * scale, frame.size.height * scale);
825
- annotationView.centerOffset =
826
- CGPointMake(frame.size.width * scale * (anchor.x - 0.5),
827
- -frame.size.height * scale * (anchor.y - 0.5));
844
+ iconView.layer.anchorPoint = anchor;
845
+ iconView.bounds = CGRectMake(0, 0, size.width, size.height);
846
+ iconView.center =
847
+ CGPointMake(scaledWidth * anchor.x, scaledHeight * anchor.y);
848
+ iconView.transform = CGAffineTransformMakeScale(scale, scale);
849
+
850
+ annotationView.bounds = CGRectMake(0, 0, scaledWidth, scaledHeight);
851
+ annotationView.centerOffset = CGPointMake(scaledWidth * (0.5 - anchor.x),
852
+ scaledHeight * (0.5 - anchor.y));
828
853
  annotationView.transform =
829
854
  CGAffineTransformMakeRotation(markerView.rotate * M_PI / 180.0);
855
+
856
+ // Debounce: rasterize once updates settle
857
+ if (markerView.rasterize) {
858
+ dispatch_block_t rasterizeBlock =
859
+ dispatch_block_create((dispatch_block_flags_t)0, ^{
860
+ annotation.pendingScaleAnimation = nil;
861
+ annotationView.image = [markerView createScaledIconImage];
862
+ [iconView removeFromSuperview];
863
+ [markerView resetIconViewTransform];
864
+ });
865
+
866
+ annotation.pendingScaleAnimation = rasterizeBlock;
867
+ dispatch_after(
868
+ dispatch_time(DISPATCH_TIME_NOW, (int64_t)(150 * NSEC_PER_MSEC)),
869
+ dispatch_get_main_queue(), rasterizeBlock);
870
+ }
830
871
  }
831
872
 
832
873
  - (void)updateAnnotationViewFrame:(AppleMarkerAnnotation *)annotation {
@@ -311,9 +311,16 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
311
311
  [markerView emitPressEventWithPoint:point];
312
312
 
313
313
  LuggCalloutView *calloutView = markerView.calloutView;
314
- if (calloutView && !calloutView.bubbled && calloutView.hasCustomContent) {
314
+ if (calloutView && calloutView.hasCustomContent) {
315
315
  [mapView animateToLocation:marker.position];
316
- [self showNonBubbledCallout:markerView];
316
+
317
+ dispatch_async(dispatch_get_main_queue(), ^{
318
+ if (calloutView.bubbled) {
319
+ mapView.selectedMarker = marker;
320
+ } else {
321
+ [self showNonBubbledCallout:markerView];
322
+ }
323
+ });
317
324
  return YES;
318
325
  }
319
326
  }
@@ -397,11 +404,15 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
397
404
  [contentView removeFromSuperview];
398
405
 
399
406
  contentView.userInteractionEnabled = YES;
407
+ contentView.hidden = YES;
400
408
  calloutView.delegate = self;
401
409
  [_wrapperView addSubview:contentView];
402
410
 
403
411
  _activeNonBubbledMarker = markerView;
404
- [self positionNonBubbledCallout];
412
+ dispatch_async(dispatch_get_main_queue(), ^{
413
+ [self positionNonBubbledCallout];
414
+ contentView.hidden = NO;
415
+ });
405
416
  }
406
417
 
407
418
  - (void)calloutViewDidUpdate:(LuggCalloutView *)calloutView {
@@ -432,9 +443,14 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
432
443
  CGPoint point = [_mapView.projection
433
444
  pointForCoordinate:_activeNonBubbledMarker.coordinate];
434
445
 
446
+ UIView *iconView = _activeNonBubbledMarker.iconView;
447
+ CGFloat markerHeight =
448
+ iconView.bounds.size.height * _activeNonBubbledMarker.scale;
449
+
435
450
  contentView.center =
436
451
  CGPointMake(point.x + contentSize.width * (0.5 - anchor.x),
437
- point.y + contentSize.height * (0.5 - anchor.y));
452
+ point.y - markerHeight * _activeNonBubbledMarker.anchor.y +
453
+ contentSize.height * (0.5 - anchor.y));
438
454
  }
439
455
 
440
456
  #pragma mark - MarkerViewDelegate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lugg/maps",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "Universal maps for React Native.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",