简体   繁体   English

适用于Android的Ionic 2 Crosswalk:this.platform.ready()事件上的this.platform.height()/ width()结果不一致

[英]Ionic 2 Crosswalk for Android: this.platform.height()/width() inconsistent result on this.platform.ready() event

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: 我在Ionic 2上使用了适用于Android的Crosswalk插件,并且注意到在实际设备上运行时,这会产生不一致的结果:

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. 有时我的高度和宽度都> 0:在这种情况下,它可以工作。

Sometimes I get height and width == 0: in this case it does not work. 有时我得到的高度和宽度== 0:在这种情况下,它不起作用。

My assumption is that there might be another event in Crosswalk to notify that it is ready to display the right height and width. 我的假设是,Crosswalk中可能会发生另一个事件,通知它已准备好显示正确的高度和宽度。

I had a look around this Crosswalk web api page but I did not find what I was looking for. 我环顾了这个Crosswalk网络api页面,但没有找到想要的东西。

https://ionicframework.com/docs/v2/api/platform/Platform/ 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. 请首先尝试使用window.innerHeight和window.innerWidth来获取设备的高度和宽度。
  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. 在Ionic 2中删除Crosswalk,以检查系统Webview是否可以获得正确的结果,那么应该是Crosswalk问题而不是Ionic问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM