Is Expo faking native ?

As a newbie, I wrote a
alert('hellooooo')
in a React native project and my Expo on phone simulator actually showed me the alert !

I was a bit confused, we’re supposed to see a pure native iOS or Android app with no JS at all… Is Expo faking native through a webView and is in fact purely web ? Or is the alert() JS function actually re-written in actual Objective-C or Java code ?

Sorry, might be naive. Thanks, Sylvain.

I was a bit confused, we’re supposed to see a pure native iOS or Android app with no JS at all

I’m not sure where you get those expectations, expo or in general, react-native executes js as there is, there is no magic conversion to objc or java. Native part are the components that react-native/expo and other libraries provide, you are using js code that calls native code. You can create webview inside rn app, but app itself is not rendered using webiview.

Or is the alert() JS function actually re-written in actual Objective-C or Java code ?

I have no idea, it’s either implemented in RN or you might have some dependency that is polyfiling web apis.

Hi @chaouidelgado

Have a look at this blog post that might clarify some things for you:

There is a JavaScript engine built into a React Native app. Traditionally JavaScriptCore, but lately there’s also Hermes. So the JavaScript code (or in the case of Hermes, bytecode) is run within the app. It is not transpiled to Java/Objective-C/whatever.

There is no WebView involved, except if you manually add one to your app. The app’s JavaScript runs in the JS engine. Not inside a WebView.

The alert() function is defined in the environment available when the JavaScript code is executing in the JS engine in the app. So it is expected for it to work.

1 Like

Ok merci !
Big revelation indeed, I thought all the js was converted in Objective-C or Java… by the way it could but might occurs some bug I guess, at least we would have a really native app.
I also thought that from a native point of view, only a webview can execute JS, but you wrote that it ships with a JS core… desktop and web are not so far away from each other apparently.
My alert() works on Expo but do you think it would with a compiled app uploaded to Play and App stores ?
Thanks !

It would be a huge effort to convert the JavaScript to Java or Objective-C, I think. It would not be worth it.

Check out William Candillon’s “Can it be done in React Native” on youtube to see what’s possible, and recent versions of React Native are moving to JSI which will make even more possible.

There are also versions of React Native for Windows and Mac, and Microsoft has rewritten some of their apps to it.

Yes, alert() will work the same way in the production version of your app, but there’s also Alert.alert() which will give you an alart with a title.