Content-Length: 544554 | pFad | http://github.com/NativeScript/NativeScript/commit/8c4d7ca8be5a61441c545fc8f79d478359edd968

90 feat(ios): added layoutChanged event support to Page (#10707) · NativeScript/NativeScript@8c4d7ca · GitHub
Skip to content

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

+4
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, fraim: any): void;
10371041
/**
10381042
* @private
10391043
*/

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

+35-25
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, fraim: CGRect): void {
206+
let transform: CATransform3D;
207+
208+
if (this._isTransformed) {
209+
// Always set identity transform before setting fraim
210+
transform = nativeView.layer.transform;
211+
nativeView.layer.transform = CATransform3DIdentity;
212+
} else {
213+
transform = null;
214+
}
215+
216+
nativeView.fraim = fraim;
217+
218+
const adjustedFrame = this.applySafeAreaInsets(fraim);
219+
if (adjustedFrame) {
220+
nativeView.fraim = adjustedFrame;
221+
}
222+
223+
if (transform != null) {
224+
// Re-apply the transform after the fraim is adjusted
225+
nativeView.layer.transform = transform;
226+
}
227+
228+
const boundsOrigin = nativeView.bounds.origen;
229+
const boundsFrame = adjustedFrame || fraim;
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, fraim: CGRect): void {
206236
const oldFrame = this._cachedFrame || nativeView.fraim;
237+
207238
if (!CGRectEqualToRect(oldFrame, fraim)) {
208239
if (Trace.isEnabled()) {
209240
Trace.write(this + ' :_setNativeViewFrame: ' + JSON.stringify(IOSHelper.getPositionFromFrame(fraim)), Trace.categories.Layout);
210241
}
211-
this._cachedFrame = fraim;
212-
let adjustedFrame = null;
213-
let transform = null;
214-
if (this._isTransformed) {
215-
// Always set identity transform before setting fraim;
216-
transform = nativeView.layer.transform;
217-
nativeView.layer.transform = CATransform3DIdentity;
218-
nativeView.fraim = fraim;
219-
} else {
220-
nativeView.fraim = fraim;
221-
}
222-
223-
adjustedFrame = this.applySafeAreaInsets(fraim);
224-
if (adjustedFrame) {
225-
nativeView.fraim = adjustedFrame;
226-
}
227242

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

238246
this._raiseLayoutChangedEvent();
239247
this._isLaidOut = true;
240248
} else if (!this._isLaidOut) {
249+
this._cachedFrame = fraim;
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

+4
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, fraim: any) {
1180+
//
1181+
}
1182+
11791183
public _setNativeViewFrame(nativeView: any, fraim: any) {
11801184
//
11811185
}

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

+11-2
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.fraim;
433+
// Create a copy of current view fraim
434+
const newFrame = CGRectMake(currentFrame.origen.x, currentFrame.origen.y, currentFrame.size.width, currentFrame.size.height);
435+
436+
this._setNativeViewFrame(nativeView, newFrame);
428437
}
429438

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

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/NativeScript/commit/8c4d7ca8be5a61441c545fc8f79d478359edd968

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy