Skip to content

Instantly share code, notes, and snippets.

@ulfie22
Last active January 6, 2020 09:22
Show Gist options
  • Save ulfie22/551c418c0a988c163b126c3ce831dbb1 to your computer and use it in GitHub Desktop.
Save ulfie22/551c418c0a988c163b126c3ce831dbb1 to your computer and use it in GitHub Desktop.
NativeScript Vue Lifecycle Package
const application = require("tns-core-modules/application");
export default function (Vue) {
Vue.cycle = {
init(vm) {
console.log('!@# starting init in lifecycle');
application.on(application.launchEvent, (args) => {
if (args.android) {
// For Android applications, args.android is an android.content.Intent class.
console.log("Launched Android application with the following intent: " + args.android + ".");
} else if (args.ios !== undefined) {
// For iOS applications, args.ios is NSDictionary (launchOptions).
console.log("Launched iOS application with options: " + args.ios);
}
});
application.on(application.suspendEvent, (args) => {
if (args.android) {
// For Android applications, args.android is an android activity class.
console.log("!@# suspendEvent Activity: " + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log("!@# suspendEvent UIApplication: " + args.ios);
}
});
application.on(application.resumeEvent, (args) => {
if (args.android) {
// For Android applications, args.android is an android activity class.
console.log("!@# resumeEvent Activity: " + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log("!@# resumeEvent UIApplication: " + args.ios);
}
console.log('!@# resuming for both platforms');
});
application.on(application.displayedEvent, (args) => {
// args is of type ApplicationEventData
console.log("displayedEvent");
});
application.on(application.orientationChangedEvent, (args) => {
// args is of type OrientationChangedEventData
console.log(args.newValue); // "portrait", "landscape", "unknown"
});
application.on(application.exitEvent, (args) => {
if (args.android) {
// For Android applications, args.android is an android activity class.
console.log("!@# exitEvent Activity: " + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log("!@# exitEvent UIApplication: " + args.ios);
}
});
application.on(application.lowMemoryEvent, (args) => {
if (args.android) {
// For Android applications, args.android is an android activity class.
console.log("!@# lowMemoryEvent Activity: " + args.android);
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log("!@# lowMemoryEvent UIApplication: " + args.ios);
}
});
application.on(application.uncaughtErrorEvent, (args) => {
console.log("!@# uncaughtErrorEvent Error: " + args.error);
});
},
}
Object.defineProperties(Vue.prototype, {
$cycle: {
get() {
return Vue.cycle;
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment