how to detect touch coordinates on webView? or how to lift the webView hidden under the keyboard

Hi,

I’m trying to display a website with some textfield inputs in it. But when I touch the textfield which is on the bottom of the screen - a keyboard covers it completely and it’s not visible.

  1. Is there a way to check, that the user has touched a textfield?

Is it possible via pseudo-URLs in the html code and check for it via urlRequest listener? Or there’s an easier way?

  1. How to check what is the Y coordinate of the touch event (touched textfield height on the screen) so that I could lift up the web view to a particular height offset and make the textfield visible?

I tried to add a touch event listener to a webView, with no success. Tried also to add a display object with touch listener, but since the native.newWebView is always on top - it doesn’t pass the clicks to the bottom layer.

Please help :slight_smile:

You can listen to urlRequest on webview. With JavaScript you can change value of hash for currently displayed page. That’s the best way I could find to make interactions between webview and app layer.

So for example you can set hash value to #input=input_value and make pattern find on event.url, that way you will have your coordinates in app part. Using hash is very convenient, because the page won’t reload, but still event will fire and you will have information passed by url.

Thanks for this solution! I was looking for a similar effect. That’s quite a canny approach. 

Ideally, it would be nice if Corona would support a touch listener above the webView which could intercept the touches, or a touch listener on the webView itself. 

You can listen to urlRequest on webview. With JavaScript you can change value of hash for currently displayed page. That’s the best way I could find to make interactions between webview and app layer.

So for example you can set hash value to #input=input_value and make pattern find on event.url, that way you will have your coordinates in app part. Using hash is very convenient, because the page won’t reload, but still event will fire and you will have information passed by url.

Thanks for this solution! I was looking for a similar effect. That’s quite a canny approach. 

Ideally, it would be nice if Corona would support a touch listener above the webView which could intercept the touches, or a touch listener on the webView itself.