Skip to content
This repository was archived by the owner on Nov 27, 2025. It is now read-only.

Commit 654676b

Browse files
author
17691002584
committed
feat:支持ignoreSilentHardwareSwitch
1 parent 48f3857 commit 654676b

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

harmony/rn_webview/src/main/ets/RNCWebView.ets

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ export struct RNCWebView {
356356
return true
357357
}
358358

359+
ignoreSilentHardwareSwitchMethods(ignoreSilentHardwareSwitch: boolean) {
360+
this.webViewBaseOperate?.ignoreSilentHardwareSwitchMethods(ignoreSilentHardwareSwitch)
361+
}
362+
359363
build() {
360364
Stack() {
361365
Web({ src: "", controller: this.controller, renderMode: this.renderMode })
@@ -377,8 +381,8 @@ export struct RNCWebView {
377381
.overScrollMode(this.overScrollMode)
378382
.onProgressChange((event) => {
379383
if (event) {
380-
this.progress = event.newProgress
381-
this.onProgressChange()
384+
this.progress = event.newProgress
385+
this.onProgressChange()
382386
}
383387
})
384388
.onScroll((event) => {
@@ -429,6 +433,7 @@ export struct RNCWebView {
429433
}
430434
})
431435
.onControllerAttached(() => {
436+
this.ignoreSilentHardwareSwitchMethods(this.descriptorWrapper.props.ignoreSilentHardwareSwitch)
432437
this.controllerAttached = true;
433438
Logger.debug(TAG, "[RNOH] onControllerAttached")
434439
let baseUrl = this.source.baseUrl
@@ -453,6 +458,7 @@ export struct RNCWebView {
453458
if (!this.hasRegisterJavaScriptProxy) {
454459
this.registerPostMessage()
455460
}
461+
this.ignoreSilentHardwareSwitchMethods(this.descriptorWrapper.props.ignoreSilentHardwareSwitch)
456462
})
457463
.onAlert((event) => this.onJavascriptAlert(event))
458464
.onConfirm((event) => this.onJavascriptConfirm(event))
@@ -562,7 +568,6 @@ export struct RNCWebView {
562568
}
563569
};
564570
this.controller.registerJavaScriptProxy(bridge, JAVASCRIPT_INTERFACE, ["postMessage"])
565-
// this.controller.refresh()
566571
this.controller.loadUrl(this.source.uri, this.headers);
567572
this.hasRegisterJavaScriptProxy = true
568573
}

harmony/rn_webview/src/main/ets/WebViewBaseOperate.ets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,10 @@ export class BaseOperate {
196196
}
197197
return result;
198198
}
199+
200+
ignoreSilentHardwareSwitchMethods(ignoreSilentHardwareSwitch: boolean) {
201+
Logger.info(TAG,
202+
`ignoreSilentHardwareSwitchignoreSilentHardwareSwitchignoreSilentHardwareSwitch==${JSON.stringify(!ignoreSilentHardwareSwitch)}`)
203+
this.controller.setAudioMuted(!ignoreSilentHardwareSwitch)
204+
}
199205
}

src/RNCWebViewNativeComponent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export interface NativeProps extends ViewProps {
175175
allowsAirPlayForMediaPlayback?: boolean;
176176
allowsLinkPreview?: boolean;
177177
automaticallyAdjustContentInsets?: boolean;
178+
ignoreSilentHardwareSwitch?:boolean;
178179
autoManageStatusBarEnabled?: boolean;
179180
bounces?: boolean;
180181
contentInset?: Readonly<{
@@ -212,6 +213,7 @@ export interface NativeProps extends ViewProps {
212213
// Workaround to watch if listener if defined
213214
hasOnFileDownload?: boolean;
214215
fraudulentWebsiteWarningEnabled?: boolean;
216+
215217
// !iOS only
216218

217219
allowFileAccessFromFileURLs?: boolean;
@@ -254,7 +256,7 @@ export interface NativeProps extends ViewProps {
254256
html?: string;
255257
baseUrl?: string;
256258
}>;
257-
userAgent?: string;
259+
userAgent?: string;
258260
}
259261

260262
export interface NativeCommands {
@@ -279,4 +281,4 @@ export const Commands = codegenNativeCommands<NativeCommands>({
279281

280282
export default codegenNativeComponent<NativeProps>(
281283
'RNCWebView'
282-
) as HostComponent<NativeProps>;
284+
) as HostComponent<NativeProps>;

src/WebView.harmony.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps & {scalesPageToFit: bool
5858
javaScriptEnabled = true,
5959
cacheEnabled = true,
6060
originWhitelist = defaultOriginWhitelist,
61+
ignoreSilentHardwareSwitch,
6162
useSharedProcessPool = true,
6263
textInteractionEnabled = true,
6364
injectedJavaScript,
@@ -136,6 +137,7 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps & {scalesPageToFit: bool
136137
onOpenWindowProp,
137138
startInLoadingState,
138139
originWhitelist,
140+
ignoreSilentHardwareSwitch,
139141
onShouldStartLoadWithRequestProp,
140142
onShouldStartLoadWithRequestCallback,
141143
onContentProcessDidTerminateProp,
@@ -237,6 +239,7 @@ const WebViewComponent = forwardRef<{}, IOSWebViewProps & {scalesPageToFit: bool
237239
key="webViewKey"
238240
{...otherProps}
239241
scrollEnabled={otherProps.scrollEnabled ?? true}
242+
ignoreSilentHardwareSwitch={ignoreSilentHardwareSwitch}
240243
scalesPageToFit={otherProps.scalesPageToFit ?? true}
241244
fraudulentWebsiteWarningEnabled={fraudulentWebsiteWarningEnabled}
242245
javaScriptEnabled={javaScriptEnabled}

0 commit comments

Comments
 (0)