Files
standardnotes-app-web/packages/mobile/MobileWebAppContainer.tsx
Vardan Hakobyan 4f5d092f89 feat(dev): option to render web app inside the mobile app (#1164)
* feat (WIP): render web app inside the mobile app

* fix: web app loading

* chore: build scripts related to mobile web bundle

* feat: show WebView header, which lets to close the WebView

* refactor: remove extra component

* chore: correct type

* chore: remove TODO

Co-authored-by: Mo <mo@standardnotes.com>
2022-06-30 13:53:29 +04:00

30 lines
985 B
TypeScript

import React from 'react'
import { Platform } from 'react-native'
import { WebView } from 'react-native-webview'
export const MobileWebAppContainer = () => {
const sourceUri = (Platform.OS === 'android' ? 'file:///android_asset/' : '') + 'Web.bundle/loader.html'
const params = 'platform=' + Platform.OS
const injectedJS = `
if (!window.location.search) {
var link = document.getElementById('web-bundle-progress-bar');
link.href = './src/index.html?${params}';
link.click();
}`
/* eslint-disable @typescript-eslint/no-empty-function */
return (
<WebView
source={{ uri: sourceUri }}
originWhitelist={['*']}
onLoad={() => {}}
onError={(err) => console.error('An error has occurred', err)}
onHttpError={() => console.error('An HTTP error occurred')}
onMessage={() => {}}
allowFileAccess={true}
injectedJavaScript={injectedJS}
/>
)
/* eslint-enable @typescript-eslint/no-empty-function */
}