-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Oguz Yuksel <[email protected]>
- Loading branch information
1 parent
9efc183
commit ab87bcc
Showing
3 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Sources/UIExtensions/Components/SwiftUI/Pure/BindingProvider.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,20 @@ | ||
// Copyright © 2023 Lautsprecher Teufel GmbH. All rights reserved. | ||
|
||
import SwiftUI | ||
|
||
struct BindingProvider<BindedState, Content: View>: View { | ||
@State private var state: BindedState | ||
private var content: (_ binding: Binding<BindedState>) -> Content | ||
|
||
init( | ||
_ initialState: BindedState, | ||
@ViewBuilder content: @escaping (_ binding: Binding<BindedState>) -> Content | ||
) { | ||
self.content = content | ||
self._state = State(initialValue: initialState) | ||
} | ||
|
||
var body: some View { | ||
content($state) | ||
} | ||
} |
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,33 @@ | ||
// Copyright © 2023 Lautsprecher Teufel GmbH. All rights reserved. | ||
|
||
import SwiftUI | ||
|
||
#if DEBUG | ||
extension PreviewProvider { | ||
@ViewBuilder | ||
public static func withBinding<BindedState, Content: View>( | ||
_ initialState: BindedState, | ||
@ViewBuilder content: @escaping (_ binding: Binding<BindedState>) -> Content | ||
) -> some View { | ||
BindingProvider(initialState, content: content) | ||
} | ||
|
||
@ViewBuilder | ||
public static func withPreviewDevices<Content: View>( | ||
_ deviceNames: [String]? = nil, | ||
@ViewBuilder content: @escaping () -> Content | ||
) -> some View { | ||
if let deviceNames { PreviewHelper(deviceNames, content: content) } | ||
else { PreviewHelper(content: content) } | ||
} | ||
|
||
@ViewBuilder | ||
public static func withPreviewDevices<Content: View>( | ||
_ deviceNames: [String]? = nil, | ||
@ViewBuilder content: @escaping (String) -> Content | ||
) -> some View { | ||
if let deviceNames { PreviewHelper(deviceNames, content: content) } | ||
else { PreviewHelper(content: content) } | ||
} | ||
} | ||
#endif |
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