8000 feat(ios): added layoutChanged event support to Page (#10707) · NativeScript/NativeScript@8c4d7ca · GitHub
[go: up one dir, main page]

Skip to content {"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}

Commit 8c4d7ca

Browse files
authored
feat(ios): added layoutChanged event support to Page (#10707)
1 parent e52d13b commit 8c4d7ca

File tree

4 files changed

+54
-27
lines changed

4 files changed

+54
-27
lines changed

packages/core/ui/core/view/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,10 @@ export abstract class View extends ViewCommon {
10341034
* @private
10351035
*/
10361036
_goToVisualState(state: string);
1037+
/**
1038+
* @private
1039+
*/
1040+
_modifyNativeViewFrame(nativeView: any, frame: any): void;
10371041
/**
10381042
* @private
10391043
*/

packages/core/ui/core/view/index.ios.ts

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -202,42 +202,52 @@ export class View extends ViewCommon implements ViewDefinition {
202202
//
203203
}
204204

205+
public _modifyNativeViewFrame(nativeView: UIView, frame: CGRect): void {
206+
let transform: CATransform3D;
207+
208+
if (this._isTransformed) {
209+
// Always set identity transform before setting frame
210+
transform = nativeView.layer.transform;
211+
nativeView.layer.transform = CATransform3DIdentity;
212+
} else {
213+
transform = null;
214+
}
215+
216+
nativeView.frame = frame;
217+
218+
const adjustedFrame = this.applySafeAreaInsets(frame);
219+
if (adjustedFrame) {
220+
nativeView.frame = adjustedFrame;
221+
}
222+
223+
if (transform != null) {
224+
// Re-apply the transform after the frame is adjusted
225+
nativeView.layer.transform = transform;
226+
}
227+
228+
const boundsOrigin = nativeView.bounds.origin;
229+
const boundsFrame = adjustedFrame || frame;
230+
231+
nativeView.bounds = CGRectMake(boundsOrigin.x, boundsOrigin.y, boundsFrame.size.width, boundsFrame.size.height);
232+
nativeView.layoutIfNeeded();
233+
}
234+
205235
public _setNativeViewFrame(nativeView: UIView, frame: CGRect): void {
206236
const oldFrame = this._cachedFrame || nativeView.frame;
237+
207238
if (!CGRectEqualToRect(oldFrame, frame)) {
208239
if (Trace.isEnabled()) {
209240
Trace.write(this + ' :_setNativeViewFrame: ' + JSON.stringify(IOSHelper.getPositionFromFrame(frame)), Trace.categories.Layout);
210241
}
211-
this._cachedFrame = frame;
212-
let adjustedFrame = null;
213-
let transform = null;
214-
if (this._isTransformed) {
215-
// Always set identity transform before setting frame;
216-
transform = nativeView.layer.transform;
217-
nativeView.layer.transform = CATransform3DIdentity;
218-
nativeView.frame = frame;
219-
} else {
220-
nativeView.frame = frame;
221-
}
222-
223-
adjustedFrame = this.applySafeAreaInsets(frame);
224-
if (adjustedFrame) {
225-
nativeView.frame = adjustedFrame;
226-
}
227242

228-
if (this._isTransformed) {
229-
// re-apply the transform after the frame is adjusted
230-
nativeView.layer.transform = transform;
231-
}
232-
233-
const boundsOrigin = nativeView.bounds.origin;
234-
const boundsFrame = adjustedFrame || frame;
235-
nativeView.bounds = CGRectMake(boundsOrigin.x, boundsOrigin.y, boundsFrame.size.width, boundsFrame.size.height);
236-
nativeView.layoutIfNeeded();
243+
this._cachedFrame = frame;
244+
this._modifyNativeViewFrame(nativeView, frame);
237245

238246
this._raiseLayoutChangedEvent();
239247
this._isLaidOut = true;
240248
} else if (!this._isLaidOut) {
249+
this._cachedFrame = frame;
250+
241251
// Rects could be equal on the first layout and an event should be raised.
242252
this._raiseLayoutChangedEvent();
243253
// But make sure event is raised only once if rects are equal on the first layout as

packages/core/ui/core/view/view-common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,10 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
11761176
super.resetNativeView();
11771177
}
11781178

1179+
public _modifyNativeViewFrame(nativeView: any, frame: any) {
1180+
//
1181+
}
1182+
11791183
public _setNativeViewFrame(nativeView: any, frame: any) {
11801184
//
11811185
}

packages/core/ui/page/index.ios.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,19 @@ export class Page extends PageBase {
424424
}
425425

426426
public layoutNativeView(left: number, top: number, right: number, bottom: number): void {
427-
//
427+
const nativeView = this.nativeViewProtected;
428+
if (!nativeView) {
429+
return;
430+
}
431+
432+
const currentFrame = nativeView.frame;
433+
// Create a copy of current view frame
434+
const newFrame = CGRectMake(currentFrame.origin.x, currentFrame.origin.y, currentFrame.size.width, currentFrame.size.height);
435+
436+
this._setNativeViewFrame(nativeView, newFrame);
428437
}
429438

430-
public _setNativeViewFrame(nativeView: UIView, frame: CGRect) {
439+
public _modifyNativeViewFrame(nativeView: UIView, frame: CGRect) {
431440
//
432441
}
433442

0 commit comments

Comments
 (0)
0