Avatar
それなら、Push系はNavigationLinkでEvent-Drivenできるし、Modal系は標準のAPIはないですが、Buttonの中で遷移状態をラップしたFullScreenPresentationLinkボタン作れば事実上のEvent-Driven遷移できるので、それでいいかなと思います 🤔 Tab系だけEvent-Drivenにする方法あまり思い浮かばないかな…(今のところそれやったことないので 😅 (edited)
8:09 AM
ちなみにうちは今こう言う感じのModal遷移ボタン作ってますw public struct FullScreenCoverPresentationLink<Label: View>: View { @State private var isPresented: Bool = false @State private var path: [Route] = [] @State private var toastHandler: ToastHandler = ToastHandler() @Environment(\.routingProvider) var routingProvider: RoutingProvider let route: Route let label: () -> Label public init(route: Route, label: @escaping () -> Label) { self.route = route self.label = label } public var body: some View { Button { isPresented = true } label: { label() } .fullScreenCover(isPresented: $isPresented, content: { NavigationStack(path: $path) { routingProvider.makeView(for: route) .displayToast(on: .bottom, handledBy: toastHandler, toastMaker: ToastView.init(toastHandler:)) .navigationDestination(for: Route.self, destination: { routingProvider.makeView(for: $0) }) .toolbar { ToolbarItem(placement: .topBarTrailing) { DismissButton() } } } }) } }
👀 2
8:09 AM
これで使う時は普通の NavigationLink と全く同じ方法で使えてるから結構楽ですw