Skip to content

fix(ios): Added layoutChanged event support to Page #10707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/ui/core/view/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,10 @@ export abstract class View extends ViewCommon {
* @private
*/
_goToVisualState(state: string);
/**
* @private
*/
_modifyNativeViewFrame(nativeView: any, frame: any): void;
/**
* @private
*/
Expand Down
60 changes: 35 additions & 25 deletions packages/core/ui/core/view/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/core/ui/core/view/view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
//
}
Expand Down
13 changes: 11 additions & 2 deletions packages/core/ui/page/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
//
}

Expand Down