Skip to content

Commit

Permalink
feat: adds new conditional renderer for specific OS
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhermawan committed Dec 3, 2023
1 parent 25965c4 commit f1ade66
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Sources/ViewCondition/ViewCondition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SwiftUI
///
/// Methods:
/// - `if(_:content:)`: Applies a modifier to the view based on a condition.
/// - `if(os:content:)`: Applies a modifier to the view based on the operating system.
/// - `visible(if:removeCompletely:)`: Conditionally shows or hides the view based on a Boolean condition.
/// - `visible(on:)`: Conditionally shows or hides the view based on the operating system.
/// - `hide(if:removeCompletely:)`: Conditionally hides or removes the view based on a Boolean condition.
Expand All @@ -39,6 +40,24 @@ public extension View {
}
}

/// Applies a modifier to the view based on the operating system.
///
/// This method allows for conditional modification of a view based on the operating system. It internally
/// utilizes `if(_:content:)` to apply the modification.
///
/// - Parameters:
/// - os: The operating system to check against.
/// - content: A closure that modifies the view.
/// - Returns: A modified view for the specified OS; otherwise, the original view.
@ViewBuilder
func `if`<Content: View>(os: OperatingSystem, content: (Self) -> Content) -> some View {
#if os(iOS)
self.if(os == .iOS, content: content)
#elseif os(macOS)
self.if(os == .macOS, content: content)
#endif
}

/// Controls the view's visibility, with an option to remove it when not visible.
///
/// This method conditionally displays the view. If the `condition` is false,
Expand Down

0 comments on commit f1ade66

Please sign in to comment.