DrChai / react-native-rheostat

inspired by Airbnb's rheostat, a powerful slider with assorted data visualized charts
MIT License
117 stars 18 forks source link

`cannot convert undefined value to object` #50

Open david98 opened 4 months ago

david98 commented 4 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-rheostat@1.0.2 for the project I'm working on.

Upon rendering the slider, the first sliding action would always fail with an exception cannot convert undefined value to object and the handle would not move. The component would then work as expected.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-rheostat/src/hoc/withRheostat.tsx b/node_modules/react-native-rheostat/src/hoc/withRheostat.tsx
index e4af925..c0086e3 100644
--- a/node_modules/react-native-rheostat/src/hoc/withRheostat.tsx
+++ b/node_modules/react-native-rheostat/src/hoc/withRheostat.tsx
@@ -162,7 +162,7 @@ const withRheostat = (ChartCompo: any = null) => React.memo((props: RheostatType
     const {
       width,
     } = containerSize;
-    const proposedPosition = (gestureState.dx / width) * PERCENT_FULL + previousHandlePos[idx];
+    const proposedPosition = (gestureState.dx / width) * PERCENT_FULL + (previousHandlePos ? previousHandlePos[idx] : idx * 100);
     const snapPosition = getSnapPosition(proposedPosition, idx);
     getNextState(idx, snapPosition);
     if (onValuesUpdated) onValuesUpdated(getPublicState());

This issue body was partially generated by patch-package.

DrChai commented 4 months ago

Thanks for your ticket! I haven't touched this project since the last version I released. Currently, all projects from myself and the company I work for have transitioned to native code. It seems that this bug may caused by recent changes in dependencies. I will try to upgrade all dependencies to the latest and address the issue. And pull requests are always welcome!

david98 commented 4 months ago

Thanks for your reply! I'm sorry if I didn't provide more details and/or a PR, but I will let you know that I have overridden the dependencies and I am using the latest versions. Everything is working just fine except for this small issue. I only tried the basic Rheostat though.

I'll see if I can assemble a Pr on Monday. Have a nice weekend 🙂