Last active
August 21, 2022 10:47
-
-
Save lutes1/2b947a3ffb3688be68f708debb0f830a to your computer and use it in GitHub Desktop.
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
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