Skip to content

Commit bf72f2c

Browse files
committed
feat: mediaPlaybackRequiresUserAction && allowsInlineMediaPlayback
1 parent fc83f18 commit bf72f2c

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/webview-ext-common.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ export const webRTCProperty = new Property<WebViewExtBase, boolean>({
8484
valueConverter: booleanConverter,
8585
});
8686

87+
export const mediaPlaybackRequiresUserActionProperty = new Property<WebViewExtBase, boolean>({
88+
name: 'mediaPlaybackRequiresUserAction',
89+
defaultValue: true,
90+
valueConverter: booleanConverter,
91+
});
92+
93+
export const allowsInlineMediaPlaybackProperty = new Property<WebViewExtBase, boolean>({
94+
name: 'allowsInlineMediaPlayback',
95+
valueConverter: booleanConverter,
96+
});
97+
8798
export const srcProperty = new Property<WebViewExtBase, string>({
8899
name: 'src',
89100
});
@@ -1666,3 +1677,4 @@ viewPortProperty.register(WebViewExtBase);
16661677
isScrollEnabledProperty.register(WebViewExtBase);
16671678
scalesPageToFitProperty.register(WebViewExtBase);
16681679
webRTCProperty.register(WebViewExtBase);
1680+
mediaPlaybackRequiresUserActionProperty.register(WebViewExtBase);

src/webview-ext.android.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
supportZoomProperty,
1515
webConsoleProperty,
1616
NotaTraceCategory,
17+
mediaPlaybackRequiresUserActionProperty,
18+
allowsInlineMediaPlaybackProperty,
1719
} from './webview-ext-common';
1820

1921
export * from './webview-ext-common';
@@ -1062,4 +1064,12 @@ export class AWebView extends WebViewExtBase {
10621064
);
10631065
}
10641066
}
1067+
1068+
1069+
[mediaPlaybackRequiresUserActionProperty.setNative](enabled: boolean) {
1070+
this.nativeViewProtected.getSettings().setMediaPlaybackRequiresUserGesture(enabled);
1071+
}
1072+
[allowsInlineMediaPlaybackProperty.setNative](enabled: boolean) {
1073+
// not supported
1074+
}
10651075
}

src/webview-ext.ios.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { File, Trace, alert, confirm, knownFolders, profile, prompt } from '@nativescript/core';
22
import { isEnabledProperty } from '@nativescript/core/ui/core/view';
33
import { webViewBridge } from './nativescript-webview-bridge-loader';
4-
import { NavigationType, WebViewExtBase, autoInjectJSBridgeProperty, scrollBounceProperty, NotaTraceCategory, webRTCProperty } from './webview-ext-common';
4+
import { NavigationType, WebViewExtBase, autoInjectJSBridgeProperty, scrollBounceProperty, NotaTraceCategory, webRTCProperty, mediaPlaybackRequiresUserActionProperty, allowsInlineMediaPlaybackProperty } from './webview-ext-common';
55

66
export * from './webview-ext-common';
77

@@ -460,6 +460,14 @@ export class AWebView extends WebViewExtBase {
460460
this.webViewRTC = WKWebViewRTC.alloc().initWithWkwebviewContentController(nativeView, nativeView.configuration.userContentController);
461461
}
462462

463+
[mediaPlaybackRequiresUserActionProperty.setNative](enabled: boolean) {
464+
this.nativeViewProtected.configuration.setValueForKey(enabled?WKAudiovisualMediaTypes.All:WKAudiovisualMediaTypes.None, 'mediaTypesRequiringUserActionForPlayback');
465+
466+
}
467+
[allowsInlineMediaPlaybackProperty.setNative](enabled: boolean) {
468+
this.nativeViewProtected.configuration.setValueForKey(enabled, 'allowsInlineMediaPlayback');
469+
}
470+
463471
/**
464472
* iOS11+
465473
*

0 commit comments

Comments
 (0)