After exploring various discussions and resources:
From these sources, I gathered some key points which I'll summarize below.
Template Structure
Firstly, ensure that your page layout follows a structure similar to the one below:
ScrollView
> StackLayout
> GridLayout
> SomeElement
> GridLayout
> TextField
Adjusting Android Soft Input Mode
This setting pertains to the on-screen keyboard that appears when a text field gains focus in the UI. To prevent the keyboard from covering your textfield, set the windowSoftInputMode
property in your AndroidManifest.xml
file. You can use either adjustResize
or adjustPan
. The difference between them is not clear, so you may need to experiment to see what works best for your scenario. More information on these flags can be found here.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="10000"
android:versionName="1.0">
...
<application
...
android:windowSoftInputMode="stateHidden | adjustPan">
Additional Update
It appears that something within NativeScript might be resetting the android:windowSoftInputMode
flag when the application is suspended and resumed. To address this, adjustments need to be made in the controller of the view to monitor these lifecycle events and re-enable the flags as needed.
some-view.component.ts (TypeScript)
import { Component, OnInit } from '@angular/core';
import * as app from "application";
import {
resumeEvent,
suspendEvent,
ApplicationEventData,
on as applicationOn,
run as applicationRun } from "tns-core-modules/application";
declare var android: any; // <- important! avoids namespace issues
@Component({
moduleId: module.id,
selector: 'some-view',
templateUrl: './some-view.component.html',
styleUrls: ['./some-view.component.css']
})
export class SomeViewComponent implements OnInit {
constructor() {
applicationOn(suspendEvent, (args: ApplicationEventData) => {
if (args.android) {
console.log("SUSPEND Activity: " + args.android);
}
});
applicationOn(resumeEvent, (args: ApplicationEventData) => {
if (args.android) {
console.log("RESUME Activity: " + args.android);
let window = app.android.startActivity.getWindow();
window.setSoftInputMode(
android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
);
// This can be SOFT_INPUT_ADJUST_PAN
// Or SOFT_INPUT_ADJUST_RESIZE
}
});
}
}