From d0ca48665801ac644bfdea075164b399206ea7f8 Mon Sep 17 00:00:00 2001 From: hewei Date: Sun, 19 May 2024 20:50:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0goBack=E3=80=81goForw?= =?UTF-8?q?ard=E3=80=81reload=E7=AD=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rn_webview/src/main/ets/RNCWebView.ets | 51 +++++++++++++++++++ src/WebView.harmony.tsx | 2 + 2 files changed, 53 insertions(+) diff --git a/harmony/rn_webview/src/main/ets/RNCWebView.ets b/harmony/rn_webview/src/main/ets/RNCWebView.ets index e54b9e199..b28a38fa1 100644 --- a/harmony/rn_webview/src/main/ets/RNCWebView.ets +++ b/harmony/rn_webview/src/main/ets/RNCWebView.ets @@ -282,6 +282,57 @@ export struct RNCWebView { } } break + case "goBack": + Logger.debug(TAG, `[RNOH] goBack,${JSON.stringify(args)}`) + if (this.controllerAttached) { + try { + this.controller.backward(); + } catch (error) { + Logger.error(TAG, "error: " + error) + } + } + break + case "goForward": + Logger.debug(TAG, `[RNOH] goForward,${JSON.stringify(args)}`) + if (this.controllerAttached) { + try { + this.controller.forward(); + } catch (error) { + Logger.error(TAG, "error: " + error) + } + } + break + case "requestFocus": + Logger.debug(TAG, `[RNOH] requestFocus,${JSON.stringify(args)}`) + if (this.controllerAttached) { + try { + this.controller.requestFocus(); + } catch (error) { + Logger.error(TAG, "error: " + error) + } + } + break + case "clearCache": + Logger.debug(TAG, `[RNOH] clearCache,${JSON.stringify(args)}`) + if (this.controllerAttached) { + try { + const removeFlag = !!args[0] === true; + this.controller.removeCache(removeFlag); + } catch (error) { + Logger.error(TAG, "error: " + error) + } + } + break + case "clearHistory": + Logger.debug(TAG, `[RNOH] clearHistory,${JSON.stringify(args)}`) + if (this.controllerAttached) { + try { + this.controller.clearHistory(); + } catch (error) { + Logger.error(TAG, "error: " + error) + } + } + break default: break } diff --git a/src/WebView.harmony.tsx b/src/WebView.harmony.tsx index 326add02d..ebc072e20 100644 --- a/src/WebView.harmony.tsx +++ b/src/WebView.harmony.tsx @@ -164,6 +164,8 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps>( clearCache: (includeDiskFiles: boolean) => webViewRef.current && Commands.clearCache(webViewRef.current, includeDiskFiles), + clearHistory: () => webViewRef.current && Commands.clearHistory(webViewRef.current), + loadUrl: (data: string) => webViewRef.current && Commands.loadUrl(webViewRef.current, data), }), [setViewState, webViewRef] );