Skip to content

Commit

Permalink
Merge pull request #69 from novoda/feature/rm-67-detail-view-short-de…
Browse files Browse the repository at this point in the history
…scription

Feature [RM67] Detail View Short Description
  • Loading branch information
swg99 authored Aug 9, 2021
2 parents dabd26b + 7952821 commit 400b248
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Rick-and-Morty/Rick And Morty/Views/CharacterCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct CharacterCell: View {

VStack(alignment: .leading, spacing: 8) {
Text(character.name)
Text(description(for: character))
description(for: character)
}

if imagePosition == .right {
Expand All @@ -39,12 +39,12 @@ struct CharacterCell: View {
.buttonStyle(PlainButtonStyle())
}

func description(for character: Character) -> String {
func description(for character: Character) -> Text {
if let c = character as? ShortCharacterDescription {
return c.shortDescription
return Text(c.shortDescription)
}

return character.description
return Text(character.description)
}
}

Expand Down
17 changes: 13 additions & 4 deletions Rick-and-Morty/Rick And Morty/Views/CharacterDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ struct CharacterDetailView: View {
.resizable()
.scaledToFit()
.frame(maxHeight: 200)
HStack {

VStack(alignment: .leading, spacing: 12) {
if let c = character as? ShortCharacterDescription {
Text(c.shortDescription)
}
Text(character.description)
Spacer()
}

Spacer()
}
.padding()
Expand All @@ -30,7 +34,12 @@ struct CharacterDetailView: View {

struct CharacterDetailView_Previews: PreviewProvider {
static var previews: some View {
CharacterDetailView(character: ricks[0])
CharacterDetailView(character: morties[0])
NavigationView {
CharacterDetailView(character: ricks[0])
}
NavigationView {
CharacterDetailView(character: morties[2])

}
}
}

0 comments on commit 400b248

Please sign in to comment.