siteline / swiftui-introspect

Introspect underlying UIKit/AppKit components from SwiftUI
MIT License
5.69k stars 352 forks source link

Navigation bar shrinking behavior is broken #394

Open Uki19 opened 10 months ago

Uki19 commented 10 months ago

Description

I have a WebView (custom UIViewRepresentable component with WKWebView) within NavigationStack, and by default, scrolling animation of navigation bar (shrinking between large title and inline) is working fine. As soon as I add .introspect modifier on it, the shrinking animation doesn't work anymore.

If I use just a swiftUI ScrollView with ForEach, navbar shrinking works fine in both cases, so it might be something to do with .introspect on custom UIViewRepresentable, but I am not sure.

Video example without .introspect modifier:

https://github.com/siteline/swiftui-introspect/assets/9538239/8684d99d-bc28-4ee6-90c1-ac5f229d722c

Video example with .introspect modifier:

https://github.com/siteline/swiftui-introspect/assets/9538239/0da67412-e750-4481-9a62-dd11e6ac6690

Checklist

Expected behavior

Navigation bar has default shrinking animation behavior

Actual behavior

Navigation bar is not shrinking/animating at all

Steps to reproduce

Here's simplest example of the issue, you can comment .introspect modifier to compare behavior

import SwiftUIIntrospect
import SwiftUI
import WebKit

struct WebView: UIViewRepresentable {

    func makeUIView(context: Context) -> WKWebView {
        let webview = WKWebView()
        let request = URLRequest(url: URL(string: "https://www.apple.com")!)
        webview.load(request)
        return webview
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
    }
}

struct ContentView: View {
    var body: some View {
        NavigationStack {
            WebView()
                .ignoresSafeArea(edges: [.bottom])
                .navigationTitle("Webview")
                .introspect(.navigationStack, on: .iOS(.v17), scope: .ancestor) { nav in
                    print(nav)
                }
        }
    }
}

#Preview {
    ContentView()
}

Version information

1.1.2

Destination operating system

No response

Xcode version information

No response

Swift Compiler version information

No response

RoblesJ commented 4 months ago

hello i may be a little late here, but i believe you just have to remove your NavigationStack in this view, i came across the same issue and i fixed this by doing so,