8000 Merge pull request #3543 from NativeScript/fix-modal-crashes · jensWorkGit/NativeScript@1765afa · GitHub
[go: up one dir, main page]

Skip to content

Commit 1765afa

Browse files
author
Alexander Vakrilov
authored
Merge pull request NativeScript#3543 from NativeScript/fix-modal-crashes
Fix: Modal crashes in Android and IOS
2 parents 703e634 + 6b61335 commit 1765afa

File tree

5 files changed

+34
-46
lines changed

5 files changed

+34
-46
lines changed

tns-core-modules/application/application.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ typedExports.start = function (entry?: NavigationEntry) {
291291
if(window) {
292292
var rootController = window.rootViewController;
293293
if(rootController) {
294-
rootController.presentViewControllerAnimatedCompletion(rootView.ios.controller, utils.ios.MajorVersion >= 7, null);
294+
rootController.presentViewControllerAnimatedCompletion(rootView.ios.controller, true, null);
295295
uiUtils.ios._layoutRootView(rootView, utils.ios.getter(UIScreen, UIScreen.mainScreen).bounds);
296296
}
297297
}

tns-core-modules/ui/core/view.ios.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,7 @@ export class View extends ViewCommon {
155155
return;
156156
}
157157

158-
// This is done because when rotated in iOS7 there is rotation applied on the first subview on the Window which is our frame.nativeView.view.
159-
// // If we set it it should be transformed so it is correct.
160-
// // When in landscape in iOS 7 there is transformation on the first subview of the window so we set frame to its subview.
161-
// // in iOS 8 we set frame to subview again otherwise we get clipped.
162-
// let nativeView: UIView;
163-
// if (!this.parent && this.nativeView.subviews.count > 0 && ios.MajorVersion < 8) {
164-
// if (traceEnabled()) {
165-
// traceWrite(this + " has no parent. Setting frame to first child instead.", traceCategories.Layout);
166-
// }
167-
// nativeView = (<UIView>this.nativeView.subviews[0]);
168-
// }
169-
// else {
170158
let nativeView = this.nativeView;
171-
// }
172159

173160
let frame = CGRectMake(left, top, right - left, bottom - top);
174161
this._setNativeViewFrame(nativeView, frame);

tns-core-modules/ui/dialogs/dialogs.ios.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { isString, isDefined, isFunction } from "utils/types";
88
import * as utils from "utils/utils";
99
import getter = utils.ios.getter;
1010

11+
export * from "./dialogs-common";
12+
1113
class UIAlertViewDelegateImpl extends NSObject implements UIAlertViewDelegate {
1214
public static ObjCProtocols = [UIAlertViewDelegate];
1315

tns-core-modules/ui/page/page.android.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ function ensureDialogFragmentClass() {
3939
this._owner.verticalAlignment = this._fullscreen ? VerticalAlignment.STRETCH : VerticalAlignment.MIDDLE;
4040
this._owner.actionBarHidden = true;
4141

42-
dialog.setContentView(this._owner._nativeView, this._owner._nativeView.getLayoutParams());
42+
const nativeView = <android.view.View>this._owner._nativeView;
43+
let layoutParams = nativeView.getLayoutParams();
44+
if (!layoutParams) {
45+
layoutParams = new org.nativescript.widgets.CommonLayoutParams();
46+
nativeView.setLayoutParams(layoutParams);
47+
}
48+
dialog.setContentView(this._owner._nativeView, layoutParams);
4349

4450
const window = dialog.getWindow();
4551
window.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));

tns-core-modules/ui/page/page.ios.ts

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ class UIViewControllerImpl extends UIViewController {
8484
return;
8585
}
8686

87-
if (owner._modalParent) {
88-
let isTablet = device.deviceType === "Tablet";
89-
let isFullScreen = !owner._UIModalPresentationFormSheet || !isTablet;
87+
const modalParent = owner._modalParent;
88+
if (modalParent) {
89+
// if inside horizontally compact environment - fullScreen will be forced
90+
let isFullScreen = !owner._UIModalPresentationFormSheet ||
91+
(modalParent.nativeView.traitCollection.horizontalSizeClass === UIUserInterfaceSizeClass.Compact);
92+
9093
let frame = isFullScreen ? getter(UIScreen, UIScreen.mainScreen).bounds : this.view.frame;
9194
let size = frame.size;
9295
let width = size.width;
@@ -99,12 +102,6 @@ class UIViewControllerImpl extends UIViewController {
99102
superViewRotationRadians = atan2f(transform.b, transform.a);
100103
}
101104

102-
if (ios.MajorVersion < 8 && ios.isLandscape() && !superViewRotationRadians) {
103-
// in iOS 7 when in landscape we switch width with height because on device they don't change even when rotated.
104-
width = size.height;
105-
height = size.width;
106-
}
107-
108105
let bottom = height;
109106
let statusBarHeight = uiUtils.ios.getStatusBarHeight();
110107
let statusBarVisible = !getter(UIApplication, UIApplication.sharedApplication).statusBarHidden;
@@ -116,20 +113,9 @@ class UIViewControllerImpl extends UIViewController {
116113
let widthSpec = layout.makeMeasureSpec(width, mode);
117114
let heightSpec = layout.makeMeasureSpec(height, mode);
118115

119-
View.measureChild(owner._modalParent, owner, widthSpec, heightSpec);
120-
let top = ((backgroundSpanUnderStatusBar && isFullScreen) || ios.MajorVersion < 8 || !isFullScreen) ? 0 : statusBarHeight;
121-
View.layoutChild(owner._modalParent, owner, 0, top, width, bottom);
122-
123-
if (ios.MajorVersion < 8) {
124-
if (!backgroundSpanUnderStatusBar && (!isTablet || isFullScreen)) {
125-
if (ios.isLandscape() && !superViewRotationRadians) {
126-
this.view.center = CGPointMake(this.view.center.x - statusBarHeight, this.view.center.y);
127-
}
128-
else {
129-
this.view.center = CGPointMake(this.view.center.x, this.view.center.y + statusBarHeight);
130-
}
131-
}
132-
}
116+
View.measureChild(modalParent, owner, widthSpec, heightSpec);
117+
let top = ((backgroundSpanUnderStatusBar && isFullScreen) || !isFullScreen) ? 0 : statusBarHeight;
118+
View.layoutChild(modalParent, owner, 0, top, width, bottom);
133119

134120
if (traceEnabled()) {
135121
traceWrite(owner + ", native frame = " + NSStringFromCGRect(this.view.frame), traceCategories.Layout);
@@ -156,8 +142,9 @@ class UIViewControllerImpl extends UIViewController {
156142
return;
157143
}
158144

159-
let frame = this.navigationController ? (<any>this.navigationController).owner : null;
160-
let newEntry = this[ENTRY];
145+
const frame = this.navigationController ? (<any>this.navigationController).owner : null;
146+
const newEntry = this[ENTRY];
147+
const modalParent = page._modalParent;
161148

162149
// Don't raise event if currentPage was showing modal page.
163150
if (!page._presentedViewController && newEntry && (!frame || frame.currentPage !== page)) {
@@ -167,6 +154,11 @@ class UIViewControllerImpl extends UIViewController {
167154

168155
page._enableLoadedEvents = true;
169156

157+
// Add page to frame if showing modal page.
158+
if (modalParent) {
159+
modalParent.frame._addView(page);
160+
}
161+
170162
if (frame) {
171163
if (!page.parent) {
172164
if (!frame._currentEntry) {
@@ -279,7 +271,7 @@ class UIViewControllerImpl extends UIViewController {
279271
public viewDidDisappear(animated: boolean): void {
280272
super.viewDidDisappear(animated);
281273

282-
let page = this._owner.get();
274+
const page = this._owner.get();
283275
if (traceEnabled()) {
284276
traceWrite(page + " viewDidDisappear", traceCategories.Navigation);
285277
}
@@ -288,12 +280,13 @@ class UIViewControllerImpl extends UIViewController {
288280
return;
289281
}
290282

291-
let modalParent = page._modalParent;
283+
const modalParent = page._modalParent;
292284
page._modalParent = undefined;
293285
page._UIModalPresentationFormSheet = false;
294286

295-
// Clear modal flag on parent page.
287+
// Clear up after modal page has closed.
296288
if (modalParent) {
289+
modalParent.frame._removeView(page);
297290
modalParent._modal = undefined;
298291
}
299292

@@ -430,7 +423,7 @@ export class Page extends PageBase {
430423

431424
super._raiseShowingModallyEvent();
432425

433-
parent.ios.presentViewControllerAnimatedCompletion(this._ios, ios.MajorVersion >= 7, null);
426+
parent.ios.presentViewControllerAnimatedCompletion(this._ios, true, null);
434427
let transitionCoordinator = getter(parent.ios, parent.ios.transitionCoordinator);
435428
if (transitionCoordinator) {
436429
UIViewControllerTransitionCoordinator.prototype.animateAlongsideTransitionCompletion.call(transitionCoordinator, null, () => this._raiseShownModallyEvent());
@@ -445,7 +438,7 @@ export class Page extends PageBase {
445438

446439
protected _hideNativeModalView(parent: Page) {
447440
parent.requestLayout();
448-
parent._ios.dismissModalViewControllerAnimated(ios.MajorVersion >= 7);
441+
parent._ios.dismissModalViewControllerAnimated(true);
449442

450443
super._hideNativeModalView(parent);
451444
}
@@ -520,7 +513,7 @@ export class Page extends PageBase {
520513
statusBarHeight = 0;
521514
}
522515

523-
if (this.frame && this.frame._getNavBarVisible(this)) {
516+
if (!this._modalParent && this.frame && this.frame._getNavBarVisible(this)) {
524517
// Measure ActionBar with the full height.
525518
let actionBarSize = View.measureChild(this, this.actionBar, widthMeasureSpec, heightMeasureSpec);
526519
actionBarWidth = actionBarSize.measuredWidth;

0 commit comments

Comments
 (0)
0