From 8875972f38deadeb67fbe773eafa8dcaf9e42381 Mon Sep 17 00:00:00 2001 From: Zahlkovsk1 <148435929+Zahlkovsk1@users.noreply.github.com> Date: Sun, 14 Jul 2024 13:58:16 +0200 Subject: [PATCH] sheet finally complete --- Bilbary for iPhone/Viiews/BilbaryView.swift | 18 +----------------- .../Viiews/CustomSheetView.swift | 14 ++++++++++++++ .../iiPhone Models/SheetCoordinator.swift | 3 ++- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Bilbary for iPhone/Viiews/BilbaryView.swift b/Bilbary for iPhone/Viiews/BilbaryView.swift index 920afce..967e32a 100644 --- a/Bilbary for iPhone/Viiews/BilbaryView.swift +++ b/Bilbary for iPhone/Viiews/BilbaryView.swift @@ -12,12 +12,6 @@ struct BilbaryView: View { @State private var coordinator = SheetCoordinator() - @State - private var tabBarShown: Bool = false - - @State - private var sheetOffset: Double = 100 - var body: some View { ZStack { ZStack { @@ -27,20 +21,10 @@ struct BilbaryView: View { // Spacer() }.padding() .onTapGesture { - tabBarShown.toggle() - if tabBarShown { - withAnimation(.easeInOut(duration: 0.2)) { - sheetOffset = 0 - } - } else { - withAnimation(.easeInOut(duration: 0.2)) { - sheetOffset = 100 - } - } + coordinator.tabBarShown.toggle() } } CustomSheetView() - .offset(y: sheetOffset) .environment(coordinator) } } diff --git a/Bilbary for iPhone/Viiews/CustomSheetView.swift b/Bilbary for iPhone/Viiews/CustomSheetView.swift index 77a50f4..8cfb0c7 100644 --- a/Bilbary for iPhone/Viiews/CustomSheetView.swift +++ b/Bilbary for iPhone/Viiews/CustomSheetView.swift @@ -89,6 +89,20 @@ struct CustomSheetView: View { appUsageTracker.endSession(to: context) } } + .onChange(of: coordinator.tabBarShown) { + if coordinator.tabBarShown { + + withAnimation(.easeInOut(duration: 0.2)) { + coordinator.offset = UIScreen.main.bounds.height * 0.85 + } + } else { + + withAnimation(.easeInOut(duration: 0.2)) { + coordinator.offset = UIScreen.main.bounds.height * 1.1 + + } + } + } .background(.ultraThinMaterial) .cornerRadius(20.0) .offset(y: coordinator.offset) diff --git a/Bilbary for iPhone/iiPhone Models/SheetCoordinator.swift b/Bilbary for iPhone/iiPhone Models/SheetCoordinator.swift index 398c5da..43155f8 100644 --- a/Bilbary for iPhone/iiPhone Models/SheetCoordinator.swift +++ b/Bilbary for iPhone/iiPhone Models/SheetCoordinator.swift @@ -17,9 +17,10 @@ class SheetCoordinator { case top } + var tabBarShown: Bool = false var sheetOffset: Double = 0 - var offset: Double = UIScreen.main.bounds.height * 0.8 + var offset: Double = UIScreen.main.bounds.height * 1.1 var offsetAnchor: CGFloat? var deltaOffset: CGFloat = 0