Thank you for the amazing work! I wonder if there is a way to scroll the VStack when expanded in case there are too many items. I tried wrapping it in scroll view but the transition from ZStack to VStack doesn't look good
@KavsoftАй бұрын
You can definitely change its behaviour to adapt into a scroll view, just make the following changes to the code, 1. Create a State variable called “height”, @State private var height: CGFloat = .zero 2. Now Wrap the layout { … } into a ScrollView, ScrollView(.vertical) { layout { … } } 3. Remove the onTapGesture from both the background and the layout instance. 4. Add the following lines of code in the respective places, a. Add these lines to the ScrollView, ScrollView { … } .rotationEffect(.init(degrees: 180)) .frame(height: isExpanded ? nil : height == 0 ? nil : height) .scrollClipDisabled() .scrollIndicators(.hidden) .scrollDisabled(!isExpanded) .allowsHitTesting(!toasts.isEmpty) .onTapGesture { isExpanded.toggle() } b. Add these lines to the layout (Inside the ScrollView), ScrollView(.vertical) { layout { … } .rotationEffect(.init(degrees: -180)) .onGeometryChange(for: CGFloat.self) { $0.size.height } action: { newValue in height = newValue } } 5. Modify the DragGesture() to the following, DragGesture(minimumDistance: 30, coordinateSpace: .global) Also modify the xOffset to the following, let xOffset = value.translation.width < 0 ? value.translation.width + 20 : 0 6. Finally change all the instances of the bouncy animation to .snappy(duration: 0.3, extraBounce: 0) animation, since bouncy animation will have some bounce glitches with the scrollviews. By doing these steps, you can convert the toasts VStack into a ScrollView. Have a great day!
@user32352Ай бұрын
does this work on the root level or only the screen you are on? if toast pops up and you navigate to a new page is it still visible?
@nitinbhatia493Ай бұрын
same question I have too
@KavsoftАй бұрын
Nope, this is more like per view context basis. Each view will have its separate toasts, but I do have a video that will create universal toasts and display at the top of the SwiftUI app. For more, check this video out, kzbin.info/www/bejne/mGeph4KOj7lridE
@KavsoftАй бұрын
Additionally, I got many people asking this, so I will try to add a new version of code in my Patreon that will work like a universal toast!
@KavsoftАй бұрын
I added a version that will work as a universal toast also with enabled scroll actions; check out the code in the patreon (link in the description).
@nitinbhatia493Ай бұрын
❤ that so fast, will launch a video for that too ?
@luunguyen8295Ай бұрын
How about the case when there're many toasts in VStackLayout and we need a ScrollView for it, can you help me build it?
@KavsoftАй бұрын
You can definitely change its behaviour to adapt into a scroll view, just make the following changes to the code, 1. Create a State variable called “height”, @State private var height: CGFloat = .zero 2. Now Wrap the layout { … } into a ScrollView, ScrollView(.vertical) { layout { … } } 3. Remove the onTapGesture from both the background and the layout instance. 4. Add the following lines of code in the respective places, a. Add these lines to the ScrollView, ScrollView { … } .rotationEffect(.init(degrees: 180)) .frame(height: isExpanded ? nil : height == 0 ? nil : height) .scrollClipDisabled() .scrollIndicators(.hidden) .scrollDisabled(!isExpanded) .allowsHitTesting(!toasts.isEmpty) .onTapGesture { isExpanded.toggle() } b. Add these lines to the layout (Inside the ScrollView), ScrollView(.vertical) { layout { … } .rotationEffect(.init(degrees: -180)) .onGeometryChange(for: CGFloat.self) { $0.size.height } action: { newValue in height = newValue } } 5. Modify the DragGesture() to the following, DragGesture(minimumDistance: 30, coordinateSpace: .global) Also modify the xOffset to the following, let xOffset = value.translation.width < 0 ? value.translation.width + 20 : 0 6. Finally change all the instances of the bouncy animation to .snappy(duration: 0.3, extraBounce: 0) animation, since bouncy animation will have some bounce glitches with the scrollviews. By doing these steps, you can convert the toasts VStack into a ScrollView. Have a great day!
@danielcrompton7818Ай бұрын
Please explain the asymmetric transition at 7:36
@KavsoftАй бұрын
It means that the view transitions will have two transitions, one for insertion and one for removal. For example, I can use this to push the view from the top when it’s inserted and slide it in the leading side when it’s removed.