-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Horizontal ScrollViews
- Loading branch information
Showing
6 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// InfiniteAxis.swift | ||
// InfiniteScrollView | ||
// | ||
// Created by Brian Moyou on 12.10.24. | ||
// | ||
|
||
/** | ||
`InfiniteAxis` represents the possible Axes for either a VStack or an HStack | ||
- `horizontal`: Horizontal Axis | ||
- `vertical`: Vertical Axis | ||
*/ | ||
public enum InfiniteAxis { | ||
case horizontal, vertical | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// LazyVHStack.swift | ||
// InfiniteScrollView | ||
// | ||
// Created by Brian Moyou on 12.10.24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@available(macOS 12.0, *) | ||
public struct LazyVHStack<Content: View>: View { | ||
let axis: Axis | ||
let spacing: CGFloat | ||
@ViewBuilder let content: () -> Content | ||
|
||
public var body: some View { | ||
Group { | ||
switch axis { | ||
case .vertical: | ||
LazyVStack(spacing: spacing) { | ||
content() | ||
} | ||
case .horizontal: | ||
LazyHStack(spacing: spacing) { | ||
content() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// VHScrollView.swift | ||
// InfiniteScrollView | ||
// | ||
// Created by Brian Moyou on 12.10.24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@available(macOS 12.0, *) | ||
public struct VHScrollView<Content: View>: View { | ||
var axis: Axis = .vertical | ||
var refresh: () async -> () = {} | ||
@ViewBuilder let content: () -> Content | ||
|
||
public var body: some View { | ||
Group { | ||
switch axis { | ||
case .vertical: | ||
ScrollView { | ||
content() | ||
} | ||
.refreshable { | ||
try? await Task.sleep(nanoseconds: 500_000_000) | ||
await refresh() | ||
} | ||
case .horizontal: | ||
ScrollView(.horizontal) { | ||
content() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// VHStack.swift | ||
// InfiniteScrollView | ||
// | ||
// Created by Brian Moyou on 12.10.24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@available(macOS 12.0, *) | ||
public struct VHStack<Content: View>: View { | ||
var axis: Axis = .vertical | ||
@ViewBuilder let content: () -> Content | ||
|
||
public var body: some View { | ||
Group { | ||
switch axis { | ||
case .vertical: | ||
VStack { | ||
content() | ||
} | ||
case .horizontal: | ||
HStack { | ||
content() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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