mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
fix(cache): do not cache 0 value dimensions
This commit is contained in:
@ -245,12 +245,19 @@ export function getDimensions(ion) {
|
||||
let dimensions = dimensionCache[ion._dimId];
|
||||
if (!dimensions) {
|
||||
let ele = ion.getNativeElement();
|
||||
// make sure we got good values before caching
|
||||
if (ele.offsetWidth && ele.offsetHeight) {
|
||||
dimensions = dimensionCache[ion._dimId] = {
|
||||
width: ele.offsetWidth,
|
||||
height: ele.offsetHeight,
|
||||
left: ele.offsetLeft,
|
||||
top: ele.offsetTop
|
||||
};
|
||||
|
||||
} else {
|
||||
// do not cache bad values
|
||||
return { width: 0, height: 0, left: 0, top: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
return dimensions;
|
||||
@ -258,10 +265,16 @@ export function getDimensions(ion) {
|
||||
|
||||
export function windowDimensions() {
|
||||
if (!dimensionCache.win) {
|
||||
// make sure we got good values before caching
|
||||
if (window.innerWidth && window.innerHeight) {
|
||||
dimensionCache.win = {
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
};
|
||||
} else {
|
||||
// do not cache bad values
|
||||
return { width: 0, height: 0 };
|
||||
}
|
||||
}
|
||||
return dimensionCache.win;
|
||||
}
|
||||
|
Reference in New Issue
Block a user