forked from lucaszischka/BottomSheet
-
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.
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 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
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
22 changes: 22 additions & 0 deletions
22
Sources/BottomSheet/Helper/Extensions/ConditionalViewExtension.swift
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,22 @@ | ||
// | ||
// ConditionalViewModifier.swift | ||
// | ||
// Created by GrandSir on 10.03.2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension View { | ||
/// Applies the given transform if the given condition evaluates to `true`. | ||
/// - Parameters: | ||
/// - condition: The condition to evaluate. | ||
/// - transform: The transform to apply to the source `View`. | ||
/// - Returns: Either the original `View` or the modified `View` if the condition is `true`. | ||
@ViewBuilder func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View { | ||
if condition { | ||
transform(self) | ||
} else { | ||
self | ||
} | ||
} | ||
} |
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