A demo of SmartFrame embeds in a react-native-webview. I have built this demo using the package versions we currently use in our NZH app:
- React Native: 0.72.17
- react-native-webview: 13.12.3
This version of React Native will not build in the latest version of XCode (16.4) so please install 16.2 or lower available from here.
The demo app consists of a Home Screen containing 3 buttons that display different forms of content in the WebView Screen which contains a react-native-webview component.
- Button 1: Displays an NZH article using the url: https://www.nzherald.co.nz/sport/rugby/all-blacks/all-blacks-v-france-scott-barrett-ruled-out-for-remainder-of-series-with-calf-injury/VGEAH7VP7RFSTKBVFCGERYCH4U/. This article contains a SmartFrame embed which displays correctly in the webview component
- Button 2: Displays a the SmartFrame embed from the article above in html format. This also includes the override script. The SmartFrame does not show at all in this format.
- Button 3: Displays a correctly X embed. I wanted to give an example of how we display other embeds within our app.
There is an additional injected JS script which returns the value 'window.location' of the webview to the console. This was how I was able to confirm that the window.location.href returns 'about:blank' when displaying the SmartFrame embed.
Note: Make sure you have completed the React Native - Environment Setup instructions till "Creating a new application" step, before proceeding.
To install the dependencies, run the following command from the root of your React Native project:
# using npm
npm installTo install the iOS dependencies, run the following command from the root of your React Native project:
# using npm
npm installFirst, you will need to start Metro, the JavaScript bundler that ships with React Native.
To start Metro, run the following command from the ios folder of your React Native project:
# using npm
pod installLet Metro Bundler run in its own terminal. Open a new terminal from the root of your React Native project. Run the following command to start your Android or iOS app:
# using npm
npm run android# using npm
npm run iosIf everything is set up correctly, you should see your new app running in your Android Emulator or iOS Simulator shortly provided you have set up your emulator/simulator correctly.
This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively.