In swiftui, I’ve horizontal scrollview which has one hstack containing three totally different view however the 2nd view has variable top, when the consumer clicks on this view, I’m toggling two variables specifically
showExchangeRates.toggle()
showExpand.toggle()
I’m additionally having these modifier on the finish of the horizontal scroll view to offer every view the mimic of swipable view, as every of the view is taking full display screen width so the second view solely seems after consumer swipes from proper to left
.contentMargins(.horizontal, 8, for: .scrollContent)
.scrollTargetBehavior(.paging)
so when the consumer is on second view and the body top of 2nd view is expanded by clicking on it, now when the consumer goes again to the primary view(with out clicking once more on the second view to get it again to its regular top), the primary view is taking an excessive amount of top as a result of most likely the 2nd view modified the peak of the entire hstack which all views are in. I’ve tried togging these variables utilizing onappear and on disappear on each first and the second view however that is not working most likely as a result of SwiftUI is contemplating all of the three view inside the Hstack as appeared or perhaps I do not know the explanation behind it.
VStack {
Textual content("This")
ScrollView(.horizontal) {
HStack {
// Begin of Forex Price Card
swipeTotalMarket()
cryptoTab()
metalRates()
}//HStack
.scrollTargetLayout()
//
}//scrollview(horizontal) Card Group 2
.contentMargins(.horizontal, 8, for: .scrollContent)
.scrollTargetBehavior(.paging)
Textual content("That")
}
I’ve tried utilizing the draggesture in swiftui to toggle the variables when it senses a swipe form of behavious,
.gesture(
DragGesture(minimumDistance: percentWidth(p.c: 1.3), coordinateSpace: .native)
.onChanged { worth in
if worth.translation.width > 14 { // Verify if the swipe is from left to proper
showExchangeRates = false
showExpand = false
}}
)
it does work however just isn’t constant and never one of the best resolution.
PS: The HStack is important in a horizontal scrollview on this case.