For the following CardView()
, I want the user to tap on it to navigate to the a WebView()
with the link string in post.article_url
.
ForEach(self.posts.reversed(), id: \.id) {post in
GeometryReader{geo -> AnyView in
return AnyView(
CardView (index: self.getPostIndex(post: post),
title: post.title,
image: post.cover_image,
author: post.author,
source: post.source, description: post.description,
imageWidth: self.cardWidth,
imageHeight: self.imageHeight(index: self.getPostIndex(post: post))
)
.animation(.spring())
.frame(width: self.widthAmount(index: self.getPostIndex(post: post)),
height: self.heightAmount(index: self.getPostIndex(post: post)))
.offset(x: self.CardOffsetAmountHorizontal(index: self.getPostIndex(post: post)),
y: self.CardOffsetAmountVertical(index: self.getPostIndex(post: post)))
.onTapGesture{
// navigate to a webview with url: post.article_url
}
)}}
I tried to wrap CardView()
with NavigationLink()
. The navigation is successful, but it turned the image and text on the CardView()
into complete blue. Maybe this can be solved through some other means (such as with some codes in .onTapGuesture{}
)?
Also, as this is a card stack that is supposed to be swiped. The NavigationLink()
also blocks the dragging gesture on these cards.
Thanks in advance!