mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Application orientation changed event
This commit is contained in:
14
apps/orientation-demo/app.ts
Normal file
14
apps/orientation-demo/app.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import application = require("application");
|
||||
|
||||
application.mainModule = "main-page";
|
||||
|
||||
application.on(application.exitEvent, () => {
|
||||
if (application.android) {
|
||||
application.android.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED);
|
||||
}
|
||||
else {
|
||||
application.ios.removeNotificationObserver(UIDeviceBatteryLevelDidChangeNotification);
|
||||
}
|
||||
});
|
||||
|
||||
application.start();
|
||||
5
apps/orientation-demo/main-page.port.xml
Normal file
5
apps/orientation-demo/main-page.port.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="onPageLoaded" unloaded="onPageUnloaded" navigatedTo="pageNavigatedTo">
|
||||
<GridLayout>
|
||||
<TextView text="{{ oreintation }}" />
|
||||
</GridLayout>
|
||||
</Page>
|
||||
21
apps/orientation-demo/main-page.ts
Normal file
21
apps/orientation-demo/main-page.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import application = require("application");
|
||||
import observable = require("data/observable");
|
||||
import pageModule = require("ui/page");
|
||||
|
||||
var vm = new observable.Observable();
|
||||
function orientationChanged(data) {
|
||||
console.log("Orientation changed: " + data.newValue);
|
||||
vm.set("oreintation", data.newValue);
|
||||
}
|
||||
export function onPageLoaded(args: observable.EventData) {
|
||||
var page = <pageModule.Page>args.object;
|
||||
application.on(application.orientationChangedEvent, orientationChanged, page);
|
||||
|
||||
page.bindingContext = vm;
|
||||
vm.set("oreintation", "not changed");
|
||||
}
|
||||
|
||||
export function onPageUnloaded(args: observable.EventData) {
|
||||
var page = <pageModule.Page>args.object;
|
||||
<any>application.off(application.orientationChangedEvent, orientationChanged, page);
|
||||
}
|
||||
2
apps/orientation-demo/package.json
Normal file
2
apps/orientation-demo/package.json
Normal file
@@ -0,0 +1,2 @@
|
||||
{ "name" : "page-reload-demo",
|
||||
"main" : "app.js" }
|
||||
Reference in New Issue
Block a user