JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.24k stars 1.11k forks source link

Compose layout system doesn't handle `additionalSafeAreaInsets` correctly. #4944

Open curliq opened 2 weeks ago

curliq commented 2 weeks ago

Describe the bug When scrolling a LazyColumn inside a UIViewController, the scrolling is ignored by the SwiftUI components, for example scrolling the content will not trigger the TabView's bottombar transitions into showing the shadow and the blur, and with a navigation title it won't collapse and expand the top navigation bar/

Affected platforms

Versions

To Reproduce Steps to reproduce the behaviour:

  1. Run this code snippet:
    @Composable
    fun Screen() {
       LazyColumn(modifier = Modifier.fillMaxWidth()) {
        (0..200).forEach {
            item {
                Text("test")
                Spacer(modifier = Modifier.height(8.dp))
            }
        }
    }
    }
    fun ScreenViewController() =
    ComposeUIViewController {
        Screen()
    }
    
    @available(iOS 16.0, *)
    @main
    struct iOSApp: App {
    init() {
        IosModulesKt.startKoin()
    }
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
    }

struct ContentView: View { var body: some View { TabView { Screen() .tabItem { Label("Hello", systemImage: "gear") } // ... more tabs } .onAppear() { let standardAppearance = UITabBarAppearance() // this would be triggered if the content reaches the bottombar standardAppearance.configureWithTransparentBackground() standardAppearance.backgroundColor = UIColor.systemGray6 UITabBar.appearance().standardAppearance = standardAppearance } } }

struct Screen: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> UIViewController { return MainViewControllerKt.ScreenViewController() }

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}

}


3. Scroll down 
4. See error

**Expected behavior**
The content would be drawn behind the bottombar and the bottombar would become slightly transparent. This is just the standard tabview behaviour if you use a SwiftUI ScrollView or a List, instead of the compose UIViewController

**Screenshots**

https://github.com/JetBrains/compose-multiplatform/assets/15181917/e5eb6aac-b080-4abd-be05-36c9408e70b9

Example of an apple app with the tabview bottombar default behaviour:

https://github.com/JetBrains/compose-multiplatform/assets/15181917/d11ba512-ec54-4ed1-b8a3-9f0772b92669

**Additional context**
I know the scrolling is handled by compose and is not an iOS native scroll but to be able to use compose in swiftUI it would be quite important to share scroll events
elijah-semyonov commented 2 weeks ago

Thought this issue is about scrolling, but it's about handling https://developer.apple.com/documentation/uikit/uiviewcontroller/2902284-additionalsafeareainsets coming from native UIViewControllers.