hermes icon indicating copy to clipboard operation
hermes copied to clipboard

Use hermes on mobile native code without react native

Open GlisboaDev opened this issue 1 year ago • 4 comments

Problem

I'm looking into executing JS code on a native app (iOS/Android non-react native), and exploring using Hermes to optimize it. Is there any documentation on this?

The goal is to have a JS code snippet, call a function there with certain params and get an output back on the native code.

For instance on iOS by replacing the usage of JavaScriptCore:

        let context = JSContext()
        let myFn = context?.evaluateScript(myJsScript)
        let result = myFn.call(withArguments: ["something here"]);

GlisboaDev avatar Apr 04 '23 17:04 GlisboaDev

The short answer is that yes, this is possible and generally speaking easy. However there isn't good documentation for this use case since almost all of our user-facing documentation is RN-specific.

We have had similar question asked before:

  • https://github.com/facebook/hermes/issues/43
  • https://github.com/facebook/hermes/issues/326

We would welcome a community contribution with documentation about it :-)

tmikov avatar Apr 04 '23 19:04 tmikov

@tmikov thank you for the links. I'm evaluating our options, and once I get back to this I'll dig a bit in there and add some documentation if we manage to achieve our objectives.

GlisboaDev avatar Apr 11 '23 19:04 GlisboaDev

@GlisboaDev Have you made any progress or have a working example yet?

benjaminbarbe avatar Feb 21 '24 14:02 benjaminbarbe

@benjaminbarbe there are working examples here: https://github.com/tmikov/hermes-jsi-demos

tmikov avatar Feb 21 '24 17:02 tmikov