Skip to content

bugfix: WebView not ignoring safe area in full-screen mode on iOS#378

Merged
KevinnZou merged 2 commits intoKevinnZou:mainfrom
Erkko68:main
Oct 17, 2025
Merged

bugfix: WebView not ignoring safe area in full-screen mode on iOS#378
KevinnZou merged 2 commits intoKevinnZou:mainfrom
Erkko68:main

Conversation

@Erkko68
Copy link
Copy Markdown
Contributor

@Erkko68 Erkko68 commented Oct 3, 2025

When embedding a full-screen WebView in Compose Multiplatform on iOS, the view does not correctly ignore the safe area.

Even if the SwiftUI hosting side applies:

struct ContentView: View {
    var body: some View {
        ComposeView()
            .ignoresSafeArea(.all)
    }
}

…the WebView is still inset by iOS safe areas.

Before (safe area respected incorrectly): image

After investigating related issues (#159), I found that the problem began after introducing a ScrollView wrapper. By default, UIScrollView always respects the safe area insets, even if Compose requests to ignore them.

Solution

The fix is to explicitly disable automatic content inset adjustment for the underlying UIScrollView. We can do this by setting:

contentInsetAdjustmentBehavior = platform.UIKit.UIScrollViewContentInsetAdjustmentBehavior.UIScrollViewContentInsetAdjustmentNever

After (expected full-screen WebView): image

This allows to manage safe area handling (e.g., with .ignoresSafeArea(.all) or .ignoresSafeArea(.keyboard) or Compose itself) instead of iOS forcing additional insets.

This fix was tested with a modified version of HtmlWebViewSample.kt:

@Composable
internal fun BasicWebViewWithHTMLSample(navHostController: NavHostController? = null) {
    val webViewState =
        rememberWebViewStateWithHTMLFile(
            fileName = Res.getUri("files/samples/index.html"),
            readType = WebViewFileReadType.COMPOSE_RESOURCE_FILES,
        )
    val webViewNavigator = rememberWebViewNavigator()
    val jsBridge = rememberWebViewJsBridge(webViewNavigator)

    LaunchedEffect(Unit) {
        initWebView(webViewState)
        initJsBridge(jsBridge)
    }

    MaterialTheme {
        WebView(
            state = webViewState,
            modifier = Modifier.fillMaxSize(),
            captureBackPresses = false,
            navigator = webViewNavigator,
            webViewJsBridge = jsBridge,
        )
    }
}

Related Issues:
#159
#287

@Erkko68 Erkko68 changed the title bugfix: Full-screen WebView ignores safe area on iOS bugfix: WebView not ignoring safe area in full-screen mode on iOS Oct 3, 2025
@Erkko68
Copy link
Copy Markdown
Contributor Author

Erkko68 commented Oct 11, 2025

@KevinnZou Could you please rerun the workflows? Sorry about the earlier code style issues. I didn’t realize I could run the check locally with ./gradlew ktlintCheck. I’ve also rebased the previous commits to clean things up.

@KevinnZou KevinnZou merged commit e686d39 into KevinnZou:main Oct 17, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants