Last active
          May 20, 2025 08:43 
        
      - 
      
 - 
        
Save bobergj/12ae71bb374c45ed810b102ed34eaee7 to your computer and use it in GitHub Desktop.  
    CarouselView
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import AnySubviews | |
| public import SwiftUI | |
| public struct CarouselView<Content: View>: View { | |
| let content: Content | |
| public init(@ViewBuilder content: () -> Content) { | |
| self.content = content() | |
| } | |
| public var body: some View { | |
| ScrollView(.horizontal) { | |
| LazyHStack(spacing: 8) { | |
| BackportGroup(subviews: content) { subviews in | |
| ForEach(subviews) { subview in | |
| subview | |
| .containerRelativeFrame(.horizontal) | |
| .scrollTransition { content, phase in | |
| content | |
| .scaleEffect(y: phase.isIdentity ? 1 : 0.95) | |
| } | |
| } | |
| } | |
| } | |
| .scrollTargetLayout() | |
| } | |
| .scrollTargetBehavior(.viewAligned(limitBehavior: .always)) | |
| .scrollClipDisabled(true) | |
| .scrollIndicators(.hidden) | |
| .shadow(color: Color(white: 0.0, opacity: 0.3), radius: 20.0, x: 0.0, y: 0.0) | |
| .frame(height: 200) | |
| } | |
| } | |
| #Preview { | |
| CarouselView { | |
| Color.red | |
| Color.green | |
| Color.yellow | |
| Color.blue | |
| } | |
| .contentMargins(.horizontal, 16, for: .scrollContent) | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment