8000 fix(google-maps): info window · NativeScript/plugins@c7a066a · GitHub
[go: up one dir, main page]

Skip to content

Commit c7a066a

Browse files
committed
fix(google-maps): info window
1 parent 56be6e0 commit c7a066a

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed

packages/google-maps/index.ios.ts

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Color, EventData, GridLayout, ImageSource, Utils, View } from '@nativescript/core';
1+
import { Color, EventData, GridLayout, ImageSource, Screen, Utils, View } from '@nativescript/core';
22
import { isNullOrUndefined } from '@nativescript/core/utils/types';
33
import {
44
ActiveBuildingEvent,
@@ -47,6 +47,11 @@ import {
4747
} from '.';
4848
import { bearingProperty, JointType, latProperty, lngProperty, MapType, MapViewBase, tiltProperty, zoomProperty } from './common';
4949
import { deserialize, intoNativeCircleOptions, intoNativeGroundOverlayOptions, intoNativeMarkerOptions, intoNativePolygonOptions, intoNativePolylineOptions, serialize } from './utils';
50+
import { layout } from '@nativescript/core/utils';
51+
52+
const native_ = Symbol('[[native]]');
53+
54+
declare const NSCCustomInfoView;
5055

5156
export class CameraUpdate implements ICameraUpdate {
5257
_native: GMSCameraUpdate;
@@ -443,21 +448,39 @@ class GMSMapViewDelegateImpl extends NSObject implements GMSMapViewDelegate {
443448
owner.notify(event);
444449

445450
if (event.view instanceof View) {
446-
if (!event.view.parent && !event.view?.nativeView) {
447-
owner._addView(event.view);
448-
}
449-
if (event.view.nativeView && !(<any>marker)._view) {
450-
(<any>marker)._view = UIView.new();
451-
}
452-
const parent = event.view.nativeView?.superview;
453-
if (event.view.nativeView && parent !== (<any>marker)._view) {
454-
if (parent) {
455-
event.view.nativeView.removeFromSuperview();
451+
let parent = marker[native_];
452+
let container = (<any>marker)._view as never as GridLayout;
453+
if (!parent) {
454+
parent = NSCCustomInfoView.new();
455+
container = new GridLayout();
456+
parent.backgroundColor = UIColor.clearColor;
457+
(<any>marker)._view = container;
458+
marker[native_] = parent;
459+
container._setupAsRootView({});
460+
container._setupUI({});
461+
container.callLoaded();
462+
parent.addSubview(container.nativeView);
463+
} else {
464+
if (event.view.parent !== container) {
465+
container.removeChildren();
456466
}
457-
const container: UIView = (<any>marker)._view;
458-
container.addSubview(event.view.nativeView);
459467
}
460-
return (<any>marker)?._view ?? null;
468+
469+
if (!event.view.parent) {
470+
container.addChild(event.view);
471+
} else if (event.view.parent !== container) {
472+
(<GridLayout>event?.view?.parent)?.removeChild?.(event.view);
473+
container.addChild(event.view);
474+
}
475+
476+
const w = layout.makeMeasureSpec(500 * Screen.mainScreen.scale, layout.AT_MOST);
477+
const h = layout.makeMeasureSpec(500 * Screen.mainScreen.scale, layout.AT_MOST);
478+
const size = View.measureChild(container, event.view, w, h);
479+
480+
View.layoutChild(container, event.view, 0, 0, size.measuredWidth, size.measuredHeight);
481+
parent.frame = CGRectMake(0, 0, size.measuredWidth / Screen.mainScreen.scale, size.measuredHeight / Screen.mainScreen.scale);
482+
483+
return parent;
461484
} else if (event.view instanceof UIView) {
462485
return event.view;
463486
}
@@ -478,13 +501,18 @@ class GMSMapViewDelegateImpl extends NSObject implements GMSMapViewDelegate {
478501
owner.notify(event);
479502

480503
if (event.view instanceof View) {
504+
let parent = marker[native_];
481505
let container = (<any>marker)._view as never as GridLayout;
482-
if (!container) {
506+
if (!parent) {
507+
parent = NSCCustomInfoView.new();
483508
container = new GridLayout();
509+
parent.backgroundColor = UIColor.clearColor;
484510
(<any>marker)._view = container;
511+
marker[native_] = parent;
485512
container._setupAsRootView({});
486513
container._setupUI({});
487514
container.callLoaded();
515+
parent.addSubview(container.nativeView);
488516
} else {
489517
if (event.view.parent !== container) {
490518
container.removeChildren();
@@ -498,7 +526,14 @@ class GMSMapViewDelegateImpl extends NSObject implements GMSMapViewDelegate {
498526
container.addChild(event.view);
499527
}
500528

501-
return event.view.nativeView;
529+
const w = layout.makeMeasureSpec(500 * Screen.mainScreen.scale, layout.AT_MOST);
530+
const h = layout.makeMeasureSpec(500 * Screen.mainScreen.scale, layout.AT_MOST);
531+
const size = View.measureChild(container, event.view, w, h);
532+
533+
View.layoutChild(container, event.view, 0, 0, size.measuredWidth, size.measuredHeight);
534+
parent.frame = CGRectMake(0, 0, size.measuredWidth / Screen.mainScreen.scale, size.measuredHeight / Screen.mainScreen.scale);
535+
536+
return parent;
502537
} else if (event.view instanceof UIView) {
503538
return event.view;
504539
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Foundation
2+
import UIKit
3+
4+
@objc(NSCCustomInfoView)
5+
@objcMembers
6+
public class NSCCustomInfoView: UIView {
7+
public override func didMoveToSuperview() {
8+
superview?.autoresizesSubviews = false;
9+
}
10+
}

0 commit comments

Comments
 (0)
0