rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
924 stars 98 forks source link

Custom back button modifier #131

Open lowryrussell opened 9 months ago

lowryrussell commented 9 months ago

Anyone have a custom navigation back button implementation they're willing to share?

jedmund commented 6 months ago

I'm also interested in this!

obaida-mostarihi commented 2 months ago

@lowryrussell I had to clone the repository and make my own implementation for that, i changed the base code, if you're interested i can share with you how i did it

trinvh commented 2 months ago

@obaida-mostarihi I'm interested as well. Could you please share?

obaida-mostarihi commented 2 months ago

@trinvh First of all i don't recommend using this library since it does not support new ios versions, it's so outdated it has a lot of navigation bugs, it's still using NavigationView instead of NavigationStack, but here's how you can add the hideBackButton:

once you fork the repository go to the package in folder "NavigationCoordinatable" and file "NavigationCoordinatable" add to the protocol this line var navigationBarHidden: Bool { get }

in the same class you'll find an extension for NavigationCoordinatable add this line

  var navigationBarHidden: Bool {
        return false
    }

then in "PresentationHelper" file under "NavigationCoordinatable" folder, inside the switch statement find case .push and change it into the following:

               if presentable is AnyView {
                        let view = AnyView(NavigationCoordinatableView(id: nextId, coordinator: coordinator))

                        self.presented = Presented(
                            view: AnyView(view.navigationBarBackButtonHidden(coordinator.navigationBarHidden)),
                            type: .push
                        )
                    } else {
                        self.presented = Presented(
                            view: AnyView(presentable.view().navigationBarBackButtonHidden(coordinator.navigationBarHidden)),
                            type: .push
                        )
                    }