Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public struct MessageDisplayOptions {
overlayDateLabelSize: CGFloat = 40,
lastInGroupHeaderSize: CGFloat = 0,
newMessagesSeparatorSize: CGFloat = 50,
minimumSwipeGestureDistance: CGFloat = 10,
minimumSwipeGestureDistance: CGFloat = 20,
currentUserMessageTransition: AnyTransition = .identity,
otherUserMessageTransition: AnyTransition = .identity,
shouldAnimateReactions: Bool = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
private var trailingRightButtonTapped: (ChatChannel) -> Void
private var trailingLeftButtonTapped: (ChatChannel) -> Void
private var leadingButtonTapped: (ChatChannel) -> Void

@State private var verticalScrolling = false

public init(
factory: Factory,
Expand Down Expand Up @@ -76,7 +78,7 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
.offset(x: self.offsetX)
.simultaneousGesture(
DragGesture(
minimumDistance: 10,
minimumDistance: 20,
coordinateSpace: .local
)
.updating($offset) { (value, gestureState, _) in
Expand All @@ -85,7 +87,11 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
width: value.location.x - value.startLocation.x,
height: value.location.y - value.startLocation.y
)


if abs(value.translation.height) > abs(value.translation.width) && !verticalScrolling {
verticalScrolling = true
}

if diff == .zero {
gestureState = .zero
} else {
Expand All @@ -98,7 +104,8 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
if offset == .zero {
// gesture ended or cancelled
dragEnded()
} else {
verticalScrolling = false
} else if !verticalScrolling {
dragChanged(to: offset.width)
}
})
Expand All @@ -122,7 +129,19 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
}

private var showTrailingSwipeActions: Bool {
!(trailingSwipeActions is EmptyView)
#if DEBUG
let view = factory.makeTrailingSwipeActionsView(
channel: channel,
offsetX: offsetX,
buttonWidth: buttonWidth,
swipedChannelId: $swipedChannelId,
leftButtonTapped: trailingLeftButtonTapped,
rightButtonTapped: trailingRightButtonTapped
)
return !(view is EmptyView)
#else
return !(trailingSwipeActions is EmptyView)
#endif
}

private var leadingSwipeActions: some View {
Expand All @@ -136,7 +155,18 @@ public struct ChatChannelSwipeableListItem<Factory: ViewFactory, ChannelListItem
}

private var showLeadingSwipeActions: Bool {
!(leadingSwipeActions is EmptyView)
#if DEBUG
let view = factory.makeLeadingSwipeActionsView(
channel: channel,
offsetX: offsetX,
buttonWidth: buttonWidth,
swipedChannelId: $swipedChannelId,
buttonTapped: leadingButtonTapped
)
return !(view is EmptyView)
#else
return !(leadingSwipeActions is EmptyView)
#endif
}

private func dragChanged(to value: CGFloat) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/StreamChatSwiftUI/DefaultViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extension ViewFactory {
swipedChannelId: Binding<String?>,
leftButtonTapped: @escaping (ChatChannel) -> Void,
rightButtonTapped: @escaping (ChatChannel) -> Void
) -> some View {
) -> TrailingSwipeActionsView {
TrailingSwipeActionsView(
channel: channel,
offsetX: offsetX,
Expand All @@ -127,7 +127,7 @@ extension ViewFactory {
buttonWidth: CGFloat,
swipedChannelId: Binding<String?>,
buttonTapped: (ChatChannel) -> Void
) -> some View {
) -> EmptyView {
EmptyView()
}

Expand Down