Provide API to resize layout when keyboard opens
See original GitHub issueOften it is useful to resize the UI to fit the visible area when the keyboard opens. This makes it possible to e.g. always show a button below the selected text input when it gets focus (see example below).
This was the behavior of the Android client on Tabris.js 1.x. On 2.x, the layout is only modified when the developer drawer is opened.
On iOS, the UI is not resized when the keyboard opens. Input fields may be covered by the keyboard when it opens (reproducible in the example below).
It would be useful to unify the default behavior on both platforms and provide API to enable/disable it.
Example:
tabris.ui.contentView.append(
new tabris.ScrollView({left: 0, top: 0, right: 0, bottom: 0}).append(
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.TextInput({left: 0, top: 'prev() 10', right: 0}),
new tabris.Button({left: 0, top: 'prev() 10', right: 0})
)
);
tabris.ui.contentView.find('ScrollView').first().on('resize', function(scrollView) {
let childrenHeight = 0;
let children = tabris.ui.contentView.find('ScrollView').first().children();
children.forEach(child => childrenHeight += child.bounds.height + 10);
if (childrenHeight - scrollView.bounds.height > 0) {
scrollView.scrollToY(childrenHeight - scrollView.bounds.height);
}
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:23 (10 by maintainers)
Top Results From Across the Web
Resize the layout when the keyboard opens - Stack Overflow
From the documentation. "adjustResize" The activity's main window is always resized to make room for the soft keyboard on screen.
Read more >Android how to adjust for soft keyboard | by Yat Man, Wong
1. Get the rootView · 2. Set a listener for the root view when the height change · 3. Calculate the height change...
Read more >Working with the Soft Keyboard | CodePath Android Cliffnotes
The soft keyboard can be configured for each activity within the AndroidManifest.xml file using the android:windowSoftInputMode attribute to adjust both default ...
Read more >Keyboard Handling on Android - PSPDFKit
Android has built in support for resizing your application layout when the soft keyboard is being shown that prevents the app's contents from...
Read more >Prevent content from being hidden underneath the Virtual ...
On Chrome on Android, the Layout Viewport will shrink when the keyboard gets shown, matching the height of the Visual Viewport. ~. A...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To embed your content in a
ScrollView
is mostly the right choice anyways since you are can not rely on a certain screen size. The usee could also activate split screen mode where your apps window would be really small.@natanraj That’s basically the story of my life on Android–content not moving in to the viewport at all or doing so in a bizzairre way.
I’d say that the way you have it set up is the intended behavior. If you set up a page and append several tall elements to it, the last few items will get cut off on lower-resolution devices (regardless of keyboard visibility). The only way around this is to place a
ScrollView
on the page and append all items to that.