Cordova ionic-webview 4.1.1
global.scss:
ion-app {
background-color: transparent !important;
--background: none;
background: url(/assets/img/file_name.jpg) no-repeat 0 0;
background-size: 128% 105%;
align-items: flex-start;
background-position: -46px 0;
ion-router-outlet, ion-modal {
ion-content {
background-color: transparent !important;
--background: none;
}
}
}
app.component.ts:
window.addEventListener('native.keyboardshow', (e) => {
const ionAppEl = <HTMLElement>(document.getElementsByTagName('ion-split-pane')[0]);
if ( ionAppEl ) {
ionAppEl.setAttribute('keyboard', 'true');
const active: any = document.activeElement;
if ( active ) {
if ( (this.platform.is('android') || this.platform.is('ios')) && e['keyboardHeight'] ) {
ionAppEl.setAttribute('style', 'height: calc(100% - ' + e['keyboardHeight'] + 'px);');
}
if ( active.scrollIntoViewIfNeeded ) {
active.scrollIntoViewIfNeeded(true); // ensure input focus
}
}
}
});
window.addEventListener('keyboardWillHide', (e) => {
const ionAppEl = <HTMLElement>(document.getElementsByTagName('ion-split-pane')[0]);
if ( ionAppEl && (this.platform.is('android') || this.platform.is('ios')) ) {
ionAppEl.setAttribute('style', 'height: 100%;');
}
});
config.xml:
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity">
<activity android:windowSoftInputMode="adjustPan" />
</edit-config>
With cordova ionic-webview 2.2.0, I was using background-size: cover; and the background would resize when I tap on an input field. I wasn't using ionic framework but some of it's plugin for example
cordova-plugin-ionic-webview^2.2.0
cordova-plugin-ionic-keyboard^2.1.3
corodva-plugin-keyboard (this was required to move to the position of the input field)
Here's my solution:
CSS:
.content-background {
background-size: 180% auto;
background-image: url("img_path.jpg");
}
JS:
document.addEventListener('deviceready', function () {
var widthHeightRatio = parseFloat((window.screen.width * window.devicePixelRatio) / (window.screen.height * window.devicePixelRatio)).toFixed(2);
if(widthHeightRatio > 0.56){
$('.content-background').css('background-size', '160% auto');
}else if(widthHeightRatio < 0.56){
$('.content-background').css('background-size', '210% auto');
}
});
Android:
Alcatel 1x
480x960 1.5 0.5 210%
(width x height | devicePixelRatio | widthHeightRatio | width)
Pixel C Tablet
1800x2560 2 0.70 150%
Nexus 7 Tablet
1200x1920 2 0.63 150%
7” Tablet
600x1024 1 0.59 160%
iOS:
iPhone SE/5S
640x1136 2 0.56 180%
iPad 2 Pro (3rd gen)
2048x2732 2 0.749 140%
iPhoneX
1125x2436 3 0.46 210%
iPhone 5S
640x1136 2 0.56 180%
iPhone 6 Plus
1242x2208 3 0.56 180%
iPhone 7
750x1334 2 0.56 180%
iPhone 8 Plus
1242x2208 3 0.56 180%
iPhone XR
828x1792 2 0.46 210%
iPad Air (3rd gen)
1668x2224 2 0.75 140%
iPad Pro (9.7inch)
1536x2048 2 0.75 140%
iPad Pro (11inch)
1668x2388 2 0.70 150%