Skip to content

Commit

Permalink
Update cards screens to add pull and refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic35 committed Feb 5, 2024
1 parent 2293e03 commit 5490201
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public struct ODSCardVerticalHeaderFirst: View {

ODSImage(source: imageSource)
.aspectRatio(contentMode: .fill)
.frame(maxHeight: 192, alignment: .center)
.clipped()
.accessibilityHidden(true)

VStack(alignment: .leading, spacing: ODSSpacing.none) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public struct ODSCardVerticalImageFirst: View {
Group {
ODSImage(source: imageSource)
.aspectRatio(contentMode: .fill)
.frame(maxHeight: 192, alignment: .center)
.clipped()
.accessibilityHidden(true)

VStack(alignment: .leading, spacing: ODSSpacing.xs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class BannerVariantModel: ObservableObject {
showImage = true
buttonCount = 0

self.recipe = RecipeBook.shared.randomRecipe()
self.recipe = RecipeBook.shared.recipes[0]
}

// =============
Expand All @@ -46,10 +46,6 @@ final class BannerVariantModel: ObservableObject {

var text: Text {
Text(showLongText ? recipe.description : recipe.title)
// let longText = °°"screens.components.banners.demo.long_text"
// let shortText = °°"screens.components.banners.demo.short_text"
//
// return Text(showLongText ? longText : shortText)
}

var imageSource: ODSImage.Source? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ final class CardHorizontalVariantModel: ObservableObject {
@Published var showAlert: Bool
@Published var imagePosition: ODSCardHorizontal.ImagePosition
@Published var showDivider: Bool
@Published var recipe: Recipe

var alertText: String
let buttonsText: [String]
private let recipe: Recipe


// =================
// MARK: Initializer
Expand Down Expand Up @@ -110,6 +111,10 @@ final class CardHorizontalVariantModel: ObservableObject {
alertText = text
showAlert = true
}

func updateRecipe() {
recipe = RecipeBook.shared.randomRecipe()
}
}

// ===============================
Expand Down Expand Up @@ -138,6 +143,9 @@ struct CardHorizontalVariant: View {
model.displayAlert(text: "screens.components.card.alert")
}
}
.refreshable {
model.updateRecipe()
}
.alert(model.alertText, isPresented: $model.showAlert) {
Button("shared.close", role: .cancel) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ final class CardSmallVariantModel: ObservableObject {
// MARK: Stored properties
// =======================

@Published var showSubtitle: Bool = true
@Published var showSubtitle: Bool
@Published var recipe: Recipe

init() {
showSubtitle = true
recipe = RecipeBook.shared.recipes[0]
}

func updateRecipe() {
recipe = RecipeBook.shared.randomRecipe()
}
}

struct CardSmallVariant: View {
Expand Down Expand Up @@ -56,6 +66,9 @@ struct CardSmallVariant: View {
}
.padding(.horizontal, ODSSpacing.m)
.padding(.top, ODSSpacing.m)
.refreshable {
model.updateRecipe()
}
} options: {
CardSmallVariantOptions(model: model)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ final class CardVerticalHeaderFirstVariantModel: ObservableObject {
@Published var showText: Bool
@Published var buttonCount: Int
@Published var showAlert: Bool

@Published var recipe: Recipe

var alertText: String = ""
let buttonsText: [String]
private let recipe: Recipe

// =================
// MARK: Initializer
Expand Down Expand Up @@ -86,6 +86,10 @@ final class CardVerticalHeaderFirstVariantModel: ObservableObject {
alertText = text
showAlert = true
}

func updateRecipe() {
recipe = RecipeBook.shared.randomRecipe()
}
}

// ==========================================
Expand Down Expand Up @@ -114,6 +118,9 @@ struct CardVerticalHeaderFirstVariant: View {
model.displayAlert(text: "screens.components.card.alert".🌐)
}
}
.refreshable {
model.updateRecipe()
}
.alert(model.alertText, isPresented: $model.showAlert) {
Button("shared.close", role: .cancel) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ final class CardVerticalImageFirstVariantModel: ObservableObject {
@Published var showText: Bool
@Published var buttonCount: Int
@Published var showAlert: Bool
@Published var recipe: Recipe

var alertText: String = ""
private let buttonsText: [String]
private let recipe: Recipe

// =================
// MARK: Initializer
Expand All @@ -43,8 +43,8 @@ final class CardVerticalImageFirstVariantModel: ObservableObject {
buttonCount = 2
showAlert = false

buttonsText = [°°"screens.components.card.button_1",
°°"screens.components.card.button_2"]
buttonsText = ["screens.components.card.button_1".🌐,
"screens.components.card.button_2".🌐]
recipe = RecipeBook.shared.recipes[0]
}

Expand Down Expand Up @@ -84,6 +84,10 @@ final class CardVerticalImageFirstVariantModel: ObservableObject {
var numberOfButtons: Int {
buttonsText.count
}

func updateRecipe() {
recipe = RecipeBook.shared.randomRecipe()
}
}

// =========================================
Expand All @@ -104,7 +108,6 @@ struct CardVerticalImageFirstVariant: View {

var body: some View {
CustomizableVariant {
// Card demonstrator
ScrollView {
card
.padding(.horizontal, ODSSpacing.m)
Expand All @@ -113,6 +116,9 @@ struct CardVerticalImageFirstVariant: View {
model.displayAlert(text: "screens.components.card.alert")
}
}
.refreshable {
model.updateRecipe()
}
.alert(model.alertText, isPresented: $model.showAlert) {
Button("shared.close", role: .cancel) {}
}
Expand Down

0 comments on commit 5490201

Please sign in to comment.