From 88c709775c9f74e253a36ee8d08577ffb5136081 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Fri, 14 Oct 2022 21:11:48 +0700 Subject: [PATCH 1/2] add custom animation config --- SwiftUIBottomSheet/Classes/BottomSheet.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SwiftUIBottomSheet/Classes/BottomSheet.swift b/SwiftUIBottomSheet/Classes/BottomSheet.swift index a34781a..27ad10a 100644 --- a/SwiftUIBottomSheet/Classes/BottomSheet.swift +++ b/SwiftUIBottomSheet/Classes/BottomSheet.swift @@ -29,7 +29,8 @@ public struct BottomSheetConfig { handleColor: Color = .init(.lightGray), handlePosition: HandlePosition = .inside, topBarCornerRadius: CGFloat? = nil, - sizeChangeRequest: Binding = .constant(0)) { + sizeChangeRequest: Binding = .constant(0), + animation: Animation = .interactiveSpring()) { self.maxHeight = maxHeight self.kind = kind self.overlayColor = overlayColor @@ -39,6 +40,7 @@ public struct BottomSheetConfig { self.handlePosition = handlePosition self.topBarCornerRadius = topBarCornerRadius self.sizeChangeRequest = sizeChangeRequest + self.animation = animation } public enum Kind: Int, CaseIterable, Equatable { @@ -63,6 +65,7 @@ public struct BottomSheetConfig { public var handlePosition: HandlePosition public var topBarCornerRadius: CGFloat? public var sizeChangeRequest: Binding + public var animation: Animation } public extension BottomSheetConfig { @@ -245,9 +248,9 @@ private struct BottomSheetContainer: View { } } .offset(y: offset) - .animation(shown ? .interactiveSpring() : nil, value: height) - .animation(.interactiveSpring(), value: dragEnded) - .animation(.interactiveSpring(), value: config.handlePosition) + .animation(shown ? config.animation : nil, value: height) + .animation(config.animation, value: dragEnded) + .animation(config.animation, value: config.handlePosition) .transaction { if dragStart != nil { $0.animation = .interactiveSpring() From d264370d04b6fa6d632041eb6dbec9bdaa06b617 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Sat, 15 Oct 2022 16:33:53 +0700 Subject: [PATCH 2/2] update --- SwiftUIBottomSheet/Classes/BottomSheet.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftUIBottomSheet/Classes/BottomSheet.swift b/SwiftUIBottomSheet/Classes/BottomSheet.swift index 27ad10a..84a84fc 100644 --- a/SwiftUIBottomSheet/Classes/BottomSheet.swift +++ b/SwiftUIBottomSheet/Classes/BottomSheet.swift @@ -253,7 +253,7 @@ private struct BottomSheetContainer: View { .animation(config.animation, value: config.handlePosition) .transaction { if dragStart != nil { - $0.animation = .interactiveSpring() + $0.animation = config.animation } } }