Skip to content

Commit

Permalink
Update README for the UIViewRepresentable support
Browse files Browse the repository at this point in the history
  • Loading branch information
theoriginalbit committed Aug 2, 2021
1 parent cab3c46 commit 64a4adc
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down

0 comments on commit 64a4adc

Please sign in to comment.