I use Crosswalk plugin for Android with Ionic 2 and I've noticed, when running on a real device, that this gives an inconsistent result:
this.platform.ready().then(() => {
console.log("this.platform.height(): " + this.platform.height() + " / this.platform.width(): " + this.platform.width());
});
Sometimes I get height and width both > 0: in this case it works.
Sometimes I get height and width == 0: in this case it does not work.
My assumption is that there might be another event in Crosswalk to notify that it is ready to display the right height and width.
I had a look around this Crosswalk web api page but I did not find what I was looking for.
https://ionicframework.com/docs/v2/api/platform/Platform/
width()
Gets the width of the platform’s viewport using window.innerWidth. Using this method is preferred since the dimension is a cached value, which reduces the chance of multiple and expensive DOM reads.
height()
Gets the height of the platform’s viewport using window.innerHeight. Using this method is preferred since the dimension is a cached value, which reduces the chance of multiple and expensive DOM reads.
// Add readySource to check if platform ready was used. The resolved value is the readySource, which states which platform ready was used. // For example, when Cordova is ready, the resolved ready source is cordova. The default ready source value will be dom. import { Component } from '@angular/core'; import { Platform } from 'ionic-angular'; @Component({...}) export MyApp { constructor(platform: Platform) { platform.ready().then((readySource) => { console.log('Platform ready from', readySource); console.log('Width: ' + platform.width()); console.log('Height: ' + platform.height()); }); }
Relevant topic: https://forum.ionicframework.com/t/how-to-get-device-width-and-height/28372
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.