From 1c46f52509f9fda3f71fd7991ccdc838652e8a92 Mon Sep 17 00:00:00 2001 From: linonetwo Date: Sun, 2 Feb 2025 11:33:00 +0800 Subject: [PATCH] feat: add renderToHardwareTextureAndroid --- .../localization/locales/en/translation.json | 4 +++- .../localization/locales/ja/translation.json | 4 +++- .../locales/zh_CN/translation.json | 4 +++- src/pages/Config/Performance.tsx | 19 ++++++++++++++++++- src/pages/WikiWebView/CustomWebview.tsx | 5 ++++- src/pages/WikiWebView/WikiViewer.tsx | 5 ++++- src/store/config.ts | 2 ++ 7 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/i18n/localization/locales/en/translation.json b/src/i18n/localization/locales/en/translation.json index a1d58b1..56f6e6a 100644 --- a/src/i18n/localization/locales/en/translation.json +++ b/src/i18n/localization/locales/en/translation.json @@ -442,7 +442,9 @@ "TranslucentStatusBar": "Translucent Status Bar", "TranslucentStatusBarDescription": "Allow the interface to be displayed below the status bar, overlapping with \n text on status bar, for more display space, but interface elements may be obscured by the status bar.", "HideStatusBar": "Hide Status Bar", - "HideStatusBarDescription": "Completely hide the status bar, more display space is available when hidden, but opening the status bar may require additional action. Does not take effect on bangs screen dig hole screen." + "HideStatusBarDescription": "Completely hide the status bar, more display space is available when hidden, but opening the status bar may require additional action. Does not take effect on bangs screen dig hole screen.", + "AndroidHardwareAcceleration": "Android Hardware Acceleration", + "AndroidHardwareAccelerationDescription": "Enabling it may potentially solve the issues of white screens on some device models or page crashes after being left in the background for a long time. However, it will reduce performance and cause videos to fail to load." }, "Error": { "InitWikiGitError": "E-1 InitWikiGitError", diff --git a/src/i18n/localization/locales/ja/translation.json b/src/i18n/localization/locales/ja/translation.json index 5391982..65fd13b 100644 --- a/src/i18n/localization/locales/ja/translation.json +++ b/src/i18n/localization/locales/ja/translation.json @@ -443,7 +443,9 @@ "TranslucentStatusBar": "半透明のステータスバー", "TranslucentStatusBarDescription": "インターフェイスをステータスバーの下に表示し、ステータスバーのテキストと重なります。表示スペースを増やすことができますが、インターフェイス要素がステータスバーによって隠されることがあります。", "HideStatusBar": "ステータスバーを非表示にする", - "HideStatusBarDescription": "ステータスバーを完全に非表示にします。非表示にすると、より多くの表示スペースが利用可能になりますが、ステータスバーを開くには追加の操作が必要になる場合があります。バンズスクリーンやドットホールスクリーンでは機能しません。" + "HideStatusBarDescription": "ステータスバーを完全に非表示にします。非表示にすると、より多くの表示スペースが利用可能になりますが、ステータスバーを開くには追加の操作が必要になる場合があります。バンズスクリーンやドットホールスクリーンでは機能しません。", + "AndroidHardwareAcceleration": "Androidのハードウェアアクセラレーション", + "AndroidHardwareAccelerationDescription": "有効にすると、一部の機種での白画面や、バックグラウンドに長時間置いた後の画面クラッシュの問題が解決するかもしれません。ただし、これにより性能が低下し、ビデオの読み込みができなくなる場合があります。" }, "Error": { "InitWikiGitError": "E - 1 InitWikiGitエラー", diff --git a/src/i18n/localization/locales/zh_CN/translation.json b/src/i18n/localization/locales/zh_CN/translation.json index bad1edf..f58780e 100644 --- a/src/i18n/localization/locales/zh_CN/translation.json +++ b/src/i18n/localization/locales/zh_CN/translation.json @@ -459,7 +459,9 @@ "TranslucentStatusBar": "半透明状态栏", "TranslucentStatusBarDescription": "让界面显示在状态栏之下,和状态栏重叠展示,获得更多展示空间,但界面元素有可能被状态栏遮挡。", "HideStatusBar": "隐藏状态栏", - "HideStatusBarDescription": "完全隐藏状态栏,隐藏后可以获得更多展示空间,但打开状态栏可能需要额外操作。在刘海屏挖孔屏上不生效。" + "HideStatusBarDescription": "完全隐藏状态栏,隐藏后可以获得更多展示空间,但打开状态栏可能需要额外操作。在刘海屏挖孔屏上不生效。", + "AndroidHardwareAcceleration": "安卓硬件加速", + "AndroidHardwareAccelerationDescription": "开启后可能可以解决有的机型上白屏或后台放久了页面崩溃的问题,但会降低性能并导致无法加载视频。" }, "Error": { "InitWikiGitError": "E-1 笔记仓库初始化失败错误", diff --git a/src/pages/Config/Performance.tsx b/src/pages/Config/Performance.tsx index 7e1d08f..9c8ac85 100644 --- a/src/pages/Config/Performance.tsx +++ b/src/pages/Config/Performance.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; +import { Platform } from 'react-native'; import { Switch, Text } from 'react-native-paper'; import { useShallow } from 'zustand/react/shallow'; import { FlexibleText, SwitchContainer } from '../../components/PreferenceWidgets'; @@ -8,7 +9,9 @@ import { useConfigStore } from '../../store/config'; export function Performance(): JSX.Element { const { t } = useTranslation(); - const [keepAliveInBackground, autoOpenDefaultWiki] = useConfigStore(useShallow(state => [state.keepAliveInBackground, state.autoOpenDefaultWiki])); + const [keepAliveInBackground, autoOpenDefaultWiki, androidHardwareAcceleration] = useConfigStore( + useShallow(state => [state.keepAliveInBackground, state.autoOpenDefaultWiki, state.androidHardwareAcceleration]), + ); const setConfig = useConfigStore(state => state.set); return ( @@ -33,6 +36,20 @@ export function Performance(): JSX.Element { }} /> + {Platform.OS === 'android' && ( + <> + {t('Preference.AndroidHardwareAcceleration')} + + {t('Preference.AndroidHardwareAccelerationDescription')} + { + setConfig({ androidHardwareAcceleration: value }); + }} + /> + + + )} ); } diff --git a/src/pages/WikiWebView/CustomWebview.tsx b/src/pages/WikiWebView/CustomWebview.tsx index 7328fb7..de897d2 100644 --- a/src/pages/WikiWebView/CustomWebview.tsx +++ b/src/pages/WikiWebView/CustomWebview.tsx @@ -12,7 +12,8 @@ interface CustomWebViewProps { preferredLanguage: string | undefined | null; reloadingKey: string | number; triggerFullReload: () => void; - useFileProtocol: boolean; + useFileProtocol: boolean | undefined; + androidHardwareAcceleration: boolean | undefined; webViewReference: MutableRefObject; wikiFolderLocation: string; } @@ -33,6 +34,7 @@ export class CustomWebView extends Component { injectedJavaScript, wikiFolderLocation, useFileProtocol, + androidHardwareAcceleration, triggerFullReload, } = this.props; @@ -89,6 +91,7 @@ export class CustomWebView extends Component { onMessage={onMessageReference.current} ref={webViewReference} webviewDebuggingEnabled={true /* Open chrome://inspect/#devices , or Development menu on Safari to debug the WebView. https://github.com/react-native-webview/react-native-webview/blob/master/docs/Debugging.md#debugging-webview-contents */} + renderToHardwareTextureAndroid={androidHardwareAcceleration} /> ); } diff --git a/src/pages/WikiWebView/WikiViewer.tsx b/src/pages/WikiWebView/WikiViewer.tsx index d8b254b..42d1039 100644 --- a/src/pages/WikiWebView/WikiViewer.tsx +++ b/src/pages/WikiWebView/WikiViewer.tsx @@ -62,7 +62,9 @@ export function WikiViewer({ wikiWorkspace, webviewSideReceiver, quickLoad }: Wi const onLoadEnd = useCallback(() => { setLoaded(true); }, []); - const [rememberLastVisitState, preferredLanguage] = useConfigStore(useShallow(state => [state.rememberLastVisitState, state.preferredLanguage])); + const [rememberLastVisitState, preferredLanguage, androidHardwareAcceleration] = useConfigStore( + useShallow(state => [state.rememberLastVisitState, state.preferredLanguage, state.androidHardwareAcceleration]), + ); /** * Register service JSB to be `window.service.xxxService`, for plugin in webView to call. */ @@ -144,6 +146,7 @@ export function WikiViewer({ wikiWorkspace, webviewSideReceiver, quickLoad }: Wi triggerFullReload={triggerFullReload} wikiFolderLocation={wikiWorkspace.wikiFolderLocation} useFileProtocol={wikiWorkspace.allowReadFileAttachment} + androidHardwareAcceleration={androidHardwareAcceleration} /> diff --git a/src/store/config.ts b/src/store/config.ts index 83fef3e..c478adc 100644 --- a/src/store/config.ts +++ b/src/store/config.ts @@ -21,6 +21,7 @@ export interface ConfigState { theme: ColorSchemeName | 'default'; translucentStatusBar?: boolean; userName: string; + androidHardwareAcceleration?: boolean; } const defaultConfig: ConfigState = { autoOpenDefaultWiki: undefined, @@ -36,6 +37,7 @@ const defaultConfig: ConfigState = { theme: 'default', translucentStatusBar: true, userName: '', + androidHardwareAcceleration: true, }; interface ConfigActions { set: (newConfig: Partial) => void;