question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide API to resize layout when keyboard opens

See original GitHub issue

Often 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:23 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mpostcommented, Feb 7, 2017

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.

1reaction
cookiegurucommented, Feb 6, 2017

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found