Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created October 15, 2019 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/6a9ac00ba5fe8f028d7a948f26ed231b to your computer and use it in GitHub Desktop.
Save fitomad/6a9ac00ba5fe8f028d7a948f26ed231b to your computer and use it in GitHub Desktop.
internal struct SessionView : View
{
...
@ObservedObject private var sessionModel: SessionViewModel
/// Vista
var body: some View
{
ScrollView([ .vertical ], showsIndicators: false)
{
Button(action: self.handleFavoriteButtonTap) {
Text(self.sessionModel.isFavorite ? "Quitar de Favoritos" : "Marcar como favorita")
.font(.callout)
.fontWeight(.semibold)
.foregroundColor(self.sessionModel.isFavorite ? .accentColor : .white)
.frame(minWidth: 0, maxWidth: .infinity)
}
.frame(height: 50)
.background(self.sessionModel.isFavorite ? Color.white : Color.accentColor)
.cornerRadius(6)
.shadow(radius: self.sessionModel.isFavorite ? 0 : 4)
.padding([.top, .bottom], 24)
...
}
...
}
/**
*/
internal init(for session: Session)
{
...
self.sessionModel = SessionViewModel(forSession: session)
}
/**
*/
private func handleFavoriteButtonTap() -> Void
{
self.sessionModel.isFavorite.toggle()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment