TextField without keyboard


#1

It might seem an odd thing to ask, but I could really do with a text field that didn’t have a keyboard.
It’s to mimic the (iPhone) phone app where the destination appears. I don’t need the user to have a keyboard (not even the “phone” keyboard) as i’m providing a keypad myself.
However, it would be useful to offer cut & paste.


#2

On iOS you can set the inputView attribute of nativeView (UITextField) to a dummy UIView.
Docs: https://developer.apple.com/documentation/uikit/uiresponder/1621092-inputview

On Android you can call setInputType on nativeView (EditText) with TYPE_NULL
Docs: https://developer.android.com/reference/android/text/InputType#type_null


#3

Thanks! Actually, I have dealt with it by calling .dismissSoftInput();

I was worried that this might only work on Android, but it seems OK on iPhone.


#4

That may be a hot fix, for best UX you must try to not show the keyboard itself. Dismiss will show keyboard a while, may be noticeable some time.


#5

I can’t see it, but take your point. How do I write code that works differently for Android ios?

eg

if (platform==ios) {

} else {

}


#6

import { isAndroid } from “platform”;
if (isAndroid) {
…// Android code
} else {
…//ios code
}

E.g. I am changing the icon source based on platform as for ios I am keeping all three set in separate folder
getIconSource(icon: string): string {
return isAndroid ? “res://”+ icon : “res://ic_edit.imageset/” + icon;
}


#7

…and now I have encountered an issue with my way, which is that if you hold down on the textField for a while, the keyboard does pop up (not a killer, as another tap makes it go away) and (more to the point) it’s hard to do a paste into the field. Intercepting the tap seems to interfere with the paste functionality. It can be done, but it’s a bit of a fight. Hopefully this platform-specific method willl work better.


#8

Here is how you shall do with platform specific solutions. I tested it with Android 7.x, but didn’t get chance to test in iOS, let me know in case if you ran into any issues.


#9

Thanks, but I do get a keyboard in the playground preview thing. Might try copying the code to my project to try that way…


#10

May I know which version you tested it against?


#11

iOS 11.3.1 playground 1.5.0 preview 1.12


#12

As I said already I didn’t test it on iOS earlier. I just made a second version tested on both iOS and Android.


#13

Excellent!

You win the prize :wink:

Now to try that in Javascript…


#14

Ignore this!!! Deleted to avoid even more embarrassment…