Skip to content

Instantly share code, notes, and snippets.

@karigrooms
Last active February 19, 2021 17:09
Show Gist options
  • Save karigrooms/1aedc75bdd19c370f099c167a395e63e to your computer and use it in GitHub Desktop.
Save karigrooms/1aedc75bdd19c370f099c167a395e63e to your computer and use it in GitHub Desktop.
SwiftUI UIViewRepresentable example for Lessons in SwiftUI blog post
import SwiftUI
// UIView wrapped with SwiftUI
struct UserAvatars: UIViewRepresentable {
let users: [UserProfile]
func makeUIView(context: Context) -> UserAvatarsUIView {
return UserAvatarsUIView()
}
func updateUIView(_ uiView: UserAvatarsUIView, context: Context) {
uiView.users = users
}
}
// Usage
struct TripBoardCard: View {
typealias ViewModel = TripBoardCardViewModel
let viewModel: ViewModel
var body: some View {
VStack(alignment: .leading, spacing: 10) {
// ...
HStack {
UserAvatars(users: viewModel.users)
.fixedSize()
Spacer()
Text(viewModel.propertyCount)
}
}
.padding(10)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment