mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-06 17:28:29 +08:00
feat(ios): added layoutChanged event support to Page (#10707)
This commit is contained in:

committed by
GitHub

parent
e52d13bfcf
commit
8c4d7ca8be
4
packages/core/ui/core/view/index.d.ts
vendored
4
packages/core/ui/core/view/index.d.ts
vendored
@ -1034,6 +1034,10 @@ export abstract class View extends ViewCommon {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_goToVisualState(state: string);
|
_goToVisualState(state: string);
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_modifyNativeViewFrame(nativeView: any, frame: any): void;
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
@ -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 {
|
public _setNativeViewFrame(nativeView: UIView, frame: CGRect): void {
|
||||||
const oldFrame = this._cachedFrame || nativeView.frame;
|
const oldFrame = this._cachedFrame || nativeView.frame;
|
||||||
|
|
||||||
if (!CGRectEqualToRect(oldFrame, frame)) {
|
if (!CGRectEqualToRect(oldFrame, frame)) {
|
||||||
if (Trace.isEnabled()) {
|
if (Trace.isEnabled()) {
|
||||||
Trace.write(this + ' :_setNativeViewFrame: ' + JSON.stringify(IOSHelper.getPositionFromFrame(frame)), Trace.categories.Layout);
|
Trace.write(this + ' :_setNativeViewFrame: ' + JSON.stringify(IOSHelper.getPositionFromFrame(frame)), Trace.categories.Layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._cachedFrame = frame;
|
this._cachedFrame = frame;
|
||||||
let adjustedFrame = null;
|
this._modifyNativeViewFrame(nativeView, frame);
|
||||||
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._raiseLayoutChangedEvent();
|
this._raiseLayoutChangedEvent();
|
||||||
this._isLaidOut = true;
|
this._isLaidOut = true;
|
||||||
} else if (!this._isLaidOut) {
|
} else if (!this._isLaidOut) {
|
||||||
|
this._cachedFrame = frame;
|
||||||
|
|
||||||
// Rects could be equal on the first layout and an event should be raised.
|
// Rects could be equal on the first layout and an event should be raised.
|
||||||
this._raiseLayoutChangedEvent();
|
this._raiseLayoutChangedEvent();
|
||||||
// But make sure event is raised only once if rects are equal on the first layout as
|
// But make sure event is raised only once if rects are equal on the first layout as
|
||||||
|
@ -1176,6 +1176,10 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
|||||||
super.resetNativeView();
|
super.resetNativeView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _modifyNativeViewFrame(nativeView: any, frame: any) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
public _setNativeViewFrame(nativeView: any, frame: any) {
|
public _setNativeViewFrame(nativeView: any, frame: any) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
@ -424,10 +424,19 @@ export class Page extends PageBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
|
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) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user