Skip to content

Commit

Permalink
Merge pull request #60 from canmertc/fix/ios_multiple_pie-radar_charts
Browse files Browse the repository at this point in the history
fix(ios): Use different gesture tags when there is multiple pie/radar charts
  • Loading branch information
farfromrefug authored Mar 4, 2024
2 parents 1673bf5 + 6fb3b5d commit df5fa2b
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 df5fa2b

Please sign in to comment.