feat(Like Button): display bottom sheet variations
* Display bottom sheet variations if the item has variants instead of
adding it to the collection without their variants.
MODIFY
ACHNBrowserUI/ACHNBrowserUI/viewModels/LikeButtonViewModel.swift
ACHNBrowserUI/ACHNBrowserUI/viewModels/LikeButtonViewModel.swift
@@ -76,4 +76,8 @@ class LikeButtonViewModel: ObservableObject {
}
return added
}
+
+ var hasSomeVariations: Bool {
+ variant == nil && item?.hasSomeVariations == true
+ }
}

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/items/ItemsView.swift
ACHNBrowserUI/ACHNBrowserUI/views/items/ItemsView.swift
@@ -29,6 +29,7 @@ struct ItemsView: View {
@StateObject var viewModel: ItemsViewModel
@State private var contentMode: ContentMode = .listLarge
+ @State private var likedItemWithVariants: Item?
let customTitle: String?
init(category: Backend.Category, items: [Item]? = nil, keyword: String? = nil) {
@@ -110,6 +111,7 @@ struct ItemsView: View {
@ViewBuilder
private var contentView: some View {
+ ZStack {
if contentMode == .grid {
ScrollView {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 120), spacing: 16)], spacing: 16) {
@@ -125,8 +127,11 @@ struct ItemsView: View {
Section(header: SearchField(searchText: $viewModel.searchText)) {
ForEach(viewModel.items) { item in
NavigationLink(destination: LazyView(ItemDetailView(item: item))) {
- ItemRowView(displayMode: contentMode == .listLarge ? .large : .compact,
- item: item)
+ ItemRowView(
+ displayMode: contentMode == .listLarge ? .large : .compact,
+ item: item,
+ likedItemWithVariants: $likedItemWithVariants
+ )
}
.listRowBackground(Color.acSecondaryBackground)
}
@@ -135,6 +140,36 @@ struct ItemsView: View {
.listStyle(GroupedListStyle())
.id(viewModel.sort)
}
+ likedItemWithVariants.map { item in
+ ZStack {
+ Color.black
+ .opacity(1/6)
+ .onTapGesture { likedItemWithVariants = nil }
+ VStack {
+ Spacer()
+ itemVariants(for: item)
+ }
+ }
+ }
+ }
+ }
+
+ private func itemVariants(for item: Item) -> some View {
+ VStack {
+ SectionHeaderView(text: "Variants", icon: "paintbrush.fill").padding()
+ ScrollView(.horizontal, showsIndicators: false) {
+ HStack {
+ ForEach(item.variations ?? []) { variant in
+ ZStack(alignment: .topLeading) {
+ ItemImage(path: variant.content.image, size: 75)
+ LikeButtonView(item: item, variant: variant)
+ }
+ }
+ }.padding()
+ }
+ .listRowInsets(EdgeInsets())
+ }
+ .background(Color.acSecondaryBackground)
}
}

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/items/row/ItemRowView.swift
ACHNBrowserUI/ACHNBrowserUI/views/items/row/ItemRowView.swift
@@ -17,9 +17,19 @@ struct ItemRowView: View {
let displayMode: DisplayMode
let item: Item
-
+ @Binding var likedItemWithVariants: Item?
@State private var displayedVariant: Variant?
+ init(
+ displayMode: DisplayMode,
+ item: Item,
+ likedItemWithVariants: Binding<Item?> = .constant(nil)
+ ) {
+ self.displayMode = displayMode
+ self.item = item
+ self._likedItemWithVariants = likedItemWithVariants
+ }
+
private var imageSize: CGFloat {
switch displayMode {
case .compact:
@@ -87,7 +97,11 @@ struct ItemRowView: View {
var body: some View {
HStack(spacing: 8) {
if displayMode != .largeNoButton {
- LikeButtonView(item: item, variant: displayedVariant)
+ LikeButtonView(
+ item: item,
+ variant: displayedVariant,
+ likedItemWithVariants: $likedItemWithVariants
+ )
}
if item.finalImage == nil && displayedVariant == nil {
Image(item.appCategory.iconName())

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/shared/LikeButtonView.swift
ACHNBrowserUI/ACHNBrowserUI/views/shared/LikeButtonView.swift
@@ -11,13 +11,20 @@ import Backend
struct LikeButtonView: View {
@StateObject private var viewModel: LikeButtonViewModel
+ @Binding private var likedItemWithVariants: Item?
- init(item: Item, variant: Variant?) {
+ init(
+ item: Item,
+ variant: Variant?,
+ likedItemWithVariants: Binding<Item?> = .constant(nil)
+ ) {
_viewModel = StateObject(wrappedValue: LikeButtonViewModel(item: item, variant: variant))
+ _likedItemWithVariants = likedItemWithVariants
}
init(villager: Villager) {
_viewModel = StateObject(wrappedValue: LikeButtonViewModel(villager: villager))
+ _likedItemWithVariants = .constant(nil)
}
var imageName: String {
@@ -25,7 +32,7 @@ struct LikeButtonView: View {
if viewModel.item?.isCritter == true {
return viewModel.isInCollection ? "checkmark.seal.fill" : "checkmark.seal"
} else {
- if viewModel.item?.hasSomeVariations == true && viewModel.variant == nil {
+ if viewModel.hasSomeVariations {
switch viewModel.variantsCompletionStatus {
case .unstarted: return "star"
case .partial: return "star.leadinghalf.fill"
@@ -51,8 +58,12 @@ struct LikeButtonView: View {
var body: some View {
Button(action: {
+ if viewModel.hasSomeVariations {
+ likedItemWithVariants = viewModel.item
+ } else {
let added = self.viewModel.toggleCollection()
FeedbackGenerator.shared.triggerNotification(type: added ? .success : .warning)
+ }
}) {
Image(systemName: imageName).foregroundColor(color)
}

feat(Like Button): display bottom sheet variations

* Display bottom sheet variations if the item has variants instead of
  adding it to the collection without their variants.