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
40 changes: 5 additions & 35 deletions Modules/Sources/JetpackStats/Charts/BarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ struct BarChartView: View {

@State private var selectedDataPoints: SelectedDataPoints?
@State private var isDragging = false
@State private var isLongPressing = false
@State private var longPressLocation: CGPoint?
@State private var tappedDataPoint: DataPoint?

@Environment(\.context) var context
Expand Down Expand Up @@ -246,43 +244,15 @@ struct BarChartView: View {
.onTapGesture { location in
handleTapGesture(at: location, proxy: proxy, geometry: geometry)
}
.onLongPressGesture(minimumDuration: 0.3) {
// Long press completed - keep showing annotation
} onPressingChanged: { isPressing in
if isPressing {
// Long press started - show annotation at current location
if let location = longPressLocation {
isLongPressing = true
selectedDataPoints = getSelectedDataPoints(at: location, proxy: proxy, geometry: geometry)
}
} else {
// Long press ended - clear annotation
isLongPressing = false
longPressLocation = nil
if !isDragging {
selectedDataPoints = nil
}
tappedDataPoint = nil
}
}
.simultaneousGesture(
DragGesture(minimumDistance: 0)
DragGesture(minimumDistance: 16)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting minimumDistance is what does the trick of allowing it to run alongside the scroll in a scroll view. Reference: https://darjeelingsteve.com/articles/Preventing-Scroll-Hijacking-by-DragGestureRecognizer-Inside-ScrollView.html.

.onChanged { value in
// Store location for long press
longPressLocation = value.location

// Handle drag if moved enough
if value.translation.width.magnitude > 8 || value.translation.height.magnitude > 8 {
isDragging = true
selectedDataPoints = getSelectedDataPoints(at: value.location, proxy: proxy, geometry: geometry)
}
isDragging = true
selectedDataPoints = getSelectedDataPoints(at: value.location, proxy: proxy, geometry: geometry)
}
.onEnded { _ in
isDragging = false
longPressLocation = nil
if !isLongPressing {
selectedDataPoints = nil
}
selectedDataPoints = nil
tappedDataPoint = nil
}
)
Expand All @@ -291,7 +261,7 @@ struct BarChartView: View {

private func handleTapGesture(at location: CGPoint, proxy: ChartProxy, geometry: GeometryProxy) {
// Only handle tap if not dragging or long pressing
guard !isDragging && !isLongPressing else { return }
guard !isDragging else { return }

guard let onDateSelected,
data.granularity != .hour,
Expand Down
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
26.3
-----
* [*] Fix an issue with Notification Settings button not working in the Reader Subscriptions context menus for subscriptions [#24778]
* [*] Fix an issue with tooltip in bar charts in Stats preventing scrolling [#24822]
* [*] Fix rare crash in Reader when loading posts [#24815]

26.2
Expand Down