Skip to content

Commit

Permalink
feat: add new SwiftIU preview struct
Browse files Browse the repository at this point in the history
  • Loading branch information
gtokman committed May 3, 2021
1 parent a37670d commit 160f3ef
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Sources/ExtensionKit/SwiftUI/Preview.swift
@@ -0,0 +1,30 @@
import SwiftUI

/// Preview content on iPhone 12 pro in light mode, iPhone 12 mini in dark mode
public struct Preview<Content: View>: View {
let content: Content

/// Create a preview for iPhone 12 pro and iPhone 12 mini
/// - Parameter content: Content
public init(@ViewBuilder _ content: () -> Content) {
self.content = content()
}

public var body: some View {
Group {
self.content
.environment(\.colorScheme, .light)
.preferredColorScheme(.light)
.navigationBarHidden(true)
.previewDevice("iPhone 12 Pro")
.previewDisplayName("Pro, light mode")

self.content
.environment(\.colorScheme, .dark)
.preferredColorScheme(.dark)
.navigationBarHidden(true)
.previewDevice("iPhone 12 mini")
.previewDisplayName("Mini, dark mode")
}
}
}

0 comments on commit 160f3ef

Please sign in to comment.