Giter Club home page Giter Club logo

Comments (4)

davdroman avatar davdroman commented on June 8, 2024 1

Thank you for the comprehensive report. I'll look into this as soon as I can.

from swiftui-navigation-transitions.

davdroman avatar davdroman commented on June 8, 2024 1

So I think maybe better not to introduce the one-line fix into the library (and we also rarely have the navigation bar visibility varying between screens? 🫠)

I concur. If anyone else raises this issue, now we have somewhere to direct them for answers.

I guess I'll be closing this now. Thank you for your research 🤝

from swiftui-navigation-transitions.

davdroman avatar davdroman commented on June 8, 2024

Sorry for the delay. Very weird indeed, most definitely a SwiftUI bug that's hidden by the fact that one can't swipe back when nav bars are hidden in vanilla SwiftUI.

Your solution does (somehow? 🤯) work, so I'm going to apply it selectively on iOS 17 and write some regression UI tests in order to have our bases covered for when iOS 18 comes around. I'm currently quite busy so this will take me until sometime next week, but feel free to do it yourself and PR it if you feel like it. My current working branch is https://github.com/davdroman/swiftui-navigation-transitions/tree/fix/freezing-ios-17.

from swiftui-navigation-transitions.

muzix avatar muzix commented on June 8, 2024

Hi @davdroman Thanks for your time. I found that my one-line fixed the issue at first but then it introduced another problem.

navigationController.setNavigationBarHidden(false, animated: true)

The problem is in this context, we don't know if the target view controller needs a hidden navigation bar or not.
So if we go back and forth between screen A (not hidden) and screen B (hidden bar), or even more screens involved, the navigation bar visibility will be messed up. Even freezing happens when the visibility doesn't match what we declared in SwiftUI view.

In my project, I workaround this issue by not patching the library, but using a delegate instead

.navigationTransition(.default, interactivity: panNavigationState.isPanEnabled ? .pan : .disabled)
        .introspectNavigationController { navigationController in
            if #available(iOS 17, *) {
                navigationController.delegate = NavigationControllerBaseDelegate.shared
            }
        }
class NavigationControllerBaseDelegate: NSObject, UINavigationControllerDelegate {
    static let shared = NavigationControllerBaseDelegate()

    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        navigationController.setNavigationBarHidden(viewController.isNavBarHidden, animated: true)
    }
}

isNavBarHidden is the property I injected into the underlying UIViewController of the SwiftUI view, where I set the navigation bar visibility

.navigationBarHidden(true)
.introspectViewController { viewController in
      viewController.isNavBarHidden = true
}

Quite a lot of weird code but the solution is working fine so far in my project. So I think maybe better not to introduce the one-line fix into the library (and we also rarely have the navigation bar visibility varying between screens? 🫠)

from swiftui-navigation-transitions.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.