Ionic 2 Crosswalk для Android: противоречивый результат this.platform.height()/width() для события this.platform.ready()

Я использую плагин Crosswalk для Android с Ionic 2 и заметил, что при работе на реальном устройстве это дает противоречивый результат:

this.platform.ready().then(() => {
        console.log("this.platform.height(): " + this.platform.height() + " / this.platform.width(): " + this.platform.width());
});

Иногда я получаю высоту и ширину как> 0: в этом случае это работает.

Иногда я получаю высоту и ширину == 0: в этом случае это не работает.

Я предполагаю, что может быть другое событие в Crosswalk, чтобы уведомить, что оно готово отображать правильную высоту и ширину.

Я просмотрел эту страницу веб-интерфейса Crosswalk, но не нашел того, что искал.

1 ответ

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. Пожалуйста, попробуйте сначала использовать window.innerHeight и window.innerWidth, чтобы получить высоту и ширину устройства.
  2. Пытаться

// 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. Удалите Crosswalk в Ionic 2, чтобы проверить, может ли системный веб-просмотр получить правильные результаты, тогда это должна быть проблема Crosswalk, а не Ionic.

Соответствующая тема: https://forum.ionicframework.com/t/how-to-get-device-width-and-height/28372

Другие вопросы по тегам