From 655cc826d18a558ac893a5441070b5b1e97b9530 Mon Sep 17 00:00:00 2001 From: Abe White Date: Sat, 22 Feb 2025 22:08:35 -0600 Subject: [PATCH] Add view aligned to scroll view playground --- .../Showcase/Resources/Localizable.xcstrings | 3 ++ Sources/Showcase/ScrollViewPlayground.swift | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Sources/Showcase/Resources/Localizable.xcstrings b/Sources/Showcase/Resources/Localizable.xcstrings index a6dff42..5266eed 100644 --- a/Sources/Showcase/Resources/Localizable.xcstrings +++ b/Sources/Showcase/Resources/Localizable.xcstrings @@ -2089,6 +2089,9 @@ }, "Repository item tap count: %lld" : { + }, + "Requires iOS 17+" : { + }, "RGB" : { diff --git a/Sources/Showcase/ScrollViewPlayground.swift b/Sources/Showcase/ScrollViewPlayground.swift index 7c4675f..6d7053f 100644 --- a/Sources/Showcase/ScrollViewPlayground.swift +++ b/Sources/Showcase/ScrollViewPlayground.swift @@ -8,6 +8,7 @@ import SwiftUI enum ScrollViewPlaygroundType: String, CaseIterable { case vertical case horizontal + case viewAligned case readerLazyVStack case readerLazyHStack case readerList @@ -21,6 +22,8 @@ enum ScrollViewPlaygroundType: String, CaseIterable { return "Vertical" case .horizontal: return "Horizontal" + case .viewAligned: + return ".viewAligned" case .readerLazyVStack: return "ScrollViewReader: LazyVStack" case .readerLazyHStack: @@ -53,6 +56,9 @@ struct ScrollViewPlayground: View { case .horizontal: HorizontalScrollViewPlayground() .navigationTitle($0.title) + case .viewAligned: + ViewAlignedScrollViewPlayground() + .navigationTitle($0.title) case .readerLazyVStack: ScrollViewReaderLazyVStackPlayground() .navigationTitle($0.title) @@ -105,6 +111,28 @@ private struct HorizontalScrollViewPlayground: View { } } +private struct ViewAlignedScrollViewPlayground: View { + var body: some View { + if #available(iOS 17, *) { + ScrollView(.horizontal) { + LazyHStack { + ForEach(0..<20) { i in + ZStack { + Color.yellow + Text(String(describing: i)) + } + .frame(width: 80, height: 80) + } + } + .scrollTargetLayout() + } + .scrollTargetBehavior(.viewAligned) + } else { + Text("Requires iOS 17+") + } + } +} + private struct ScrollViewReaderLazyVStackPlayground: View { var body: some View { ScrollViewReader { proxy in