-
-
Save MainasuK/9584882163161d3a77d7236929251987 to your computer and use it in GitHub Desktop.
Generic structures to host previews of UIView and UIViewController subclasses. Also NSView and NSViewController
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
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
struct <#NSView#>_Preview: PreviewProvider { | |
static var previews: some View { | |
NSViewPreview { | |
<#Code#> | |
} | |
} | |
} | |
#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
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
struct <#NSViewController#>_Preview: PreviewProvider { | |
static var previews: some View { | |
NSViewControllerPreview { | |
<#Code#> | |
} | |
} | |
} | |
#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
import Cocoa | |
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
struct NSViewControllerPreview<ViewController: NSViewController>: NSViewControllerRepresentable { | |
let viewController: ViewController | |
init(_ builder: @escaping () -> ViewController) { | |
viewController = builder() | |
} | |
// MARK: - NSViewControllerRepresentable | |
func makeNSViewController(context: Context) -> ViewController { | |
return viewController | |
} | |
func updateNSViewController(_ viewController: ViewController, context: Context) { | |
} | |
} | |
#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
import Cocoa | |
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
struct NSViewPreview<View: NSView>: NSViewRepresentable { | |
let view: View | |
init(_ builder: @escaping () -> View) { | |
view = builder() | |
} | |
// MARK: - NSViewRepresentable | |
func makeNSView(context: Context) -> View { | |
return view | |
} | |
func updateNSView(_ view: View, context: Context) { | |
view.setContentHuggingPriority(.defaultHigh, for: .horizontal) | |
view.setContentHuggingPriority(.defaultHigh, for: .vertical) | |
} | |
} | |
#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
#if DEBUG | |
import SwiftUI | |
struct <#UIView#>_Preview: PreviewProvider { | |
static var previews: some View { | |
UIViewPreview { | |
<#Code#> | |
} | |
} | |
} | |
#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
#if DEBUG | |
import SwiftUI | |
struct <#UIViewController#>_Preview: PreviewProvider { | |
static var previews: some View { | |
UIViewControllerPreview { | |
<#Code#> | |
} | |
} | |
} | |
#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
import UIKit | |
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable { | |
let viewController: ViewController | |
init(_ builder: @escaping () -> ViewController) { | |
viewController = builder() | |
} | |
// MARK: - UIViewControllerRepresentable | |
func makeUIViewController(context: Context) -> ViewController { | |
return viewController | |
} | |
func updateUIViewController(_ viewController: ViewController, context: Context) { | |
return | |
} | |
} | |
#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
import UIKit | |
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
struct UIViewPreview<View: UIView>: UIViewRepresentable { | |
let view: View | |
init(_ builder: @escaping () -> View) { | |
view = builder() | |
} | |
// MARK: - UIViewRepresentable | |
func makeUIView(context: Context) -> UIView { | |
return view | |
} | |
func updateUIView(_ view: UIView, context: Context) { | |
view.setContentHuggingPriority(.defaultHigh, for: .horizontal) | |
view.setContentHuggingPriority(.defaultHigh, for: .vertical) | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment