Hi guys
I want to intercept application.resumeEvent
and start a timer just when the user is on a specific screen. How can I do that?
Thanks
Hi guys
I want to intercept application.resumeEvent
and start a timer just when the user is on a specific screen. How can I do that?
Thanks
In your entry point, app.ts/app.js file is where you’ll set this up most likely (I would anyway).
You’ll need the application
and ui/frame
module. So import those and then we can code
We’ll use the onResume
event http://docs.nativescript.org/api-reference/modules/application.html#onresume
and the frame module’s currentPage prop http://docs.nativescript.org/api-reference/classes/ui_frame.frame.html#currentpage
import * as app from "application";
import { Frame } from "ui/frame";
app.onResume = (() => {
let currentPage = Frame.currentPage;
if (currentPage === somePageYouWant) {
/// setup your timer
}
})
I had to do something little different but I could get in what page the user is.
My .html / .xml file:
<ActionBar title="">
<NavigationButton android.systemIcon="ic_menu_back" android.iconVisibility="always" (tap)="backToPreviousScreen()"></NavigationButton>
<Image src="res://topbar_logo" stretch="none"></Image>
</ActionBar>
<GridLayout id="etaPage">
....
</GridLayout>
My .ts file
// other imports here
import * as application from "application";
import * as frame from "ui/frame";
export class ETAComponent {
// class code here
}
// after class code:
application.on(application.resumeEvent, function (args) {
if ( frame.topmost().currentPage != null ) {
var viewId = frame.topmost().currentPage.getViewById( "etaPage" );
if ( viewId != null && viewId.id === "etaPage" ) {
console.log( "You are at ETA Page" );
} else {
console.log( "You are at any other place but ETA Page" );
}
}
});
It solved my problem