Skip to content

Commit

Permalink
Update documentation for SwiftUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTelezhkin committed Oct 6, 2022
1 parent b86dc14 commit 93c8729
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions Documentation/SwiftUI.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ It seems possible, and code infrastructure is prepared to implement SwiftUI view

However, I might reconsider this, if there's demand for this feature.

# When will DTTableViewManager support UIHostingConfiguration on iOS 16?
# Is UIHostingConfiguration supported on iOS 16 and higher?

If everything goes well, in the next 11.x release.
UIHostingConfiguration on iOS 16 is supported by additional registration method:

```swift
manager.registerHostingConfiguration(for: Post.self) { cell, post, indexPath in
UIHostingConfiguration {
PostView(post: post)
}
}
```

Because this is officially supported way of integrating SwiftUI with table and collection view cells, I highly recommend watching [WWDC 2022 session video](https://developer.apple.com/videos/play/wwdc2022/10072/) on this topic.

All customization options for UIHostingConfiguration is fully supported, for example you can customize margins for cells content:

```swift
manager.registerHostingConfiguration(for: Post.self) { cell, post, indexPath in
UIHostingConfiguration {
PostView(post: post)
}.margins(.horizontal, 16)
}
```

Additionally, you can also use `UICellConfigurationState` of a cell by simply adding one additional parameter:

```
manager.registerHostingConfiguration(for: Post.self) { state, cell, post, indexPath in
UIHostingConfiguration {
PostView(post: post, isSelected: state.isSelected)
}
}
```

0 comments on commit 93c8729

Please sign in to comment.