From 5490201fba4488d93f37c26a7416e8edf3184dd5 Mon Sep 17 00:00:00 2001 From: Ludovic PINEL Date: Mon, 5 Feb 2024 17:46:36 +0100 Subject: [PATCH] Update cards screens to add pull and refresh --- .../Cards/ODSCardVerticalHeaderFirst.swift | 2 ++ .../Cards/ODSCardVerticalImageFirst.swift | 2 ++ .../Pages/Banners/BannerVariantOptions.swift | 6 +----- .../Pages/Cards/CardHorizontalVariant.swift | 10 +++++++++- .../Components/Pages/Cards/CardSmallVariant.swift | 15 ++++++++++++++- .../Cards/CardVerticalHeaderFirstVariant.swift | 11 +++++++++-- .../Cards/CardVerticalImageFirstVariant.swift | 14 ++++++++++---- 7 files changed, 47 insertions(+), 13 deletions(-) diff --git a/OrangeDesignSystem/Sources/OrangeDesignSystem/Components/Cards/ODSCardVerticalHeaderFirst.swift b/OrangeDesignSystem/Sources/OrangeDesignSystem/Components/Cards/ODSCardVerticalHeaderFirst.swift index 4ed26b6e..924ab656 100644 --- a/OrangeDesignSystem/Sources/OrangeDesignSystem/Components/Cards/ODSCardVerticalHeaderFirst.swift +++ b/OrangeDesignSystem/Sources/OrangeDesignSystem/Components/Cards/ODSCardVerticalHeaderFirst.swift @@ -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) { diff --git a/OrangeDesignSystem/Sources/OrangeDesignSystem/Components/Cards/ODSCardVerticalImageFirst.swift b/OrangeDesignSystem/Sources/OrangeDesignSystem/Components/Cards/ODSCardVerticalImageFirst.swift index bd9e7c1d..a338fbd8 100644 --- a/OrangeDesignSystem/Sources/OrangeDesignSystem/Components/Cards/ODSCardVerticalImageFirst.swift +++ b/OrangeDesignSystem/Sources/OrangeDesignSystem/Components/Cards/ODSCardVerticalImageFirst.swift @@ -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) { diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Banners/BannerVariantOptions.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Banners/BannerVariantOptions.swift index 533e0f6c..8a4957f3 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Banners/BannerVariantOptions.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Banners/BannerVariantOptions.swift @@ -37,7 +37,7 @@ final class BannerVariantModel: ObservableObject { showImage = true buttonCount = 0 - self.recipe = RecipeBook.shared.randomRecipe() + self.recipe = RecipeBook.shared.recipes[0] } // ============= @@ -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? { diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardHorizontalVariant.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardHorizontalVariant.swift index bd087d71..e873cbb3 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardHorizontalVariant.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardHorizontalVariant.swift @@ -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 @@ -110,6 +111,10 @@ final class CardHorizontalVariantModel: ObservableObject { alertText = text showAlert = true } + + func updateRecipe() { + recipe = RecipeBook.shared.randomRecipe() + } } // =============================== @@ -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) {} } diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardSmallVariant.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardSmallVariant.swift index a9cfbb68..c3bb8c6c 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardSmallVariant.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardSmallVariant.swift @@ -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 { @@ -56,6 +66,9 @@ struct CardSmallVariant: View { } .padding(.horizontal, ODSSpacing.m) .padding(.top, ODSSpacing.m) + .refreshable { + model.updateRecipe() + } } options: { CardSmallVariantOptions(model: model) } diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardVerticalHeaderFirstVariant.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardVerticalHeaderFirstVariant.swift index 3ec171de..330fe0d3 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardVerticalHeaderFirstVariant.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardVerticalHeaderFirstVariant.swift @@ -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 @@ -86,6 +86,10 @@ final class CardVerticalHeaderFirstVariantModel: ObservableObject { alertText = text showAlert = true } + + func updateRecipe() { + recipe = RecipeBook.shared.randomRecipe() + } } // ========================================== @@ -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) {} } diff --git a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardVerticalImageFirstVariant.swift b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardVerticalImageFirstVariant.swift index 4342a7b1..b6411cf8 100644 --- a/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardVerticalImageFirstVariant.swift +++ b/OrangeDesignSystemDemo/OrangeDesignSystemDemo/Screens/Components/Pages/Cards/CardVerticalImageFirstVariant.swift @@ -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 @@ -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] } @@ -84,6 +84,10 @@ final class CardVerticalImageFirstVariantModel: ObservableObject { var numberOfButtons: Int { buttonsText.count } + + func updateRecipe() { + recipe = RecipeBook.shared.randomRecipe() + } } // ========================================= @@ -104,7 +108,6 @@ struct CardVerticalImageFirstVariant: View { var body: some View { CustomizableVariant { - // Card demonstrator ScrollView { card .padding(.horizontal, ODSSpacing.m) @@ -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) {} }