Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0eb2745

Browse files
authored
fix(ios): safe area memory leak on iOS 10 and older versions (#10673)
1 parent 5f8fb2c commit 0eb2745

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,38 @@ export class IOSHelper {
200200
}
201201
}
202202

203+
/**
204+
* This method simulates the iOS 11+ safeAreaLayoutGuide property and its constraints for older versions.
205+
*
206+
* @param controller
207+
* @param owner
208+
*/
203209
static updateConstraints(controller: UIViewController, owner: View): void {
204210
if (!__VISIONOS__ && SDK_VERSION <= 10) {
205-
const layoutGuide = IOSHelper.initLayoutGuide(controller);
206-
(<any>controller.view).safeAreaLayoutGuide = layoutGuide;
211+
if (!controller.view.safeAreaLayoutGuide) {
212+
IOSHelper.initLayoutGuide(controller);
213+
}
207214
}
208215
}
209216

210-
static initLayoutGuide(controller: UIViewController) {
217+
/**
218+
* This method simulates the iOS 11+ safeAreaLayoutGuide property for older versions.
219+
*
220+
* @param controller
221+
*/
222+
static initLayoutGuide(controller: UIViewController): UILayoutGuide {
211223
const rootView = controller.view;
212-
const layoutGuide = UILayoutGuide.new();
213-
rootView.addLayoutGuide(layoutGuide);
214-
NSLayoutConstraint.activateConstraints(<any>[layoutGuide.topAnchor.constraintEqualToAnchor(controller.topLayoutGuide.bottomAnchor), layoutGuide.bottomAnchor.constraintEqualToAnchor(controller.bottomLayoutGuide.topAnchor), layoutGuide.leadingAnchor.constraintEqualToAnchor(rootView.leadingAnchor), layoutGuide.trailingAnchor.constraintEqualToAnchor(rootView.trailingAnchor)]);
215224

216-
return layoutGuide;
225+
if (!rootView.safeAreaLayoutGuide) {
226+
const layoutGuide = UILayoutGuide.new();
227+
228+
rootView.addLayoutGuide(layoutGuide);
229+
NSLayoutConstraint.activateConstraints([layoutGuide.topAnchor.constraintEqualToAnchor(controller.topLayoutGuide.bottomAnchor), layoutGuide.bottomAnchor.constraintEqualToAnchor(controller.bottomLayoutGuide.topAnchor), layoutGuide.leadingAnchor.constraintEqualToAnchor(rootView.leadingAnchor), layoutGuide.trailingAnchor.constraintEqualToAnchor(rootView.trailingAnchor)]);
230+
231+
(<any>rootView).safeAreaLayoutGuide = layoutGuide;
232+
}
233+
234+
return rootView.safeAreaLayoutGuide;
217235
}
218236

219237
static layoutView(controller: UIViewController, owner: View): void {

0 commit comments

Comments
 (0)