Skip to content

Commit

Permalink
feat: fix haptics
Browse files Browse the repository at this point in the history
  • Loading branch information
osdnk committed Sep 20, 2021
1 parent f8da3e9 commit eb9c828
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/charts/linear/ChartPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Platform } from 'react-native';
import { LongPressGestureHandler } from 'react-native-gesture-handler';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import Animated, {
runOnJS,
useAnimatedGestureHandler,
useAnimatedStyle,
useDerivedValue,
Expand All @@ -26,8 +27,8 @@ import { svgBezierPath } from '../../smoothing/smoothSVG';

function impactHeavy() {
'worklet';
(Animated.runOnJS
? Animated.runOnJS(ReactNativeHapticFeedback.trigger)
(runOnJS
? runOnJS(ReactNativeHapticFeedback.trigger)
: ReactNativeHapticFeedback.trigger)('impactHeavy');
}

Expand Down Expand Up @@ -108,6 +109,7 @@ function setoriginalXYAccordingToPosition(
// prevent the following error on android:
// java.lang.RuntimeException: undefined is not an object (evaluating 'data.value[idx].originalX')
// why data.value = [] sometimes onActive?
// eslint-disable-next-line no-console
console.warn('No data available for chart', data.value.length, idx);
return;
}
Expand Down Expand Up @@ -219,7 +221,7 @@ export default function ChartPathProvider({
const [parsedoriginalData, newExtremes] = parse(
data.nativePoints || data.points
);
setContextValue((prev) => ({ ...prev, ...newExtremes, data }));
setContextValue(prev => ({ ...prev, ...newExtremes, data }));
setExtremes(newExtremes);
if (prevData.value.length !== 0) {
valuesStore.current.prevData = currData.value;
Expand Down Expand Up @@ -262,7 +264,7 @@ export default function ChartPathProvider({
const isStarted = useSharedValue(false, 'isStarted');

const onLongPressGestureEvent = useAnimatedGestureHandler({
onActive: (event) => {
onActive: event => {
state.value = event.state;
if (!currData.value || currData.value.length === 0) {
return;
Expand Down Expand Up @@ -340,7 +342,7 @@ export default function ChartPathProvider({
);
positionX.value = eventX;
},
onCancel: (event) => {
onCancel: event => {
isStarted.value = false;
state.value = event.state;
originalX.value = '';
Expand All @@ -358,7 +360,7 @@ export default function ChartPathProvider({
);
}
},
onEnd: (event) => {
onEnd: event => {
isStarted.value = false;
state.value = event.state;
originalX.value = '';
Expand All @@ -380,7 +382,7 @@ export default function ChartPathProvider({
impactHeavy();
}
},
onFail: (event) => {
onFail: event => {
isStarted.value = false;
state.value = event.state;
originalX.value = '';
Expand All @@ -398,7 +400,7 @@ export default function ChartPathProvider({
);
}
},
onStart: (event) => {
onStart: event => {
// WARNING: the following code does not run on using iOS, but it does on Android.
// I use the same code from onActive except of "progress.value = 1" which was taken from the original onStart.
state.value = event.state;
Expand Down
2 changes: 1 addition & 1 deletion src/interpolations/bSplineInterpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BSpline {
seqAt(dim) {
let points = this.points;
let margin = this.degree + 1;
return function(n) {
return function (n) {
if (n < margin) {
return points[0][dim];
} else if (points.length + margin <= n) {
Expand Down

0 comments on commit eb9c828

Please sign in to comment.