5

Different behavior with focus() between Android and iOS

 1 year ago
source link: https://answers.sap.com/questions/13915278/different-behavior-with-focus-between-android-and.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
11 minutes ago

Different behavior with focus() between Android and iOS

8 Views

Hello together,

I have a page with a sap.m.Input field. For this field I want to set the focus out of the controller.

I have tried several approaches. But it works only with the help of setTimeout I gues. Getting the control via this.getView().byId('control') to set the focus does not work reliably.

On a desktop PC and on Android mobile devices this setTimeout approach works. On an iOS device unfortunately not. Sometimes only a small highlighted frame is visible, but not every time on iOS.

Background would be a barcode scanning app. Here is the code that currently works.

onAfterRendering: function () {
const oScanField = this.byId("scanField");
setTimeout(() => {
oScanField.focus();
}, 250);
}

Are there certain requirements for the focus or does a certain sequence have to be followed for a simple focus() to work out of the controller?

Would it also be possible to set the focus() and hide the soft keyboard initially? Only when the user actively clicks into the input field the keyboard should be shown. So when the focus is set from the controller, then the softkeyboard should be hidden and when the user manually clicks into the field, then the keyboard should be displayed.

Here I have found a work-a-round. Is there a better approach for this?

onTestPress: function () {<br>  const oScanField = this.byId("scanField");<br>  // https://answers.sap.com/questions/12963714/sapui5-how-to-disable-soft-keyboard-on-android-whe.html<br>  // currently just a workaround for hiding the soft - keyboard on the scanner<br>  oScanField.setEditable(false);<br>  setTimeout(() => {<br>    oScanField.setEditable(true);<br>    oScanField.focus();<br>  }, 200);<br>}<br>

Current UI5 framework are: 1.108.16

Test on Desktop with Browser Edge and Chrome (latest version)

  1. focus() is working.
  2. No Keyboard test

Test on Android with Edge and Chrome (latest version)

  1. focus() is working
  2. Soft keyboard is hidden for the focus() out of the controller

Test on iOS with Safari and Chrome (also latest version)

  1. focus() not working. Sometimes a dotted frame is visible, but not very often.
  2. Soft Keyboard is not hidden.

Here the result on the desktop PC as picture:

desktop.jpg

Here the result on Android as picture:

android.jpg

Here the result on iOS as picture:

ios.jpg

Maybe I did something wrong or the implementation needs to be changed from my side. Maybe there is another and more stable approach for my implementation.

Thanks for support


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK