Android style fixes (#286)

* Delete redundant loading div

* Match SafeArea background color with system

* Format and lint
This commit is contained in:
Reckless_Satoshi 2022-10-15 18:39:43 +00:00 committed by GitHub
parent 7c52c90866
commit a8c2af5824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 485 additions and 440 deletions

View File

@ -1,18 +1,24 @@
import React, { useEffect, useRef } from 'react'; import React, { useEffect, useRef } from 'react';
import { WebView, WebViewMessageEvent } from 'react-native-webview'; import { WebView, WebViewMessageEvent } from 'react-native-webview';
import { SafeAreaView, Text, Platform } from 'react-native'; import { SafeAreaView, Text, Platform, Appearance } from 'react-native';
import TorClient from './services/Tor'; import TorClient from './services/Tor';
import Clipboard from '@react-native-clipboard/clipboard'; import Clipboard from '@react-native-clipboard/clipboard';
import NetInfo from '@react-native-community/netinfo'; import NetInfo from '@react-native-community/netinfo';
import EncryptedStorage from 'react-native-encrypted-storage'; import EncryptedStorage from 'react-native-encrypted-storage';
const backgroundColors = {
light: 'white',
dark: 'black',
};
const App = () => { const App = () => {
const colorScheme = Appearance.getColorScheme();
const torClient = new TorClient(); const torClient = new TorClient();
const webViewRef = useRef<WebView>(); const webViewRef = useRef<WebView>();
const uri = (Platform.OS === 'android' ? 'file:///android_asset/' : '') + 'Web.bundle/index.html'; const uri = (Platform.OS === 'android' ? 'file:///android_asset/' : '') + 'Web.bundle/index.html';
const injectMessageResolve = (id: string, data?: object) => { const injectMessageResolve = (id: string, data?: object) => {
const json = JSON.stringify(data || {}); const json = JSON.stringify((data != null) || {});
webViewRef.current?.injectJavaScript( webViewRef.current?.injectJavaScript(
`(function() {window.NativeRobosats.onMessageResolve(${id}, ${json});})();`, `(function() {window.NativeRobosats.onMessageResolve(${id}, ${json});})();`,
); );
@ -26,8 +32,8 @@ const App = () => {
}; };
const init = (reponseId: string) => { const init = (reponseId: string) => {
const loadCookie = (key: string) => { const loadCookie = async (key: string) => {
return EncryptedStorage.getItem(key).then((value) => { return await EncryptedStorage.getItem(key).then((value) => {
if (value) { if (value) {
const json = JSON.stringify({ key, value }); const json = JSON.stringify({ key, value });
webViewRef.current?.injectJavaScript( webViewRef.current?.injectJavaScript(
@ -132,7 +138,7 @@ const App = () => {
}; };
return ( return (
<SafeAreaView style={{ flex: 1 }}> <SafeAreaView style={{ flex: 1, backgroundColor: backgroundColors[colorScheme] }}>
<WebView <WebView
source={{ source={{
uri, uri,
@ -154,10 +160,10 @@ const App = () => {
setBuiltInZoomControls={false} setBuiltInZoomControls={false}
allowingReadAccessToURL={uri} allowingReadAccessToURL={uri}
allowFileAccess={true} allowFileAccess={true}
allowsBackForwardNavigationGestures={false} allowsBackForwardNavigationGestures={true}
mediaPlaybackRequiresUserAction={false} mediaPlaybackRequiresUserAction={false}
allowsLinkPreview={false} allowsLinkPreview={false}
renderLoading={() => <Text>Loading RoboSats</Text>} renderLoading={() => <Text></Text>}
onError={(syntheticEvent) => <Text>{syntheticEvent.type}</Text>} onError={(syntheticEvent) => <Text>{syntheticEvent.type}</Text>}
/> />
</SafeAreaView> </SafeAreaView>

903
mobile/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ class TorClient {
}); });
} }
private connectDaemon: () => void = async () => { private readonly connectDaemon: () => void = async () => {
try { try {
this.daemon.startIfNotStarted(); this.daemon.startIfNotStarted();
} catch { } catch {