Skip to content

Instantly share code, notes, and snippets.

@lutes1
Last active August 21, 2022 10:47
Show Gist options
  • Save lutes1/2b947a3ffb3688be68f708debb0f830a to your computer and use it in GitHub Desktop.
Save lutes1/2b947a3ffb3688be68f708debb0f830a to your computer and use it in GitHub Desktop.
struct HeaderView<LeftControls: View, RightControls: View>: View {
init(
viewModel: HeaderViewModel,
@ViewBuilder leftControls: @escaping () -> LeftControls,
@ViewBuilder rightControls: @escaping () -> RightControls) {
// Assignments removed for brevety
}
private var viewModel: HeaderViewModel
private let leftControls: () -> LeftControls
private let rightControls: () -> RightControls
var body: some View {
ZStack {
HStack {
if let leftButtonTitle = viewModel.leftButtonTitle {
Button(leftButtonTitle) {
viewModel.leftButtonAction?()
}
}
leftControls()
Spacer()
rightControls()
}
Text(viewModel.title)
.font(.title.bold())
}
.buttonStyle(.bordered)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment