Skip to content

Commit 3a6db6e

Browse files
authored
Merge pull request #4528 from albertgasset/MOBILE-4840
MOBILE-4840 cordova: Fix edge-to-edge with CSS zoom
2 parents 8549063 + 94de821 commit 3a6db6e

File tree

6 files changed

+33
-23
lines changed

6 files changed

+33
-23
lines changed

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<preference name="ScrollEnabled" value="true" />
3434
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
3535
<preference name="HideKeyboardFormAccessoryBar" value="false" />
36-
<preference name="KeyboardResizeMode" value="ionic" />
36+
<preference name="KeyboardResizeMode" value="none" />
3737
<preference name="AllowInlineMediaPlayback" value="true" />
3838
<preference name="LoadUrlTimeoutValue" value="60000" />
3939
<preference name="load-url-timeout" value="60000" />

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"@moodlehq/cordova-plugin-file-transfer": "2.0.0-moodle.2",
8080
"@moodlehq/cordova-plugin-inappbrowser": "6.0.0-moodle.1",
8181
"@moodlehq/cordova-plugin-intent": "2.2.0-moodle.3",
82-
"@moodlehq/cordova-plugin-ionic-keyboard": "^2.2.0-moodle.1",
82+
"@moodlehq/cordova-plugin-ionic-keyboard": "^2.2.0-moodle.2",
8383
"@moodlehq/cordova-plugin-ionic-webview": "5.0.0-moodle.5",
8484
"@moodlehq/cordova-plugin-media-capture": "5.0.0-moodle.1",
8585
"@moodlehq/cordova-plugin-qrscanner": "3.0.1-moodle.5",
@@ -234,4 +234,4 @@
234234
"nl.kingsquare.cordova.background-audio": {}
235235
}
236236
}
237-
}
237+
}

src/core/features/settings/services/settings-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export class CoreSettingsHelperProvider {
385385
applyZoomLevel(zoomLevel: CoreZoomLevel): void {
386386
const zoom = CoreConstants.CONFIG.zoomlevels[zoomLevel];
387387

388-
document.documentElement.style.setProperty('--zoom-level', `${zoom}%`);
388+
document.documentElement.style.setProperty('--zoom-ratio', `${zoom / 100}`);
389389
}
390390

391391
/**

src/core/initializers/initialize-edge-to-edge.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default async function(): Promise<void> {
3737
});
3838

3939
// Listener for keyboard height changes.
40-
// We need to update the CSS variables and the ion-app height at the same time.
40+
// We need to update safe area and keyboard height CSS variables at the same time.
4141
const imeInsetListener = await Inset.create({
4242
mask: InsetMask.IME,
4343
includeRoundedCorners: false,
@@ -54,14 +54,9 @@ export default async function(): Promise<void> {
5454
rootStyle.setProperty('--ion-safe-area-top', `${insets.top}px`);
5555
rootStyle.setProperty('--ion-safe-area-bottom', `${keyboardHeight > 0 ? 0 : insets.bottom}px`);
5656

57-
// Update ion-app height.
58-
// This is the behaviour of the Cordova keyboard plugin on iOS.
59-
const appStyle = document.querySelector('ion-app')?.style;
60-
appStyle?.setProperty('height', keyboardHeight > 0 ? `${window.innerHeight - keyboardHeight}px` : null);
61-
6257
// Update the CSS variable with the kebyoard height.
6358
// On iOS, the variable is updated in the forked Cordova keyboard plugin.
64-
rootStyle.setProperty('--keyboard-height', keyboardHeight > 0 ? `${keyboardHeight}px` : null);
59+
rootStyle.setProperty('--keyboard-height', `${keyboardHeight}px`);
6560
};
6661

6762
systemInsetListener.addListener(update);

src/theme/theme.base.scss

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@
88
}
99

1010
:root {
11-
--zoom-level: 100%;
12-
zoom: var(--zoom-level);
11+
--zoom-ratio: 1;
12+
--zoom-level: calc(100% * var(--zoom-ratio)); // @deprecated since 5.1.
13+
zoom: calc(100% * var(--zoom-ratio));
1314

1415
&.ios {
15-
font-size: var(--zoom-level);
16+
font-size: calc(100% * var(--zoom-ratio));
1617
}
1718

18-
// Store safe area variables as --root-safe-area-*.
19+
// Apply zoom ratio to safe area and keyboard height CSS variable.
20+
// Also, store safe area variables as --root-safe-area-*.
1921
// Contrary to the --ion-safe-area-* variables, these are never overridden.
20-
--root-safe-area-left: var(--ion-safe-area-left);
21-
--root-safe-area-right: var(--ion-safe-area-right);
22-
--root-safe-area-top: var(--ion-safe-area-top);
23-
--root-safe-area-bottom: var(--ion-safe-area-bottom);
22+
--root-safe-area-left: calc(var(--ion-safe-area-left, 0px) / var(--zoom-ratio));
23+
--root-safe-area-right: calc(var(--ion-safe-area-right, 0px) / var(--zoom-ratio));
24+
--root-safe-area-top: calc(var(--ion-safe-area-top, 0px) / var(--zoom-ratio));
25+
--root-safe-area-bottom: calc(var(--ion-safe-area-bottom, 0px) / var(--zoom-ratio));
26+
--root-keyboard-height: calc(var(--keyboard-height, 0px) / var(--zoom-ratio));
27+
& > body {
28+
--ion-safe-area-left: var(--root-safe-area-left);
29+
--ion-safe-area-right: var(--root-safe-area-right);
30+
--ion-safe-area-top: var(--root-safe-area-top);
31+
--ion-safe-area-bottom: var(--root-safe-area-bottom);
32+
--keyboard-height: var(--root-keyboard-height);
33+
}
2434
}
2535

2636
a {
@@ -187,6 +197,11 @@ core-split-view.menu-and-content {
187197
}
188198
}
189199

200+
// Set ion-app height based on the keyboard height.
201+
ion-app {
202+
height: calc(100% - var(--keyboard-height, 0px));
203+
}
204+
190205
// Hidden submit button.
191206
.core-submit-hidden-enter {
192207
position: absolute;

0 commit comments

Comments
 (0)