Last active
February 19, 2021 17:09
-
-
Save karigrooms/1aedc75bdd19c370f099c167a395e63e to your computer and use it in GitHub Desktop.
SwiftUI UIViewRepresentable example for Lessons in SwiftUI blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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