macbackend/Sources/Core/View/ScrollView.swift
david-swift ebd3797d78
All checks were successful
Deploy Docs / publish (push) Successful in 3m56s
SwiftLint / SwiftLint (push) Successful in 4s
Add option to hide the scroll indicators
2025-01-05 13:31:16 +01:00

50 lines
1.3 KiB
Swift

//
// ScrollView.swift
// MacBackend
//
// Created by david-swift on 02.12.2024.
//
import SwiftUI
/// The scroll view widget.
public struct ScrollView: SwiftUIWidget {
/// The axes.
var axes: Set<Axis>
/// The view's content.
var content: Body
/// Whether to hide the scroll indicators.
var hideScrollIndicators = false
/// The wrapped views.
public var wrappedViews: [String: any Meta.AnyView] {
[.mainContent: content]
}
/// Initialize the scroll view.
/// - Parameter content: The content view.
public init(_ axes: Set<Axis> = .vertical, @Meta.ViewBuilder content: () -> Body) {
self.content = content()
self.axes = axes
}
/// Get the SwiftUI view.
/// - Parameter properties: The widget data.
/// - Returns: The SwiftUI view.
public static func view(properties: Self) -> some SwiftUI.View {
SwiftUI.ScrollView(properties.axes.swiftUI) {
MacBackendView(.mainContent)
}
.scrollIndicators(properties.hideScrollIndicators ? .hidden : .automatic)
}
/// Whether to hide the scroll indicators.
/// - Parameter enabled: Whether the scroll indicators are hidden.
/// - Returns: The scroll view.
public func hideScrollIndicators(_ enabled: Bool = true) -> Self {
modify { $0.hideScrollIndicators = enabled }
}
}