Skip to content

Commit c933629

Browse files
authored
Merge pull request #1883 from EnsembleUI/webview_fix
[1882] Fixed External links are not opening in a webview for Android
2 parents 0e27c2f + acb83c2 commit c933629

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

modules/ensemble/lib/widget/webview/native/webviewstate.dart

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -146,41 +146,39 @@ class WebViewState extends EWidgetState<EnsembleWebView> with CookieMethods {
146146
headers: widget.controller.headers,
147147
)
148148
: null,
149-
initialOptions: InAppWebViewGroupOptions(
150-
crossPlatform: InAppWebViewOptions(
151-
useShouldOverrideUrlLoading: true,
152-
mediaPlaybackRequiresUserGesture: false,
153-
javaScriptEnabled: true,
154-
useOnLoadResource: true,
155-
clearCache: true,
156-
transparentBackground: true,
157-
supportZoom: true,
158-
preferredContentMode: UserPreferredContentMode.MOBILE,
159-
),
160-
android: AndroidInAppWebViewOptions(
161-
useHybridComposition: true,
162-
hardwareAcceleration: true,
163-
mixedContentMode:
164-
AndroidMixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW,
165-
safeBrowsingEnabled: false,
166-
domStorageEnabled: true,
167-
databaseEnabled: true,
168-
supportMultipleWindows: true,
169-
builtInZoomControls: true,
170-
displayZoomControls: false,
171-
allowFileAccess: true,
172-
useWideViewPort: true,
173-
allowContentAccess: true,
174-
loadWithOverviewMode: true,
175-
),
176-
ios: IOSInAppWebViewOptions(
177-
allowsInlineMediaPlayback: true,
178-
allowsBackForwardNavigationGestures: true,
179-
enableViewportScale: true,
180-
suppressesIncrementalRendering: false,
181-
allowsPictureInPictureMediaPlayback: true,
182-
isFraudulentWebsiteWarningEnabled: false,
183-
),
149+
initialSettings: InAppWebViewSettings(
150+
// Cross Platform Settings
151+
useShouldOverrideUrlLoading: true,
152+
mediaPlaybackRequiresUserGesture: false,
153+
javaScriptEnabled: true,
154+
useOnLoadResource: true,
155+
transparentBackground: true,
156+
supportZoom: true,
157+
clearCache: true,
158+
preferredContentMode: UserPreferredContentMode.MOBILE,
159+
160+
// Android Specific Settings
161+
useHybridComposition: true,
162+
hardwareAcceleration: true,
163+
mixedContentMode: MixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW,
164+
safeBrowsingEnabled: false,
165+
domStorageEnabled: true,
166+
databaseEnabled: true,
167+
supportMultipleWindows: true,
168+
builtInZoomControls: true,
169+
displayZoomControls: false,
170+
allowFileAccess: true,
171+
useWideViewPort: true,
172+
allowContentAccess: true,
173+
loadWithOverviewMode: true,
174+
175+
// iOS Specific Settings
176+
allowsInlineMediaPlayback: true,
177+
allowsBackForwardNavigationGestures: true,
178+
enableViewportScale: true,
179+
suppressesIncrementalRendering: false,
180+
allowsPictureInPictureMediaPlayback: true,
181+
isFraudulentWebsiteWarningEnabled: false,
184182
),
185183
gestureRecognizers: gestureRecognizers,
186184
onWebViewCreated: (controller) async {
@@ -234,9 +232,17 @@ class WebViewState extends EWidgetState<EnsembleWebView> with CookieMethods {
234232
setState(
235233
() => widget.controller.error = "Error loading html content");
236234
},
235+
onCreateWindow: (controller, createWindowAction) async {
236+
// Get the URL from the creation request
237+
final url = createWindowAction.request.url?.toString();
238+
if (url != null) {
239+
// Load the URL in the current WebView instead of creating a new window
240+
await controller.loadUrl(urlRequest: URLRequest(url: WebUri(url)));
241+
}
242+
return true;
243+
},
237244
shouldOverrideUrlLoading: (controller, navigationAction) async {
238245
final url = navigationAction.request.url?.toString() ?? '';
239-
240246
WebViewNavigationEvent event = WebViewNavigationEvent(widget, url);
241247
if (widget.controller.onNavigationRequest != null) {
242248
ScreenController().executeAction(

0 commit comments

Comments
 (0)