From afe1e828c9d48bc4160d66124b062f3234f95fde Mon Sep 17 00:00:00 2001 From: zhou_jun Date: Sat, 7 Dec 2024 11:33:52 +0800 Subject: [PATCH] Make compatible to swift 6.0 and iOS 18 --- .../SwipeCell/SwipeCellViewModifier2.swift | 20 +++++++++---------- .../SwipeCell/SwipeCellViewModifier3.swift | 10 +++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Sources/SwipeCell/SwipeCellViewModifier2.swift b/Sources/SwipeCell/SwipeCellViewModifier2.swift index a5a88c2..0ff962d 100644 --- a/Sources/SwipeCell/SwipeCellViewModifier2.swift +++ b/Sources/SwipeCell/SwipeCellViewModifier2.swift @@ -39,18 +39,14 @@ extension SwipeCellModifier { .environment(\.cellStatus, status) } .zIndex(3) - .highPriorityGesture( - TapGesture(count: 1), - including: currentCellID == nil ? .subviews : .none - ) .contentShape(Rectangle()) - //解决Button冲突问题. - .onTapGesture( - count: currentCellID != nil ? 1 : 4, - perform: { + .highPriorityGesture( + TapGesture(count: 1) + .onEnded { resetStatus() dismissNotification() - } + }, + including: currentCellID == nil ? .subviews : .gesture ) .offset(x: offset) } @@ -183,7 +179,11 @@ extension View { @ViewBuilder func myGesture(_ g:_EndedGesture<_ChangedGesture>) -> some View { if #available(iOS 18, *) { - simultaneousGesture(g) + #if compiler(>=6.0) + highPriorityGesture(g) + #else + gesture(g) + #endif } else { gesture(g) } diff --git a/Sources/SwipeCell/SwipeCellViewModifier3.swift b/Sources/SwipeCell/SwipeCellViewModifier3.swift index 637e995..e2bac8c 100644 --- a/Sources/SwipeCell/SwipeCellViewModifier3.swift +++ b/Sources/SwipeCell/SwipeCellViewModifier3.swift @@ -8,8 +8,16 @@ import SwiftUI extension SwipeCellModifier { func getGesture() -> _EndedGesture<_ChangedGesture> { //为了避免editMode切换时的异常动画,所以在进入editmode后仍然继续绘制Slots,只是对手势做了处理,避免了滑动 + let nonEditGragMinDistance: CGFloat = { + if #available(iOS 18, *) { + #if compiler(>=6.0) + return 20 + #endif + } + return 0 + }() return DragGesture( - minimumDistance: editMode?.wrappedValue == .active ? 10000 : 0, + minimumDistance: editMode?.wrappedValue == .active ? 10000 : nonEditGragMinDistance, coordinateSpace: .local ) .onChanged { value in