diff --git a/packages/core/ui/core/view/index.d.ts b/packages/core/ui/core/view/index.d.ts index 568c1941db..7186aaeb6b 100644 --- a/packages/core/ui/core/view/index.d.ts +++ b/packages/core/ui/core/view/index.d.ts @@ -1034,6 +1034,10 @@ export abstract class View extends ViewCommon { * @private */ _goToVisualState(state: string); + /** + * @private + */ + _modifyNativeViewFrame(nativeView: any, frame: any): void; /** * @private */ diff --git a/packages/core/ui/core/view/index.ios.ts b/packages/core/ui/core/view/index.ios.ts index 854b3836bd..39d3d2f485 100644 --- a/packages/core/ui/core/view/index.ios.ts +++ b/packages/core/ui/core/view/index.ios.ts @@ -202,42 +202,52 @@ export class View extends ViewCommon implements ViewDefinition { // } + public _modifyNativeViewFrame(nativeView: UIView, frame: CGRect): void { + let transform: CATransform3D; + + if (this._isTransformed) { + // Always set identity transform before setting frame + transform = nativeView.layer.transform; + nativeView.layer.transform = CATransform3DIdentity; + } else { + transform = null; + } + + nativeView.frame = frame; + + const adjustedFrame = this.applySafeAreaInsets(frame); + if (adjustedFrame) { + nativeView.frame = adjustedFrame; + } + + if (transform != null) { + // Re-apply the transform after the frame is adjusted + nativeView.layer.transform = transform; + } + + const boundsOrigin = nativeView.bounds.origin; + const boundsFrame = adjustedFrame || frame; + + nativeView.bounds = CGRectMake(boundsOrigin.x, boundsOrigin.y, boundsFrame.size.width, boundsFrame.size.height); + nativeView.layoutIfNeeded(); + } + public _setNativeViewFrame(nativeView: UIView, frame: CGRect): void { const oldFrame = this._cachedFrame || nativeView.frame; + if (!CGRectEqualToRect(oldFrame, frame)) { if (Trace.isEnabled()) { Trace.write(this + ' :_setNativeViewFrame: ' + JSON.stringify(IOSHelper.getPositionFromFrame(frame)), Trace.categories.Layout); } - this._cachedFrame = frame; - let adjustedFrame = null; - let transform = null; - if (this._isTransformed) { - // Always set identity transform before setting frame; - transform = nativeView.layer.transform; - nativeView.layer.transform = CATransform3DIdentity; - nativeView.frame = frame; - } else { - nativeView.frame = frame; - } - - adjustedFrame = this.applySafeAreaInsets(frame); - if (adjustedFrame) { - nativeView.frame = adjustedFrame; - } - if (this._isTransformed) { - // re-apply the transform after the frame is adjusted - nativeView.layer.transform = transform; - } - - const boundsOrigin = nativeView.bounds.origin; - const boundsFrame = adjustedFrame || frame; - nativeView.bounds = CGRectMake(boundsOrigin.x, boundsOrigin.y, boundsFrame.size.width, boundsFrame.size.height); - nativeView.layoutIfNeeded(); + this._cachedFrame = frame; + this._modifyNativeViewFrame(nativeView, frame); this._raiseLayoutChangedEvent(); this._isLaidOut = true; } else if (!this._isLaidOut) { + this._cachedFrame = frame; + // Rects could be equal on the first layout and an event should be raised. this._raiseLayoutChangedEvent(); // But make sure event is raised only once if rects are equal on the first layout as diff --git a/packages/core/ui/core/view/view-common.ts b/packages/core/ui/core/view/view-common.ts index 65ab18f466..3610fa1965 100644 --- a/packages/core/ui/core/view/view-common.ts +++ b/packages/core/ui/core/view/view-common.ts @@ -1176,6 +1176,10 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { super.resetNativeView(); } + public _modifyNativeViewFrame(nativeView: any, frame: any) { + // + } + public _setNativeViewFrame(nativeView: any, frame: any) { // } diff --git a/packages/core/ui/page/index.ios.ts b/packages/core/ui/page/index.ios.ts index 8313c5c18a..a36bce5fb7 100644 --- a/packages/core/ui/page/index.ios.ts +++ b/packages/core/ui/page/index.ios.ts @@ -424,10 +424,19 @@ export class Page extends PageBase { } public layoutNativeView(left: number, top: number, right: number, bottom: number): void { - // + const nativeView = this.nativeViewProtected; + if (!nativeView) { + return; + } + + const currentFrame = nativeView.frame; + // Create a copy of current view frame + const newFrame = CGRectMake(currentFrame.origin.x, currentFrame.origin.y, currentFrame.size.width, currentFrame.size.height); + + this._setNativeViewFrame(nativeView, newFrame); } - public _setNativeViewFrame(nativeView: UIView, frame: CGRect) { + public _modifyNativeViewFrame(nativeView: UIView, frame: CGRect) { // }