From 64a4adc4ed14d3cb7d3c6e721bfa6d37494cf66f Mon Sep 17 00:00:00 2001 From: theoriginalbit Date: Mon, 2 Aug 2021 12:14:06 +1000 Subject: [PATCH] Update README for the UIViewRepresentable support --- README.md | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 47f9f2b..e53f740 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,53 @@ # PreviewView -Make use of SwiftUI previews for your UIKit controllers! +Make use of SwiftUI previews for rapidly protyping your UIViewControllers and UIViews! + +### Previewing a UIViewController -It's as simple as: ```swift struct YourViewController_Previews: PreviewProvider { static var previews: some View { - PreviewView(for: YourViewController()) + Preview(for: YourViewController()) .edgesIgnoringSafeArea(.all) .previewDevice(PreviewDevice(rawValue: "iPhone 11")) } } ``` -If your view controller is meant to be displayed in a `UINavigationController` just add `.wrapInNavigationController()` +If your view controller is meant to be displayed in a `UINavigationController` there is a second parameter to adjust the navigation controller style; it can be either `.none` or `.wrap(prefersLargeTitles:)` ```swift struct YourViewController_Previews: PreviewProvider { static var previews: some View { - PreviewView(for: YourViewController()) - .wrapInNavigationController() + Preview(for: YourViewController(), navigationControllerStyle: .wrap(prefersLargeTitles: true)) .edgesIgnoringSafeArea(.all) .previewDevice(PreviewDevice(rawValue: "iPhone 11")) } } ``` -The `.wrapInNavigationController()` function accepts a single parameter `prefersLargeTitles` which allows you to also configure the navigation controller's `navigationBar.prefersLargeTitles` property; by default it will be set to `false`. +### Previewing a UIView + +```swift +struct YourViewController_Previews: PreviewProvider { + static var previews: some View { + Preview(for: YourView()) + .previewLayout(.fixed(width: 375, height: 86)) + } +} +``` + +Update the `previewLayout` values to be the typical size of your view. + +### Pro Tip + +Did you know that you can easily create multiple previews with a simple `ForEach` loop? -**PRO TIP:** Did you know that you can easily create multiple previews with a simple `ForEach` loop? ```swift struct YourViewController_Previews: PreviewProvider { static var previews: some View { ForEach(["iPhone 11", "iPhone 8", "iPhone SE (1st generation)"], id: \.self) { deviceName in - PreviewView(for: YourViewController()) - .edgesIgnoringSafeArea(.all) + Preview(for: YourViewController()) .previewDevice(PreviewDevice(rawValue: deviceName)) .previewDisplayName(deviceName) }