0

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.

nyluje
  • 3,573
  • 7
  • 37
  • 67

1 Answers1

0

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.
  1. Please try using window.innerHeight and window.innerWidth to get height and width of the device at first.
  2. Try

// 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());
    });
  }
  1. Remove Crosswalk in Ionic 2 to check if system webview can get correct results, then it should be Crosswalk issue rather than Ionic issue.

Relevant topic: https://forum.ionicframework.com/t/how-to-get-device-width-and-height/28372

  • It is likely crosswalk I agree since before installing it, I was getting consistently the height and width from `this.platform.height()/width()`. And did not even have to wait for `platform.ready` to have those attribute with their right values. Haven t tried `window.innerHeight()/innerWidth` yet since that is what `platform.width()/height()` is supposed to deliver according to documentation. – nyluje Nov 22 '16 at 08:53
  • Sorry I haven t read thoroughly all your comments at firts since some of them are embeded in code formatting part. I will try those and give you feedback. – nyluje Nov 22 '16 at 09:03