Skip to content

Commit

Permalink
feat: add renderToHardwareTextureAndroid
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Feb 2, 2025
1 parent ab14fca commit 1c46f52
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/i18n/localization/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/localization/locales/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,9 @@
"TranslucentStatusBar": "半透明のステータスバー",
"TranslucentStatusBarDescription": "インターフェイスをステータスバーの下に表示し、ステータスバーのテキストと重なります。表示スペースを増やすことができますが、インターフェイス要素がステータスバーによって隠されることがあります。",
"HideStatusBar": "ステータスバーを非表示にする",
"HideStatusBarDescription": "ステータスバーを完全に非表示にします。非表示にすると、より多くの表示スペースが利用可能になりますが、ステータスバーを開くには追加の操作が必要になる場合があります。バンズスクリーンやドットホールスクリーンでは機能しません。"
"HideStatusBarDescription": "ステータスバーを完全に非表示にします。非表示にすると、より多くの表示スペースが利用可能になりますが、ステータスバーを開くには追加の操作が必要になる場合があります。バンズスクリーンやドットホールスクリーンでは機能しません。",
"AndroidHardwareAcceleration": "Androidのハードウェアアクセラレーション",
"AndroidHardwareAccelerationDescription": "有効にすると、一部の機種での白画面や、バックグラウンドに長時間置いた後の画面クラッシュの問題が解決するかもしれません。ただし、これにより性能が低下し、ビデオの読み込みができなくなる場合があります。"
},
"Error": {
"InitWikiGitError": "E - 1 InitWikiGitエラー",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/localization/locales/zh_CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@
"TranslucentStatusBar": "半透明状态栏",
"TranslucentStatusBarDescription": "让界面显示在状态栏之下,和状态栏重叠展示,获得更多展示空间,但界面元素有可能被状态栏遮挡。",
"HideStatusBar": "隐藏状态栏",
"HideStatusBarDescription": "完全隐藏状态栏,隐藏后可以获得更多展示空间,但打开状态栏可能需要额外操作。在刘海屏挖孔屏上不生效。"
"HideStatusBarDescription": "完全隐藏状态栏,隐藏后可以获得更多展示空间,但打开状态栏可能需要额外操作。在刘海屏挖孔屏上不生效。",
"AndroidHardwareAcceleration": "安卓硬件加速",
"AndroidHardwareAccelerationDescription": "开启后可能可以解决有的机型上白屏或后台放久了页面崩溃的问题,但会降低性能并导致无法加载视频。"
},
"Error": {
"InitWikiGitError": "E-1 笔记仓库初始化失败错误",
Expand Down
19 changes: 18 additions & 1 deletion src/pages/Config/Performance.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
Expand All @@ -33,6 +36,20 @@ export function Performance(): JSX.Element {
}}
/>
</SwitchContainer>
{Platform.OS === 'android' && (
<>
<Text variant='titleLarge'>{t('Preference.AndroidHardwareAcceleration')}</Text>
<SwitchContainer>
<FlexibleText>{t('Preference.AndroidHardwareAccelerationDescription')}</FlexibleText>
<Switch
value={androidHardwareAcceleration}
onValueChange={(value) => {
setConfig({ androidHardwareAcceleration: value });
}}
/>
</SwitchContainer>
</>
)}
</>
);
}
5 changes: 4 additions & 1 deletion src/pages/WikiWebView/CustomWebview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebView | null>;
wikiFolderLocation: string;
}
Expand All @@ -33,6 +34,7 @@ export class CustomWebView extends Component<CustomWebViewProps> {
injectedJavaScript,
wikiFolderLocation,
useFileProtocol,
androidHardwareAcceleration,
triggerFullReload,
} = this.props;

Expand Down Expand Up @@ -89,6 +91,7 @@ export class CustomWebView extends Component<CustomWebViewProps> {
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}
/>
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/WikiWebView/WikiViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -144,6 +146,7 @@ export function WikiViewer({ wikiWorkspace, webviewSideReceiver, quickLoad }: Wi
triggerFullReload={triggerFullReload}
wikiFolderLocation={wikiWorkspace.wikiFolderLocation}
useFileProtocol={wikiWorkspace.allowReadFileAttachment}
androidHardwareAcceleration={androidHardwareAcceleration}
/>
</WebViewContainer>
</>
Expand Down
2 changes: 2 additions & 0 deletions src/store/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ConfigState {
theme: ColorSchemeName | 'default';
translucentStatusBar?: boolean;
userName: string;
androidHardwareAcceleration?: boolean;
}
const defaultConfig: ConfigState = {
autoOpenDefaultWiki: undefined,
Expand All @@ -36,6 +37,7 @@ const defaultConfig: ConfigState = {
theme: 'default',
translucentStatusBar: true,
userName: '',
androidHardwareAcceleration: true,
};
interface ConfigActions {
set: (newConfig: Partial<ConfigState>) => void;
Expand Down

0 comments on commit 1c46f52

Please sign in to comment.