Új megközelítés a webmotor natív alkalmazásokba történő keveréséhez
Mi lenne, ha elmondanám a JSON fenti, narancssárga színű 7 sorát, amire szükséged van ahhoz, hogy egy weboldalt mobilalkalmazássá alakítsunk? Nem kell átírnia webhelyét valamilyen keretrendszer-API használatával, csak azért, hogy a mobilalkalmazásként viselkedjen. Csak hozza a meglévő webhelyét a jelenlegi állapotában, és keverje bele natív alkalmazásba, egyszerű URL hivatkozással.
És mi van akkor, ha a JSON jelölés kissé módosításával elérheti az összes natív API-t, natív felhasználói felület összetevőket, valamint a natív nézetátmeneteket a dobozból?
Így néz ki egy minimális példa működés közben:

Figyelje meg, hogyan ágyaztam be a github.com weboldalt, de az elrendezés többi része minden natív felhasználói felület-összetevő, például a navigációs fejléc és az alsó lapsáv. Az átállás pedig automatikusan natív, anélkül, hogy át kellene írnia a webhelyet bármilyen API-val.
Mielőtt elmagyaráznám, hogyan teheti fel, megkérdezheti: "Ez nagyon jó, de tehet-e bármi értelmes dolgot azon kívül, hogy csak a weboldalt natív alkalmazáskeretben jeleníti meg?"
Remek kérdés, mert ez a bejegyzés fő témája. Mindössze annyit kell tennie, hogy zökkenőmentes kétirányú kommunikációs csatornát hozzon létre az internetes nézet és az alkalmazás között , így a szülőalkalmazás bármilyen JavaScript-funkciót kiválthat az internetes nézetben, és a webnézet kívül elérheti a natív API-k hívását.
Íme egy ilyen példa:

Vegye figyelembe, hogy ez a nézet a következőket tartalmazza:
- Natív navigációs fejléc, beépített átmeneti funkciókkal kiegészítve
- A Web view, which embeds a QR code generator web app
- A native chat input component at the bottom
All this can be described by just tweaking some of the JSON markup attributes we saw above.
Finally, note that the QR code changes as you enter something from the chat input. The chat input triggers a JavaScript function inside the QR code web app that re-generates the image.
No app development framework has tried to fundamentally solve this problem of “seamless integration of web view into native apps” because they’re all focused on picking either 100% native or 100% HTML5 side.
Whenever you hear someone talk about the future of mobile apps, you would probably hear them talk about “Will it be the HTML5 approach that wins out? Or will it be native?”
None of them see native
and html
as something that could co-exist and furthermore, create synergy and achieve things that are not easily possible otherwise.
In this article I’m going to explain:
- Why blending web engine and native components is often a good idea.
- Why a seamless integration of HTML and Native is not easy, and how I implemented one.
- Most importantly, how YOU can use it to build your own app instantly.
Why would you use HTML in a native app?
Before we go further, let’s first discuss whether this is even a good idea, and when you may want to take this approach. Here are some potential use cases:
1. Use Web Native Features
Some parts of your app may be better implemented using the web engine. For example, Websocket is a web-native feature that’s designed for the web environment. In this case it makes sense to use the built-in web engine (WKWebView for iOS and WebView for Android) instead of installing a 3rd party library that essentially “emulates” Websocket.
No need to install additional code just to do something that you can do for free, which brings us to the next point.
2. Avoid Large Binary Size
You may want to quickly incorporate features that will otherwise require a huge 3rd party library.

Original text
For example, to incorporate a QR code image generator natively, you will need to install some 3rd party library which will increase the binary size. But if you use the web view engine and a JavaScript library through a simple