import SwiftUI

struct CustomBackButtonModifier<S: ShapeStyle>: ViewModifier {
    var background: S
    var action: () -> Void

    func body(content: Content) -> some View {
        content
            .navigationBarBackButtonHidden(true)
            .toolbar {
                ToolbarItem(placement: .topBarLeading) {
                    ToolbarButton(.back, background: background) { action() }
                }
            }
    }
}

public extension View {
    func customBackButton<S: ShapeStyle>(background: S, action: @escaping () -> Void) -> some View {
        modifier(CustomBackButtonModifier(background: background, action: action))
    }
}
