@@ -15,6 +15,7 @@ public struct InfiniteCarousel<Content: View, T: Any>: View {
1515 @State private var timer : Timer . TimerPublisher
1616 @State private var cancellable : Cancellable ?
1717 @State private var selectedTab : Int = 1
18+ @State private var isScaleEnabled : Bool = true
1819 private let data : [ T ]
1920 private let seconds : Double
2021 private let content : ( T ) -> Content
@@ -61,7 +62,7 @@ public struct InfiniteCarousel<Content: View, T: Any>: View {
6162 . frame ( maxWidth: . infinity, maxHeight: . infinity)
6263 . rotation3DEffect ( transition == . rotation3D ? getRotation ( positionMinX) : . degrees( 0 ) , axis: ( x: 0 , y: 1 , z: 0 ) )
6364 . opacity ( transition == . opacity ? getValue ( positionMinX) : 1 )
64- . scaleEffect ( transition == . scale ? getValue ( positionMinX) : 1 )
65+ . scaleEffect ( isScaleEnabled && transition == . scale ? getValue ( positionMinX) : 1 )
6566 . padding ( . horizontal, horizontalPadding)
6667 . onChange ( of: positionMinX) { offset in
6768 // If the user change the position of a banner, the offset is different of 0, so we stop the timer
@@ -105,6 +106,10 @@ public struct InfiniteCarousel<Content: View, T: Any>: View {
105106 }
106107 . onAppear {
107108 startTimer ( )
109+ isScaleEnabled = true
110+ }
111+ . onWillDisappear {
112+ isScaleEnabled = false
108113 }
109114 . onReceive ( timer) { _ in
110115 withAnimation {
@@ -160,13 +165,28 @@ public enum TransitionType {
160165 case rotation3D, scale, opacity
161166}
162167
168+ struct TestView : View {
169+ @State private var isActive : Bool = false
170+ var body : some View {
171+ NavigationView {
172+ VStack {
173+ InfiniteCarousel ( data: [ " Element 1 " , " Element 2 " , " Element 3 " , " Element 4 " ] ) { element in
174+ Text ( element)
175+ . font ( . title. bold ( ) )
176+ . padding ( )
177+ . background ( Color . green)
178+ }
179+ NavigationLink ( destination: Text ( " Next screen " ) , isActive: $isActive) {
180+ Button ( " Go to next screen " ) {
181+ isActive = true
182+ }
183+ }
184+ }
185+ }
186+ }
187+ }
163188struct InfiniteCarousel_Previews : PreviewProvider {
164189 static var previews : some View {
165- InfiniteCarousel ( data: [ " Element 1 " , " Element 2 " , " Element 3 " , " Element 4 " ] ) { element in
166- Text ( element)
167- . font ( . title. bold ( ) )
168- . padding ( )
169- . background ( Color . green)
170- }
190+ TestView ( )
171191 }
172192}
0 commit comments