Skip to content

Commit

Permalink
fix(ios): use different gesture tags
Browse files Browse the repository at this point in the history
when there is more than one pie chart on the same page on iOS and the latest added pie chart slices get tapped the first pie chart's tap gesture handler gets triggered. this commit aims to fix this issue. (bar/line charts already have the logic that is added with this commit for pie and radar charts)
  • Loading branch information
canmertc committed Mar 4, 2024
1 parent 1673bf5 commit 6fb3b5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/charting/charts/Chart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PanGestureHandlerOptions, PinchGestureHandlerOptions, TapGestureHandlerOptions } from '@nativescript-community/gesturehandler';
import { PanGestureHandlerOptions, PinchGestureHandlerOptions, RotationGestureHandlerOptions, TapGestureHandlerOptions } from '@nativescript-community/gesturehandler';
import { Align, Canvas, CanvasView, Paint } from '@nativescript-community/ui-canvas';
import { EventData, Utils as NUtils, Trace } from '@nativescript/core';
import { ChartAnimator, EasingFunction } from '../animation/ChartAnimator';
Expand Down Expand Up @@ -215,6 +215,7 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
public tapGestureOptions: TapGestureHandlerOptions & { gestureTag?: number };
public doubleTapGestureOptions: TapGestureHandlerOptions & { gestureTag?: number };
public pinchGestureOptions: PinchGestureHandlerOptions & { gestureTag?: number };
public rotationGestureOptions: RotationGestureHandlerOptions & { gestureTag?: number };

/**
* Sets a new data object for the chart. The data object contains all values
Expand Down
20 changes: 18 additions & 2 deletions src/charting/listener/PieRadarChartTouchListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Utils } from '../utils/Utils';
import { ChartGesture, ChartTouchListener } from './ChartTouchListener';
import { GestureHandlerStateEvent, GestureState, GestureStateEventData, HandlerType, Manager, RotationGestureHandler, TapGestureHandler } from '@nativescript-community/gesturehandler';

let TAP_HANDLER_TAG = 11232000;
let ROTATION_HANDLER_TAG = 11231000;

/**
* TouchListener for Pie- and RadarChart with handles all
* touch interaction.
Expand All @@ -20,22 +23,35 @@ export class PieRadarChartTouchListener extends ChartTouchListener<PieRadarChart
*
* @param chart instance of the chart
*/
TAP_HANDLER_TAG;
ROTATION_HANDLER_TAG;
constructor(chart: PieRadarChartBase<any, any, any>) {
super(chart);
this.TAP_HANDLER_TAG = TAP_HANDLER_TAG++;
this.ROTATION_HANDLER_TAG = ROTATION_HANDLER_TAG++;
}

getTapGestureOptions() {
return { gestureTag: this.TAP_HANDLER_TAG, ...(this.mChart.tapGestureOptions || {}) };
}
getRotationGestureOptions() {
return { gestureTag: this.ROTATION_HANDLER_TAG, ...(this.mChart.rotationGestureOptions || {}) };
}

getOrCreateRotationGestureHandler() {
if (!this.rotationGestureHandler) {
const manager = Manager.getInstance();
this.rotationGestureHandler = manager.createGestureHandler(HandlerType.ROTATION, 11231, {}).on(GestureHandlerStateEvent, this.onRotationGesture, this);
const options = this.getRotationGestureOptions();
this.rotationGestureHandler = manager.createGestureHandler(HandlerType.ROTATION, options.gestureTag, {}).on(GestureHandlerStateEvent, this.onRotationGesture, this);
}
return this.rotationGestureHandler;
}

getOrCreateTapGestureHandler() {
if (!this.tapGestureHandler) {
const manager = Manager.getInstance();
this.tapGestureHandler = manager.createGestureHandler(HandlerType.TAP, 11232, {}).on(GestureHandlerStateEvent, this.onTapGesture, this);
const options = this.getTapGestureOptions();
this.tapGestureHandler = manager.createGestureHandler(HandlerType.TAP, options.gestureTag, {}).on(GestureHandlerStateEvent, this.onTapGesture, this);
}
return this.tapGestureHandler;
}
Expand Down

0 comments on commit 6fb3b5d

Please sign in to comment.