Skip to content

Commit 4a11cf9

Browse files
Alexander Vakrilovdtopuzov
authored andcommitted
fix: Page and Frame isLoaded undefined checks (#6255)
* fix(view): isLoaded handling closes #6179 * refactor: Error handling code in onCreateView
1 parent 13d4f34 commit 4a11cf9

4 files changed

Lines changed: 23 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,13 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
595595
}
596596

597597
public loadView(view: ViewBase): void {
598-
if (!view.isLoaded) {
598+
if (view && !view.isLoaded) {
599599
view.callLoaded();
600600
}
601601
}
602602

603603
public unloadView(view: ViewBase): void {
604-
if (view.isLoaded) {
604+
if (view && view.isLoaded) {
605605
view.callUnloaded();
606606
}
607607
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function initializeDialogFragment() {
185185
}
186186

187187
const owner = this.owner;
188-
if (!owner.isLoaded) {
188+
if (owner && !owner.isLoaded) {
189189
owner.callLoaded();
190190
}
191191

@@ -201,7 +201,7 @@ function initializeDialogFragment() {
201201
}
202202

203203
const owner = this.owner;
204-
if (owner.isLoaded) {
204+
if (owner && owner.isLoaded) {
205205
owner.callUnloaded();
206206
}
207207
}

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Page } from "../page";
99
import * as application from "../../application";
1010
import {
1111
FrameBase, stack, goBack, View, Observable,
12-
traceEnabled, traceWrite, traceCategories
12+
traceEnabled, traceWrite, traceCategories, traceError
1313
} from "./frame-common";
1414

1515
import {
@@ -720,8 +720,23 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
720720
}
721721

722722
const entry = this.entry;
723+
if (!entry) {
724+
traceError(`${fragment}.onCreateView: entry is null or undefined`);
725+
return null;
726+
}
727+
723728
const page = entry.resolvedPage;
729+
if (!page) {
730+
traceError(`${fragment}.onCreateView: entry has no resolvedPage`);
731+
return null;
732+
}
733+
724734
const frame = this.frame;
735+
if (!frame) {
736+
traceError(`${fragment}.onCreateView: this.frame is null or undefined`);
737+
return null;
738+
}
739+
725740
if (page.parent === frame) {
726741
// If we are navigating to a page that was destroyed
727742
// reinitialize its UI.
@@ -730,12 +745,12 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
730745
page._setupUI(context);
731746
}
732747
} else {
733-
if (!this.frame._styleScope) {
748+
if (!frame._styleScope) {
734749
// Make sure page will have styleScope even if parents don't.
735750
page._updateStyleScope();
736751
}
737752

738-
this.frame._addView(page);
753+
frame._addView(page);
739754
}
740755

741756
if (frame.isLoaded && !page.isLoaded) {

tns-core-modules/ui/styling/style-scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export class CssState {
328328
* As a result, at some point in time, the selectors matched have to be requerried from the style scope and applied to the view.
329329
*/
330330
public onChange(): void {
331-
if (this.view.isLoaded) {
331+
if (this.view && this.view.isLoaded) {
332332
this.unsubscribeFromDynamicUpdates();
333333
this.updateMatch();
334334
this.subscribeForDynamicUpdates();

0 commit comments

Comments
 (0)