Skip to content

Commit

Permalink
Add missing doc for kit
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Oct 25, 2024
1 parent 826ee22 commit 7bc0623
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 46 deletions.
6 changes: 3 additions & 3 deletions Sources/SplitViewKit/SplitViewWrapper+Const.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import SwiftUI
extension SplitViewWrapper {
/**
* Alias for a closure that returns a "Sidebar view"
* - Fixme: ⚠️️ add description
* - Description: Defines a closure type for creating a sidebar view, which is dynamically configured based on the provided `SplitConfig` and `sizeClass`.
*/
public typealias SideBarAlias = (_ splitConfig: SplitConfig, _ sizeClass: Binding<UserInterfaceSizeClass?>) -> SideBar
/**
* Alias for a closure that returns a "Content view" (aka Main view) with a toggleColumn binding.
* - Fixme: ⚠️️ add description
* - Description: Defines a closure type for creating a main content view, dynamically configured based on the provided `SplitConfig` and `sizeClass`.
* - Note: We inject the bidning so it can be controlled by a button
* - Note: alternative name: `MainColumnAlias`
*/
Expand All @@ -25,7 +25,7 @@ extension SplitViewWrapper {
*/
public typealias DetailAlias = (_ splitConfig: SplitConfig, _ sizeClass: Binding<UserInterfaceSizeClass?>) -> Detail
/**
* - Fixme: ⚠️️ add description
* - Description: Defines a closure type for creating an "Overlay view" which can be conditionally displayed over the main content based on the provided `SplitConfig` and `sizeClass`.
* - Note: suitable for debugging or floating UI that can change the splitview UI, since we get the splitview bindings etc
*/
public typealias OverlayAlias = (_ splitConfig: SplitConfig, _ sizeClass: Binding<UserInterfaceSizeClass?>) -> OverlayView?
Expand Down
18 changes: 9 additions & 9 deletions Sources/SplitViewKit/SplitViewWrapper+Content.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ extension SplitViewWrapper {
* - Fixme: ⚠️️ Maybe toggle on OS. macOS doesn't need geomreader, skip using it in that case etc? i guess leave it for now. This is only relevant for iOS / iPad, so we could skip the geomreader for macos
*/
var splitViewContainer: some View {
GeometryReader { geometry in // - Fixme: ⚠️️ doc this line
navigationSplitView(geometry.size.width) // - Fixme: ⚠️️ doc this line
GeometryReader { geometry in // Utilizes GeometryReader to dynamically obtain the current view size
navigationSplitView(geometry.size.width) // Passes the current width to the navigationSplitView function
.id(refreshID) // Used to refresh view when sizeClass change, and winSize change
.onChange(of: geometry.size) { oldSize, newSize in // - Fixme: ⚠️️ Add doc
.onChange(of: geometry.size) { oldSize, newSize in // Triggers a view refresh when the geometry size changes
if sizeClass == .regular && oldSize != newSize { // ⚠️️ Only repaint view if size has actually changed, avoids infinite loop etc, we only need this in regular mode, it causes issues with popup sheet in compact mode
refreshID = UUID() // Re-generates view
}
Expand All @@ -54,14 +54,14 @@ extension SplitViewWrapper {
columnVisibility: $splitConfig.columnVisibility, // Binding to control column arrangement
preferredCompactColumn: $splitConfig.preferredCompactColumn // Binding to set the preferred visible column in compact mode
) {
sideBar(splitConfig, sizeClass.reBind) // - Fixme: ⚠️️ Doc this line
.sideBarViewModifier(winWidth: winWidth, columnWidth: columnWidth) // - Fixme: ⚠️️ Doc this line, use copilot
sideBar(splitConfig, sizeClass.reBind) // Provides the sidebar view, binding the split configuration and size class for dynamic updates.
.sideBarViewModifier(winWidth: winWidth, columnWidth: columnWidth) // Applies visual modifications to the sidebar based on window width and column width settings.
} content: {
content(splitConfig, sizeClass.reBind) // - Fixme: ⚠️️ Doc this line
.mainViewModifier(winWidth: winWidth, columnWidth: columnWidth) // - Fixme: ⚠️️ Doc this line, use copilot
content(splitConfig, sizeClass.reBind) // Displays the main content view, with bindings for split configuration and size class for responsiveness.
.mainViewModifier(winWidth: winWidth, columnWidth: columnWidth) // Modifies the main view's appearance based on the current window width and predefined column widths.
} detail: {
detail(splitConfig, sizeClass.reBind) // - Fixme: ⚠️️ Doc this line
.detailViewModifier(winWidth: winWidth, columnWidth: columnWidth) // - Fixme: ⚠️️ Doc this line, use copilot
detail(splitConfig, sizeClass.reBind) // Renders the detail view, using bindings to adapt to changes in split configuration and size class.
.detailViewModifier(winWidth: winWidth, columnWidth: columnWidth) // Adjusts the detail view's layout and styling based on window width and column width.
}
.navigationSplitViewStyle(.balanced)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SplitViewKit/ext/UIDeviceOrientation+Ext.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import SwiftUI
/**
* Determines if the device is in a landscape orientation.
* - Description: This variable checks if the current device orientation is landscape.
* - Note: On macOS, it always returns true as macOS windows are typically considered landscape.
* - Note: The variable name is rather long so doesn't conflict with implementer API etc
* - Note: This can't be in the `UIDeviceOrientation` scope. Because it only exists for iOS. So we put it in the global scope
* - Fixme: ⚠️️ add description
* - Returns: A Boolean value indicating whether the device orientation is landscape.
*/
public var isOrientationLandscape: Bool {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SplitViewKit/ext/UserInterfaceSizeClass+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SwiftUI
extension Optional where Wrapped == UserInterfaceSizeClass {
/**
* Convenient rebinder (Environtment -> Binding)
* - Fixme: ⚠️️ Add description
* - Description: Provides a binding to the optional `UserInterfaceSizeClass` to facilitate the propagation of size class changes through the view hierarchy.
* - Note: We rebind sizeClass because environment variables Because you have to apply envirotnment variables to views that are regenerated down the hirarchy. So param drilling is easier to understand etc. less abstract. We removed environmentObject and now do param drill instead, param-drill the sizeClass and splitConfig, environment variables is confusing if its not passed correctly, it can jump to compact in the wrong scope where it should be regular etc, and doesnt attach if views are replaced, like detailview etc. sizeClass needs to be a binding or else UI doesn't react on changes
* - Note: It seem very tricky to make horizontalSizeClass a two way binding. @Bindable seems to be the best way. But it doesnt work on this environment variable for some reason. There could be a way. update when discovered. for now. we sync on onChange. I think the reason is that this environmental value isnt easily settable in the same scope. Might be a way with more research etc
*/
Expand All @@ -19,7 +19,7 @@ extension Optional where Wrapped == UserInterfaceSizeClass {
*/
extension UserInterfaceSizeClass {
/**
* - Fixme: ⚠️️ Add description
* - Description: Determines if the device is in a landscape mode where the window occupies approximately 70% of the screen width, typically used for adaptive layouts in larger devices like iPads.
* - Note: The way we can detect landscape_70_percentage_mode is if: sizeClass == .regular && orientation == .landscape && winWidth < appWidth
* - Note: if 70% mode. use double or adjust column sizes. get is70percentage bool to work etc
* - Parameter winWidth: The width of the window in points.
Expand Down
9 changes: 5 additions & 4 deletions Sources/SplitViewKit/modifier/DetailViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ struct DetailViewModifier: ViewModifier {
*/
let winWidth: CGFloat
/**
* - Fixme: ⚠️️ add description
* The `ColumnWidthKind` protocol instance that provides custom width settings for the detail column based on the window width.
*/
let columnWidth: ColumnWidthKind
/**
* Body
* - Fixme: ⚠️️ add description
* - Description: This function modifies the view by applying a custom width to the detail column of the navigation split view based on the window width. It uses the `ColumnWidthKind` protocol to determine the appropriate widths.
*/
* - Note: There is also: `navigationSplitViewColumnWidth`
*/
func body(content: Content) -> some View {
Expand All @@ -35,10 +36,10 @@ struct DetailViewModifier: ViewModifier {
extension View {
/**
* Convenient
* - Fixme: ⚠️️ add description
* - Description: This method applies a detail view modifier that adjusts the detail column's width according to the window width using the provided `ColumnWidthKind` instance.
* - Parameters:
* - winWidth: The width of the window in which the detail view is displayed.
* - columnWidth: - Fixme: ⚠️️ add doc
* - columnWidth: An instance conforming to the `ColumnWidthKind` protocol, which provides custom width settings for the detail column based on the window width.
* - Returns: A View with the detail view modifier applied.
*/
internal func detailViewModifier(winWidth: CGFloat, columnWidth: ColumnWidthKind) -> some View{
Expand Down
8 changes: 4 additions & 4 deletions Sources/SplitViewKit/modifier/MainViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ fileprivate struct MainViewModifier: ViewModifier {
*/
let winWidth: CGFloat
/**
* - Fixme: ⚠️️ Add description
* - Description: The `ColumnWidthKind` protocol instance that provides custom width settings for the main column based on the window width.
*/
let columnWidth: ColumnWidthKind
/**
* Body
* - Fixme: ⚠️️ Add description
* - Description: This function modifies the view by applying a custom width to the main column of the navigation split view based on the window width. It uses the `ColumnWidthKind` protocol to determine the appropriate widths.
*/
func body(content: Content) -> some View {
if let columnWidth = columnWidth.mainColumn(winWidth: winWidth) {
Expand All @@ -35,10 +35,10 @@ fileprivate struct MainViewModifier: ViewModifier {
extension View {
/**
* Convenient
* - Fixme: ⚠️️ add description
* - Description: This method applies a main view modifier that adjusts the main column's width according to the window width using the provided `ColumnWidthKind` instance.
* - Parameters:
* - winWidth: The width of the window.
* - columnWidth: - Fixme: ⚠️️ add doc
* - columnWidth: An instance conforming to the `ColumnWidthKind` protocol, which provides custom width settings for the main column based on the window width.
* - Returns: A View with the main view modifier applied.
*/
internal func mainViewModifier(winWidth: CGFloat, columnWidth: any ColumnWidthKind) -> some View {
Expand Down
8 changes: 4 additions & 4 deletions Sources/SplitViewKit/modifier/SideBarViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import SwiftUI
/**
* SideBarViewModifier
* - Abstract. We apply columnwidth to the column with this modifier
* - Fixme: ⚠️️ add description
* - Description: This modifier is used to apply custom width settings to the sidebar of a navigation split view based on the window width.
*/
fileprivate struct SideBarViewModifier: ViewModifier {
/**
* - Description: The width of the window
*/
let winWidth: CGFloat
/**
* - Fixme: ⚠️️ add description
* - Description: The `ColumnWidthKind` protocol instance that provides custom width settings for the sidebar based on the window width.
*/
let columnWidth: ColumnWidthKind
/**
Expand All @@ -37,10 +37,10 @@ fileprivate struct SideBarViewModifier: ViewModifier {
extension View {
/**
* Applies the SideBarViewModifier to the view.
* - Fixme: ⚠️️ add description
* - Description: This method applies a sidebar view modifier that adjusts the sidebar's width according to the window width using the provided `ColumnWidthKind` instance.
* - Parameters:
* - winWidth: The width of the window in which the sidebar view is displayed.
* - columnWidth: - Fixme: ⚠️️ add doc
* - columnWidth: An instance conforming to the `ColumnWidthKind` protocol, which provides custom width settings for the sidebar based on the window width.
* - Returns: A View with the sidebar view modifier applied.
*/
internal func sideBarViewModifier(winWidth: CGFloat, columnWidth: ColumnWidthKind) -> some View {
Expand Down
8 changes: 4 additions & 4 deletions Sources/SplitViewKit/util/ColumnWidth/ColumnWidth.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI
/**
* - Fixme: ⚠️️ Add description
* - Description: This file defines the `ColumnWidth` struct which is used to specify the minimum, ideal, and maximum widths for columns within a `NavigationSplitView`. This allows for flexible and adaptive UI layouts across different devices and orientations.
* - Important: ⚠️️ To resize columns when the app is running, you have to force reload the navigationsplitview view. Refreshing the state is not enough. The best way is to toggle two navsplitviews in a geometryreader.
* - Note: Here is how we can easily persist columnWidths with userdefault: https://github.com/stevengharris/SplitView#using-userdefaults-for-split-state
* - Note: Only some platforms enable resizing columns. If you specify a width that the current presentation environment doesn’t support, SwiftUI may use a different width for your column.
Expand Down Expand Up @@ -28,9 +28,9 @@ public struct ColumnWidth {
public let max: CGFloat?
/**
* - Parameters:
* - min: - Fixme: ⚠️️ add doc
* - ideal: - Fixme: ⚠️️ add doc
* - max: - Fixme: ⚠️️ add doc
* - min: The minimum width of the column. If nil, the column width is not constrained on the lower end.
* - ideal: The recommended width of the column. This width is used when possible within the constraints of the minimum and maximum widths.
* - max: The maximum width of the column. If nil, the column width is not constrained on the upper end.
*/
public init(min: CGFloat?, ideal: CGFloat, max: CGFloat?) {
self.min = min
Expand Down
21 changes: 11 additions & 10 deletions Sources/SplitViewKit/util/ColumnWidth/ColumnWidthKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ import UIKit
/**
* Extend this to customize column widths
* - Note: Kind must implement these calls
* - Fixme: ⚠️️ add description
* - Description: Defines a protocol for customizing the widths of columns in a split view layout. Implement this protocol to specify different widths for sidebar, main, and detail columns based on the window width.
*/
public protocol ColumnWidthKind {
/**
* - Fixme: ⚠️️ add description
* - Parameter winWidth: - Fixme: ⚠️️ add doc
* - Returns: - Fixme: ⚠️️ add doc
* - Description: Specifies the width for the sidebar column based on the given window width.
* - Parameter winWidth: The width of the window which is used to determine the appropriate column width.
* - Returns: An optional `ColumnWidth` object specifying the width of the sidebar column. If nil, the default width is used.
*/
func sideBarColumn(winWidth: CGFloat) -> ColumnWidth?
/**
* - Fixme: ⚠️️ add description
* - Parameter winWidth: - Fixme: ⚠️️ add doc
* - Returns: - Fixme: ⚠️️ add doc
* Specifies the width for the main content column based on the given window width.
* - Parameter winWidth: The width of the window which is used to determine the appropriate column width for the main content area.
* - Returns: An optional `ColumnWidth` object specifying the width of the main content column. If nil, the default width is used.
*/
func mainColumn(winWidth: CGFloat) -> ColumnWidth?

/**
* - Fixme: ⚠️️ add description
* - Parameter winWidth: - Fixme: ⚠️️ add doc
* - Returns: - Fixme: ⚠️️ add doc
* Specifies the width for the detail column based on the given window width.
* - Parameter winWidth: The width of the window which is used to determine the appropriate column width for the detail area.
* - Returns: An optional `ColumnWidth` object specifying the width of the detail column. If nil, the default width is used.
*/
func detailColumn(winWidth: CGFloat) -> ColumnWidth?
}
Expand Down
9 changes: 4 additions & 5 deletions Sources/SplitViewKit/util/SplitConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class SplitConfig: ObservableObject {
* - Description: This property determines the visibility of columns in the `NavigationSplitView` based on the current device and orientation. It adjusts between all columns visible, double column, or detail only views.
* - Note: Required init for publc classes
* - Parameters:
* - columnVisibility: - Fixme: ⚠️️ add doc
* - preferredCompactColumn: - Fixme: ⚠️️ add doc
* - columnVisibility: Specifies the visibility of columns in the NavigationSplitView. It can be set to .all, .doubleColumn, or .singleColumn to control the number of visible columns based on the device's orientation and size.
* - preferredCompactColumn: Determines the primary visible column in compact mode. Options include .sidebar, .content, or .detail, allowing explicit control over which column is displayed in a compact environment.
*/
public init(columnVisibility: NavigationSplitViewVisibility = .all, preferredCompactColumn: NavigationSplitViewColumn = .content) {
self.columnVisibility = columnVisibility
Expand All @@ -41,10 +41,9 @@ extension SplitConfig {
/**
* - Description: Determines if the sidebar is currently visible based on the column visibility and size class.
* - Fixme: ⚠️️ Document in which scenario this is used etc
* - Fixme: ⚠️️ Rename to to something else?
* - Fixme: ⚠️️ This is also true if 1 col + preferredCompactColumn == .sidebar I think
* - Parameter sizeClass: - Fixme: ⚠️️ add doc
* - Returns: - Fixme: ⚠️️ add doc
* - Parameter sizeClass: The current horizontal size class of the user interface, which determines the layout and visibility of the sidebar.
* - Returns: A Boolean value indicating whether the sidebar is visible based on the current `columnVisibility` and `sizeClass`.
*/
public func isShowingSideBar(sizeClass: UserInterfaceSizeClass?) -> Bool {
let isShowingSideBar = (columnVisibility == .all && sizeClass == .regular) || (preferredCompactColumn == .sidebar && sizeClass == .compact)
Expand Down

0 comments on commit 7bc0623

Please sign in to comment.