Instawork / hyperview

Server-driven mobile apps with React Native

Home Page:https://hyperview.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Send data from webview message?

Afani97 opened this issue · comments

First things first, awesome library!

How can I emit a value from a webview?

Is it possible to set a new value from the webview? For example, I have a timer in a webview that needs to send back the value to a text field in order to create a new object.

If not, maybe it can be updated to support objects and string?

Something like: hyperview:{'event-name': 'set-value', 'new-value': '1'}?

Hi, it is possible to dispatch an event from a web view that can trigger a behavior in Hyperview. The documentation for that feature is available here: https://hyperview.org/docs/reference_web#dispatching-events-from-web-views

However, this approach does not support passing a specific value to set in an input field. Can you tell me more about your use case? Perhaps there’s an alternate approach to achieve what you’re trying to do.

Sure thing, long story short is I have a timer component in my web app that I'd to re-use in the mobile app instead of recreating it/using a react native library.

The value from the timer is used to create a new object for users to track their time.

Very simply I need to dispatch the value from the timer after a user clicks "done" and then the user can click save to finish off the task.

If there isn't a clean way to do this using hyperview alone, I'll probably move the other form inputs into that webview page and fire off a complete event to reload the screen after a successful submit.

Looking forward to your thoughts, thanks!

I got a working version using react-native-stopwatch-timer so it saves me the trouble of recreating this and creating a custom component worked well!

I'll close this.

Glad to hear it! Custom components are often the answer for this type of functionality. At Instawork, we have a custom timer component too. It triggers events at different countdown steps.