FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(view): isLoaded stability improvements by NathanWalker · Pull Request #6187 · NativeScript/NativeScript · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions tns-core-modules/ui/core/view-base/view-base.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,13 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
}

public loadView(view: ViewBase): void {
if (!view.isLoaded) {
if (view && !view.isLoaded) {
view.callLoaded();
}
}

public unloadView(view: ViewBase): void {
if (view.isLoaded) {
if (view && view.isLoaded) {
view.callUnloaded();
}
}
Expand Down
4 changes: 2 additions & 2 deletions tns-core-modules/ui/core/view/view.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function initializeDialogFragment() {
}

const owner = this.owner;
if (!owner.isLoaded) {
if (owner && !owner.isLoaded) {
owner.callLoaded();
}

Expand All @@ -194,7 +194,7 @@ function initializeDialogFragment() {
}

const owner = this.owner;
if (owner.isLoaded) {
if (owner && owner.isLoaded) {
owner.callUnloaded();
}
}
Expand Down
62 changes: 36 additions & 26 deletions tns-core-modules/ui/frame/frame.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Page } from "../page";
import * as application from "../../application";
import {
FrameBase, stack, goBack, View, Observable,
traceEnabled, traceWrite, traceCategories
traceEnabled, traceWrite, traceCategories, traceError
} from "./frame-common";

import {
Expand Down Expand Up @@ -700,35 +700,45 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
}

const entry = this.entry;
const page = entry.resolvedPage;
const frame = this.frame;
if (page.parent === frame) {
// If we are navigating to a page that was destroyed
// reinitialize its UI.
if (!page._context) {
const context = container && container.getContext() || inflater && inflater.getContext();
page._setupUI(context);
if (entry) {
const page = entry.resolvedPage;
if (page) {
const frame = this.frame;
if (page.parent === frame) {
// If we are navigating to a page that was destroyed
// reinitialize its UI.
if (!page._context) {
const context = container && container.getContext() || inflater && inflater.getContext();
page._setupUI(context);
}
} else {
if (!frame._styleScope) {
// Make sure page will have styleScope even if parents don't.
page._updateStyleScope();
}

frame._addView(page);
}
} else {
if (!this.frame._styleScope) {
// Make sure page will have styleScope even if parents don't.
page._updateStyleScope();

if ((frame && frame.isLoaded) && (page && !page.isLoaded)) {
page.callLoaded();
}

this.frame._addView(page);
}

if (frame.isLoaded && !page.isLoaded) {
page.callLoaded();

const savedState = entry.viewSavedState;
if (savedState) {
(<android.view.View>page.nativeViewProtected).restoreHierarchyState(savedState);
entry.viewSavedState = null;
}

return page.nativeViewProtected;
}
if (traceEnabled()) {
traceError(`${fragment}.onCreateView page: ${page}`);
}
}

const savedState = entry.viewSavedState;
if (savedState) {
(<android.view.View>page.nativeViewProtected).restoreHierarchyState(savedState);
entry.viewSavedState = null;
if (traceEnabled()) {
traceError(`${fragment}.onCreateView entry: ${entry}`);
}

return page.nativeViewProtected;
}

@profile
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/styling/style-scope.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export class CssState {
* As a result, at some point in time, the selectors matched have to be requerried from the style scope and applied to the view.
*/
public onChange(): void {
if (this.view.isLoaded) {
if (this.view && this.view.isLoaded) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What are the cases when you get error here?
The view is passed in the constructor and never changed.
Maybe we should add a check there?

This comment was marked as abuse.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That’s exactly right @NathanaelA

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm still struggling to get this one. The view is private and is never set (except from the constructor).
If there is a problem with trying to apply styles on disposed view - this check will do nothing more. The view will be disposed, but its CssState will still hold the reference and so this.view will not be null.

this.unsubscribeFromDynamicUpdates();
this.updateMatch();
this.subscribeForDynamicUpdates();
Expand Down

Back | FazBrowse Home | New Git URL