I am working on a more traditional React Native app. There has been a requirement given to include small mini-games within the app.
I would really like to allow our dev team to utilize a game making tool such as GameMaker. It allows export of HTML5 assets to run the game as Javascript, so I figured I could load it up in a WebView and be done with it.
Apparently it's not that simple :(
I tried the following:
- Export the game and put it's directory into the React Native assets folder (ex.
assets/spackrocks/). - Install the
react-native-webviewpackage. - Implement the game as such inside of an
Asteroidspage within the RN app:
import { StyleSheet, Platform } from "react-native";import React from "react";import { WebView } from "react-native-webview";const Asteroids = () => { const source = Platform.OS === "ios" ? require("../../assets/asteroid/index.html") : { uri: "file:///android_asset/asteroid/index.html" }; return (<WebView styles={style.container} source={source} allowFileAccess={true} allowUniversalAccessFromFileURLs={true} javaScriptEnabled={true} domStorageEnabled={true} originWhitelist={["*"]} onMessage={event => { console.log(event.nativeEvent.data); }} /> );};export default Asteroids;const style = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", },});This loads the index.html without issue. However, the containing js file cannot be loaded inside index.html. I get the following output in the console:
Error: 'assets/asteroid/html5game/Space%20Rocks.js' cannot be loaded as its extension is not registered in assetExtsAppending "js" to assetsExts isn't possible from my understanding, as the js file is not a static asset such as an image.
I'm unsure how to proceed. Is there a way to make this happen? Am I going about it completely wrong?
Thanks for any help :)