JWAutumn / ACarousel

A carousel view for SwiftUI | SwiftUI 旋转木马效果
MIT License
406 stars 81 forks source link

Enable client to set a custom animation type. #32

Open swipip opened 10 months ago

swipip commented 10 months ago

Summary

As a client of the SDK I need to be able to set a custom animation type.

The animation currently defaults to spring() which takes a bit to long to complete. I added to possibility to override the default behavior with a Animation injected through a closure.

Technical decisions

Animation is injected through a closure allowing the client to perform run time logic. Animation closure is optional in initializer so the changes would not be breaking for existing clients. Current default behavior is maintained.

Call site exemple

            ACarousel(roles,
                      id: \.self,
                      index: $currentIndex,
                      spacing: spacing,
                      headspace: headspace,
                      sidesScaling: sidesScaling,
                      isWrap: isWrap,
                      autoScroll: autoScroll ? .active(time) : .inactive) { name in
                Image(name)
                    .resizable()
                    .scaledToFill()
                    .frame(height: 300)
                    .cornerRadius(30)
            } animation: {
                .easeInOut(duration: 0.3)
            }