From 9782412dc5df05419084005c90079270b8bbad5d Mon Sep 17 00:00:00 2001 From: Ivan Magda Date: Wed, 24 Jul 2024 17:07:15 +0900 Subject: [PATCH] Use FlowLayoutCompatibility --- ...ojectSelectionListGridCellBadgesView.swift | 52 ++++++++++--------- .../StepQuizCodeBlanksSuggestionsView.swift | 39 ++++++-------- .../Item/StudyPlanSectionItemBadgesView.swift | 25 +++++---- ...TrackSelectionListGridCellBadgesView.swift | 51 ++++++++++-------- 4 files changed, 87 insertions(+), 80 deletions(-) diff --git a/iosHyperskillApp/iosHyperskillApp/Sources/Modules/ProjectSelection/List/Views/Grid/Cell/ProjectSelectionListGridCellBadgesView.swift b/iosHyperskillApp/iosHyperskillApp/Sources/Modules/ProjectSelection/List/Views/Grid/Cell/ProjectSelectionListGridCellBadgesView.swift index 6868ee5ab9..fc3aa7c019 100644 --- a/iosHyperskillApp/iosHyperskillApp/Sources/Modules/ProjectSelection/List/Views/Grid/Cell/ProjectSelectionListGridCellBadgesView.swift +++ b/iosHyperskillApp/iosHyperskillApp/Sources/Modules/ProjectSelection/List/Views/Grid/Cell/ProjectSelectionListGridCellBadgesView.swift @@ -12,10 +12,13 @@ struct ProjectSelectionListGridCellBadgesView: View { } var body: some View { - if isEmpty { - EmptyView() - } else { - HStack(spacing: LayoutInsets.smallInset) { + if !isEmpty { + FlowLayoutCompatibility( + configuration: .init( + spacing: LayoutInsets.smallInset, + fallbackLayout: .horizontal() + ) + ) { if isSelected { BadgeView.selected() } @@ -40,24 +43,25 @@ struct ProjectSelectionListGridCellBadgesView: View { } } -struct ProjectSelectionListGridCellBadgesView_Previews: PreviewProvider { - static var previews: some View { - ProjectSelectionListGridCellBadgesView( - isSelected: true, - isIdeRequired: true, - isBeta: true, - isBestRated: true, - isFastestToComplete: true - ) - .padding() - - ProjectSelectionListGridCellBadgesView( - isSelected: true, - isIdeRequired: true, - isBeta: true, - isBestRated: true, - isFastestToComplete: true - ) - .preferredColorScheme(.dark) - } +#if DEBUG +#Preview { + ProjectSelectionListGridCellBadgesView( + isSelected: true, + isIdeRequired: true, + isBeta: true, + isBestRated: true, + isFastestToComplete: true + ) +} + +#Preview { + ProjectSelectionListGridCellBadgesView( + isSelected: true, + isIdeRequired: true, + isBeta: true, + isBestRated: true, + isFastestToComplete: true + ) + .preferredColorScheme(.dark) } +#endif diff --git a/iosHyperskillApp/iosHyperskillApp/Sources/Modules/StepQuizSubmodules/StepQuizCodeBlanks/Views/StepQuizCodeBlanksSuggestionsView.swift b/iosHyperskillApp/iosHyperskillApp/Sources/Modules/StepQuizSubmodules/StepQuizCodeBlanks/Views/StepQuizCodeBlanksSuggestionsView.swift index feed5acbc2..3feb666bf8 100644 --- a/iosHyperskillApp/iosHyperskillApp/Sources/Modules/StepQuizSubmodules/StepQuizCodeBlanks/Views/StepQuizCodeBlanksSuggestionsView.swift +++ b/iosHyperskillApp/iosHyperskillApp/Sources/Modules/StepQuizSubmodules/StepQuizCodeBlanks/Views/StepQuizCodeBlanksSuggestionsView.swift @@ -7,30 +7,25 @@ struct StepQuizCodeBlanksSuggestionsView: View { let onSuggestionTap: (Suggestion) -> Void var body: some View { - let views = ForEach(suggestions, id: \.self) { suggestion in - Button( - action: { - onSuggestionTap(suggestion) - }, - label: { - StepQuizCodeBlanksOptionView(text: suggestion.text, isActive: true) - } + FlowLayoutCompatibility( + configuration: .init( + spacing: LayoutInsets.defaultInset, + fallbackLayout: .vertical() ) - .buttonStyle(BounceButtonStyle()) - } - - if #available(iOS 16.0, *) { - FlowLayout(spacing: LayoutInsets.defaultInset) { - views - } - .padding(LayoutInsets.defaultInset) - .frame(minHeight: 72) - } else { - VStack(alignment: .leading, spacing: LayoutInsets.defaultInset) { - views + ) { + ForEach(suggestions, id: \.self) { suggestion in + Button( + action: { + onSuggestionTap(suggestion) + }, + label: { + StepQuizCodeBlanksOptionView(text: suggestion.text, isActive: true) + } + ) + .buttonStyle(BounceButtonStyle()) } - .padding(LayoutInsets.defaultInset) - .frame(minHeight: 72) } + .padding(LayoutInsets.defaultInset) + .frame(minHeight: 72) } } diff --git a/iosHyperskillApp/iosHyperskillApp/Sources/Modules/StudyPlan/Views/Section/List/Item/StudyPlanSectionItemBadgesView.swift b/iosHyperskillApp/iosHyperskillApp/Sources/Modules/StudyPlan/Views/Section/List/Item/StudyPlanSectionItemBadgesView.swift index aba8974b05..4fbaec8053 100644 --- a/iosHyperskillApp/iosHyperskillApp/Sources/Modules/StudyPlan/Views/Section/List/Item/StudyPlanSectionItemBadgesView.swift +++ b/iosHyperskillApp/iosHyperskillApp/Sources/Modules/StudyPlan/Views/Section/List/Item/StudyPlanSectionItemBadgesView.swift @@ -10,10 +10,13 @@ struct StudyPlanSectionItemBadgesView: View { } var body: some View { - if isEmpty { - EmptyView() - } else { - HStack(spacing: LayoutInsets.smallInset) { + if !isEmpty { + FlowLayoutCompatibility( + configuration: .init( + spacing: LayoutInsets.smallInset, + fallbackLayout: .horizontal() + ) + ) { if let formattedProgress { BadgeView(text: formattedProgress, style: .green) } @@ -26,11 +29,11 @@ struct StudyPlanSectionItemBadgesView: View { } } -struct StudyPlanSectionItemBadgesView_Previews: PreviewProvider { - static var previews: some View { - StudyPlanSectionItemBadgesView( - formattedProgress: "50%", - isIdeRequired: true - ) - } +#if DEBUG +#Preview { + StudyPlanSectionItemBadgesView( + formattedProgress: "50%", + isIdeRequired: true + ) } +#endif diff --git a/iosHyperskillApp/iosHyperskillApp/Sources/Modules/TrackSelection/List/Views/Grid/Cell/TrackSelectionListGridCellBadgesView.swift b/iosHyperskillApp/iosHyperskillApp/Sources/Modules/TrackSelection/List/Views/Grid/Cell/TrackSelectionListGridCellBadgesView.swift index fb0a09e693..44738a95ce 100644 --- a/iosHyperskillApp/iosHyperskillApp/Sources/Modules/TrackSelection/List/Views/Grid/Cell/TrackSelectionListGridCellBadgesView.swift +++ b/iosHyperskillApp/iosHyperskillApp/Sources/Modules/TrackSelection/List/Views/Grid/Cell/TrackSelectionListGridCellBadgesView.swift @@ -11,10 +11,13 @@ struct TrackSelectionListGridCellBadgesView: View { } var body: some View { - if isEmpty { - EmptyView() - } else { - HStack(spacing: LayoutInsets.smallInset) { + if !isEmpty { + FlowLayoutCompatibility( + configuration: .init( + spacing: LayoutInsets.smallInset, + fallbackLayout: .horizontal() + ) + ) { if isSelected { BadgeView.selected() } @@ -35,23 +38,25 @@ struct TrackSelectionListGridCellBadgesView: View { } } -struct TrackSelectionListGridCellBadgesView_Previews: PreviewProvider { - static var previews: some View { - TrackSelectionListGridCellBadgesView( - isSelected: true, - isIdeRequired: true, - isBeta: true, - isCompleted: true - ) - .padding() - - TrackSelectionListGridCellBadgesView( - isSelected: true, - isIdeRequired: true, - isBeta: true, - isCompleted: true - ) - .padding() - .preferredColorScheme(.dark) - } +#if DEBUG +#Preview { + TrackSelectionListGridCellBadgesView( + isSelected: true, + isIdeRequired: true, + isBeta: true, + isCompleted: true + ) + .padding() +} + +#Preview { + TrackSelectionListGridCellBadgesView( + isSelected: true, + isIdeRequired: true, + isBeta: true, + isCompleted: true + ) + .padding() + .preferredColorScheme(.dark) } +#endif