Skip to content

Commit 24f639c

Browse files
committed
Add a onDrag callback
1 parent 3cdfe3d commit 24f639c

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

ChartUI.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |spec|
22

33
spec.name = "ChartUI"
4-
spec.version = "0.4.0"
4+
spec.version = "0.5.0"
55
spec.summary = "📈 A SwiftUI chart library"
66
spec.homepage = "https://github.com/theo-brlle/chart-ui"
77
spec.license = { :type => "MIT", :file => "LICENSE" }

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Just add this repo as a dependency of your project. Here is the repo URL: https:
1515
Add ChartUI as a dependency in your `Podfile`.
1616

1717
```
18-
pod 'ChartUI', '~> 0.4.0'
18+
pod 'ChartUI', '~> 0.5.0'
1919
```
2020

2121
Then run `pod install` and open the `.xcworkspace` file in Xcode.

Sources/ChartUI/LineChart/ViewModels/LineChartViewModel.swift

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ final class LineChartViewModel: ObservableObject {
2525
@Published var plotDetailsViewSize: CGSize = .zero
2626
@Published var rightLabelsViewSize: CGSize = .zero
2727

28+
// MARK: - Callbacks
29+
30+
var onDragAction: ((Bool) -> Void)?
31+
2832
// MARK: - Computed properties
2933

3034
var chartColor: Color {

Sources/ChartUI/LineChart/Views/LineChartView.swift

+15
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,35 @@ private extension LineChartView {
238238
var dragGesture: some Gesture {
239239
DragGesture(minimumDistance: 0)
240240
.onChanged { value in
241+
if !viewModel.isPlotDetailsViewPresented {
242+
viewModel.onDragAction?(true)
243+
}
244+
241245
withAnimation {
242246
viewModel.isPlotDetailsViewPresented = true
243247
}
244248

245249
viewModel.updateSelectedPlot(from: value.location.x)
246250
}
247251
.onEnded { value in
252+
viewModel.onDragAction?(false)
253+
248254
withAnimation {
249255
viewModel.isPlotDetailsViewPresented = false
250256
}
251257
}
252258
}
253259
}
254260

261+
// MARK: - Callbacks
262+
263+
public extension LineChartView {
264+
func onDrag(_ action: @escaping (Bool) -> Void) -> Self {
265+
self.viewModel.onDragAction = action
266+
return self
267+
}
268+
}
269+
255270
// MARK: - Previews
256271

257272
struct LineChartView_Previews: PreviewProvider {

0 commit comments

Comments
 (0)