feat(Like Button): animate the variants bottom sheet view
* Also refactor the Bottom sheet view to let it be in its own View
* Add the behaviour inside the ItemDetailView for the main Like button,
so it fixes the "doing nothing" behaviour
MODIFY
ACHNBrowserUI/ACHNBrowserUI.xcodeproj/project.pbxproj
ACHNBrowserUI/ACHNBrowserUI.xcodeproj/project.pbxproj
4C30BFC3249627FD003E96A2 /* Sequence+Unique.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C30BFC2249627FC003E96A2 /* Sequence+Unique.swift */; };
4C6E95FD24842F690074433B /* Collection+SafeDirectAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6E95FC24842F690074433B /* Collection+SafeDirectAccess.swift */; };
4C7F555D248B91C80089F26C /* TodayVillagerVisitsSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C7F555C248B91C80089F26C /* TodayVillagerVisitsSection.swift */; };
+ 4CB1E3D925A0BB8F0021A175 /* VariantsForLikeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB1E3D825A0BB8F0021A175 /* VariantsForLikeView.swift */; };
69157B7E2471A5A1005B9002 /* TodayMysteryIslandsSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69157B6D247121ED005B9002 /* TodayMysteryIslandsSection.swift */; };
69157B802471A5A1005B9002 /* UserListFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69875F5424654EB900B1D46C /* UserListFormView.swift */; };
69157B812471A5A1005B9002 /* RowLoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 693E2BBD2465B65D00B85CB8 /* RowLoadingView.swift */; };
4C7F2F772461F10300930928 /* TurnipsChartVerticalLegend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartVerticalLegend.swift; sourceTree = "<group>"; };
4C7F555C248B91C80089F26C /* TodayVillagerVisitsSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayVillagerVisitsSection.swift; sourceTree = "<group>"; };
4C7FE788245B57A10011E8AB /* AdaptsToSoftwareKeyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptsToSoftwareKeyboard.swift; sourceTree = "<group>"; };
+ 4CB1E3D825A0BB8F0021A175 /* VariantsForLikeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VariantsForLikeView.swift; sourceTree = "<group>"; };
4CF14B74246B3E9E00F740BF /* TurnipsChartValuesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartValuesView.swift; sourceTree = "<group>"; };
4CF8049A24635E54005C6C63 /* Path.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Path.swift; sourceTree = "<group>"; };
4F92A4522470AC01003A2911 /* CollectionRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionRowView.swift; sourceTree = "<group>"; };
69CA5F00244F1AD300B275B6 /* SectionHeaderView.swift */,
69875F4F24652A4700B1D46C /* Sheet.swift */,
69E67EFA2494C35B00ED7AC8 /* ButtonImageCounterOverlay.swift */,
+ 4CB1E3D825A0BB8F0021A175 /* VariantsForLikeView.swift */,
);
path = shared;
sourceTree = "<group>";
69157BB02471A5A1005B9002 /* TodayView.swift in Sources */,
69157BB12471A5A1005B9002 /* CategoriesView.swift in Sources */,
69157BB22471A5A1005B9002 /* Sheet.swift in Sources */,
+ 4CB1E3D925A0BB8F0021A175 /* VariantsForLikeView.swift in Sources */,
6950EB37249D03C7002A4902 /* CommentsSection.swift in Sources */,
69157BB32471A5A1005B9002 /* CategoriesSearchViewModel.swift in Sources */,
69157BB42471A5A1005B9002 /* UserListRow.swift in Sources */,

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/items/ItemsView.swift
ACHNBrowserUI/ACHNBrowserUI/views/items/ItemsView.swift
@@ -140,36 +140,8 @@ 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())
+ VariantsForLikeView(item: $likedItemWithVariants)
}
- .background(Color.acSecondaryBackground)
}
}

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/items/detail/ItemDetailView.swift
ACHNBrowserUI/ACHNBrowserUI/views/items/detail/ItemDetailView.swift
@@ -20,6 +20,7 @@ struct ItemDetailView: View {
@State private var displayedVariant: Variant?
@State private var selectedSheet: Sheet.SheetType?
+ @State private var itemToDisplayVariantsLike: Item?
init(item: Item) {
self._itemViewModel = StateObject(wrappedValue: ItemDetailViewModel(item: item))
@@ -46,6 +47,13 @@ struct ItemDetailView: View {
// MARK: - Boby
var body: some View {
+ ZStack {
+ content
+ VariantsForLikeView(item: $itemToDisplayVariantsLike)
+ }
+ }
+
+ var content: some View {
List {
ItemDetailInfoView(item: itemViewModel.item,
recipe: itemViewModel.recipe,
@@ -123,13 +131,23 @@ extension ItemDetailView {
private var navButtons: some View {
HStack {
- LikeButtonView(item: itemViewModel.item,
- variant: displayedVariant).imageScale(.large)
+ LikeButtonView(
+ item: itemViewModel.item,
+ variant: displayedVariant,
+ customAction: tapOnMainLikeButton
+ )
+ .imageScale(.large)
.safeHoverEffectBarItem(position: .trailing)
+
shareButton
}
}
+ private func tapOnMainLikeButton() {
+ // Display variants bottom sheet only if the item has some variants
+ itemToDisplayVariantsLike = itemViewModel.item.hasSomeVariations ? itemViewModel.item : nil
+ }
+
private var keywordsSection: some View {
Section(header: SectionHeaderView(text: "Keywords", icon: "link")) {
ScrollView(.horizontal, showsIndicators: false) {

MODIFY
ACHNBrowserUI/ACHNBrowserUI/views/shared/LikeButtonView.swift
ACHNBrowserUI/ACHNBrowserUI/views/shared/LikeButtonView.swift
@@ -12,14 +12,17 @@ import Backend
struct LikeButtonView: View {
@StateObject private var viewModel: LikeButtonViewModel
@Binding private var likedItemWithVariants: Item?
+ private var customAction: () -> Void = { }
init(
item: Item,
variant: Variant?,
- likedItemWithVariants: Binding<Item?> = .constant(nil)
+ likedItemWithVariants: Binding<Item?> = .constant(nil),
+ customAction: @escaping () -> Void = { }
) {
_viewModel = StateObject(wrappedValue: LikeButtonViewModel(item: item, variant: variant))
_likedItemWithVariants = likedItemWithVariants
+ self.customAction = customAction
}
init(villager: Villager) {
@@ -64,6 +67,7 @@ struct LikeButtonView: View {
let added = self.viewModel.toggleCollection()
FeedbackGenerator.shared.triggerNotification(type: added ? .success : .warning)
}
+ customAction()
}) {
Image(systemName: imageName).foregroundColor(color)
}

MODIFY
ACHNBrowserUI/Packages/Backend/Sources/Backend/Environments/UserCollection.swift
ACHNBrowserUI/Packages/Backend/Sources/Backend/Environments/UserCollection.swift
@@ -152,10 +152,10 @@ public class UserCollection: ObservableObject {
if !items.contains(item) && variants.completionStatus(for: item) != .unstarted {
// We add the item to the liked items if at least one of its variant is added
- toggleItem(item: item)
+ _ = toggleItem(item: item)
} else if items.contains(item) && variants.completionStatus(for: item) == .unstarted {
// We remove the item from the liked items if there is none of its variants liked
- toggleItem(item: item)
+ _ = toggleItem(item: item)
}
return isAdded

MODIFY
ACHNBrowserUI/Packages/Backend/Sources/Backend/Models/Item.swift
ACHNBrowserUI/Packages/Backend/Sources/Backend/Models/Item.swift
@@ -272,7 +272,20 @@ public let static_item = Item(name: "Acoustic guitar",
dIY: true,
customize: true,
movementSpeed: nil,
- variations: nil,
+ variations: [
+ Variant(id: 49134, content: Variant.Content(
+ image: "https://acnhcdn.com/latest/FtrIcon/FtrAcorsticguitar_Remake_0_0.png",
+ colors: ["Beige", "Brown"]
+ )),
+ Variant(id: 49135, content: Variant.Content(
+ image: "https://acnhcdn.com/latest/FtrIcon/FtrAcorsticguitar_Remake_1_0.png",
+ colors: ["Red", "Black"]
+ )),
+ Variant(id: 49136, content: Variant.Content(
+ image: "https://acnhcdn.com/latest/FtrIcon/FtrAcorsticguitar_Remake_2_0.png",
+ colors: ["Brown", "Black"]
+ )),
+ ],
category: "Housewares",
materials: nil,
buy: 200,

feat(Like Button): animate the variants bottom sheet view

* Also refactor the Bottom sheet view to let it be in its own View
* Add the behaviour inside the ItemDetailView for the main Like button,
  so it fixes the "doing nothing" behaviour