Merge pull request #3797 from NoelDeMartin/MOBILE-4189

MOBILE-4189 core: Fix collapsible header zoom
main
Dani Palou 2023-09-28 12:54:18 +02:00 committed by GitHub
commit 229f99645d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View File

@ -378,8 +378,8 @@ export class CoreCollapsibleHeaderDirective implements OnInit, OnChanges, OnDest
textProperties.includes(property), textProperties.includes(property),
) )
.reduce((styles, property) => { .reduce((styles, property) => {
styles[0][property] = collapsedTitleStyles.getPropertyValue(property); styles[0][property] = CoreDom.getCSSPropertyValue(collapsedTitleStyles, property);
styles[1][property] = expandedTitleStyles.getPropertyValue(property); styles[1][property] = CoreDom.getCSSPropertyValue(expandedTitleStyles, property);
return styles; return styles;
}, [{}, {}]); }, [{}, {}]);

View File

@ -22,6 +22,8 @@ import { CoreEventObserver } from '@singletons/events';
*/ */
export class CoreDom { export class CoreDom {
static fontSizeZoom: number | null = null;
// Avoid creating singleton instances. // Avoid creating singleton instances.
private constructor() { private constructor() {
// Nothing to do. // Nothing to do.
@ -579,6 +581,38 @@ export class CoreDom {
} }
} }
/**
* Get CSS property value from computed styles.
*
* @param styles Computed styles.
* @param property Property name.
* @returns Property CSS value (may not be the same as the computed value).
*/
static getCSSPropertyValue(styles: CSSStyleDeclaration, property: string): string {
const value = styles.getPropertyValue(property);
if (property === 'font-size') {
if (this.fontSizeZoom === null) {
const baseFontSize = 20;
const span = document.createElement('span');
span.style.opacity = '0';
span.style.fontSize = `${baseFontSize}px`;
document.body.append(span);
this.fontSizeZoom = baseFontSize / Number(getComputedStyle(span).fontSize.slice(0, -2));
span.remove();
}
if (this.fontSizeZoom !== 1) {
return `calc(${this.fontSizeZoom} * ${value})`;
}
}
return value;
}
} }
/** /**