Orientation cleanup

This commit is contained in:
Max Lynch
2015-09-09 13:51:34 -05:00
parent 824d310ecc
commit 7ca620a470
6 changed files with 20 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import {BatteryPage} from 'pages/battery';
import {ContactsPage} from 'pages/contacts'; import {ContactsPage} from 'pages/contacts';
import {DevicePage} from 'pages/device'; import {DevicePage} from 'pages/device';
import {DeviceMotionPage} from 'pages/device-motion'; import {DeviceMotionPage} from 'pages/device-motion';
import {DeviceOrientationPage} from 'pages/device-orientation';
import {GeolocationPage} from 'pages/geolocation'; import {GeolocationPage} from 'pages/geolocation';
import {VibrationPage} from 'pages/vibration'; import {VibrationPage} from 'pages/vibration';
@ -26,6 +27,7 @@ class MyApp {
{title: 'Camera', page: CameraPage}, {title: 'Camera', page: CameraPage},
{title: 'Device', page: DevicePage}, {title: 'Device', page: DevicePage},
{title: 'Device Motion', page: DeviceMotionPage}, {title: 'Device Motion', page: DeviceMotionPage},
{title: 'Device Orientation', page: DeviceOrientationPage},
{title: 'Geolocation', page: GeolocationPage}, {title: 'Geolocation', page: GeolocationPage},
{title: 'Contacts', page: ContactsPage}, {title: 'Contacts', page: ContactsPage},
{title: 'Battery', page: BatteryPage}, {title: 'Battery', page: BatteryPage},

View File

@ -1,5 +1,8 @@
import {IonicView, DeviceOrientation} from 'ionic/ionic'; import {IonicView, DeviceOrientation} from 'ionic/ionic';
import {CSS} from 'ionic/util/dom';
import {NgStyle, forwardRef, Host, Component, View, ElementRef} from 'angular2/angular2';
@IonicView({ @IonicView({
template: ` template: `
@ -7,16 +10,22 @@ import {IonicView, DeviceOrientation} from 'ionic/ionic';
<button aside-toggle> <button aside-toggle>
<icon menu></icon> <icon menu></icon>
</button> </button>
<ion-title>Device Motion</ion-title> <ion-title>Device Orientation</ion-title>
</ion-navbar> </ion-navbar>
<ion-content class="padding"> <ion-content class="padding">
<div [ng-style]="imageStyle"><img src="http://ionic-io-assets.s3.amazonaws.com/ionitron-love.png" style="max-width: 100%"></div>
</ion-content> </ion-content>
` `
}) })
export class DeviceMotionPage { export class DeviceOrientationPage {
constructor() { constructor() {
this.imageStyle = {
}
}
onInit() {
let device = DeviceOrientation.watchHeading().source.subscribe((resp) => { let device = DeviceOrientation.watchHeading().source.subscribe((resp) => {
console.log('Device orientation', resp); this.orientation = resp;
this.imageStyle['-webkit-transform'] = 'rotate(' + (resp.alpha || 100) + 'deg)';
}, (err) => { }, (err) => {
console.log('Device err', err); console.log('Device err', err);
}); });

View File

@ -1,4 +1,4 @@
import {CORE_DIRECTIVES, FORM_DIRECTIVES, Component, Directive, View, forwardRef} from 'angular2/angular2' import {CORE_DIRECTIVES, FORM_DIRECTIVES, NgStyle, Component, Directive, View, forwardRef} from 'angular2/angular2'
import * as util from 'ionic/util'; import * as util from 'ionic/util';
import {IonicConfig} from './config'; import {IonicConfig} from './config';
@ -31,6 +31,8 @@ export const IonicDirectives = [
CORE_DIRECTIVES, CORE_DIRECTIVES,
FORM_DIRECTIVES, FORM_DIRECTIVES,
NgStyle
// Content // Content
forwardRef(() => Aside), forwardRef(() => Aside),
forwardRef(() => AsideToggle), forwardRef(() => AsideToggle),

View File

@ -64,7 +64,7 @@ export class DeviceMotion {
source: source, source: source,
watchID: watchID, watchID: watchID,
clear: () => { clear: () => {
window.removeEventListener('devicemotion', cbFn); window.removeEventListener('devicemotion', fnCb);
} }
} }
} else if(navigator.accelerometer) { } else if(navigator.accelerometer) {

View File

@ -56,7 +56,7 @@ export class DeviceOrientation {
source: source, source: source,
watchID: watchID, watchID: watchID,
clear: () => { clear: () => {
window.removeEventListener('deviceorientation', cbFn); window.removeEventListener('deviceorientation', fnCb);
} }
} }
} else if(navigator.accelerometer) { } else if(navigator.accelerometer) {

View File

@ -4,5 +4,6 @@ export * from './camera/camera'
export * from './contacts/contacts' export * from './contacts/contacts'
export * from './device/device' export * from './device/device'
export * from './device-motion/device-motion' export * from './device-motion/device-motion'
export * from './device-orientation/device-orientation'
export * from './geolocation/geolocation' export * from './geolocation/geolocation'
export * from './vibration/vibration' export * from './vibration/vibration'