Skip to content

Instantly share code, notes, and snippets.

@1mash0
Created December 19, 2023 16:54
Show Gist options
  • Save 1mash0/51670cee0a2c79b36009028832153e08 to your computer and use it in GitHub Desktop.
Save 1mash0/51670cee0a2c79b36009028832153e08 to your computer and use it in GitHub Desktop.
TapGestureとLongPressGestureを共存させて遷移先を変える
import SwiftUI
struct ContentView: View {
@State var isLongPress = false
@State var isTap = false
var body: some View {
NavigationStack {
Button {
} label: {
Text("押せ!!")
}
.navigationDestination(isPresented: $isLongPress) {
SecondView()
.navigationTitle("SecondView")
}
.navigationDestination(isPresented: $isTap) {
ThirdView()
.navigationTitle("ThirdView")
}
.simultaneousGesture(
LongPressGesture(minimumDuration: 0.4)
.onEnded { _ in
print("long press gesture")
isLongPress.toggle()
}
)
.simultaneousGesture(
TapGesture()
.onEnded { _ in
print("tap gesture")
isTap.toggle()
}
)
.navigationBarTitleDisplayMode(.inline)
.navigationTitle("Home")
}
}
}
struct SecondView: View {
var body: some View {
Text("SecondView")
}
}
struct ThirdView: View {
var body: some View {
Text("ThirdView")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment