mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fixed #779: frame.topmost().currentPage is not the same instance as the page being loaded in page.loaded event handler.
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
import observable = require("data/observable");
|
||||
import pages = require("ui/page");
|
||||
import labelModule = require("ui/label");
|
||||
import frame = require("ui/frame");
|
||||
|
||||
var page: pages.Page;
|
||||
var label: labelModule.Label;
|
||||
|
||||
export function pageLoaded(args: observable.EventData) {
|
||||
export function onLoaded(args: observable.EventData) {
|
||||
console.log("main-page.onLoaded");
|
||||
if (args.object !== frame.topmost().currentPage) {
|
||||
throw new Error("args.object must equal frame.topmost().currentPage on page.loaded");
|
||||
}
|
||||
page = <pages.Page>args.object;
|
||||
label = page.getViewById<labelModule.Label>("label");
|
||||
label = frame.topmost().getViewById<labelModule.Label>("label");
|
||||
if (!label) {
|
||||
throw new Error("Could not find `label`");
|
||||
}
|
||||
}
|
||||
|
||||
export function onNavigatedTo(args: observable.EventData) {
|
||||
console.log("main-page.onNavigatedTo");
|
||||
}
|
||||
|
||||
export function onTap(args: observable.EventData) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded" id="_mainPage" backgroundColor="Red">
|
||||
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="onLoaded" navigatedTo="onNavigatedTo" id="_mainPage" backgroundColor="Red">
|
||||
<StackLayout backgroundColor="PaleGreen">
|
||||
<Button text="Login (small)" tap="onTap" />
|
||||
<Button text="Login (full-screen)" tap="onTap" />
|
||||
|
||||
Reference in New Issue
Block a user