Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touchpad scrolling is very fast and broke timeline #929

Open
serhiimahdiuk opened this issue Apr 6, 2024 · 0 comments
Open

Touchpad scrolling is very fast and broke timeline #929

serhiimahdiuk opened this issue Apr 6, 2024 · 0 comments

Comments

@serhiimahdiuk
Copy link

serhiimahdiuk commented Apr 6, 2024

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

because the touchpad is on Mac, I guess, to quickly update the onScroll function, I tried to fix this with https://stackoverflow.com/a/5542105/23627578 - this helper function

Here is the diff that solved my problem:

diff --git a/node_modules/react-calendar-timeline/lib/lib/scroll/ScrollElement.js b/node_modules/react-calendar-timeline/lib/lib/scroll/ScrollElement.js
index ead0a36..6ec9bd2 100644
--- a/node_modules/react-calendar-timeline/lib/lib/scroll/ScrollElement.js
+++ b/node_modules/react-calendar-timeline/lib/lib/scroll/ScrollElement.js
@@ -65,8 +65,34 @@ function (_Component) {
       }
     });
 
+    function detectTrackPad(e) {
+      let isTrackpad = false;
+      if (e.wheelDeltaY) {
+        if (Math.abs(e.wheelDeltaY) !== 120) {
+          isTrackpad = true;
+        }
+      }
+      else if (e.deltaMode === 0) {
+        isTrackpad = true;
+      }
+      return isTrackpad
+    }
+
     _defineProperty(_assertThisInitialized(_this), "handleWheel", function (e) {
-      var traditionalZoom = _this.props.traditionalZoom; // zoom in the time dimension
+      e.preventDefault();
+      var traditionalZoom = _this.props.traditionalZoom; 
+     if(detectTrackPad(e)){
+      const wheelDistance = function(evt){
+        if (!evt) evt = event;
+        var w=evt.wheelDeltaX, d=evt.detail;
+        if (d){
+          if (w) return w/d/40*d>0?1:-1; 
+          else return -d/3;              
+        } else return w/120;             
+      };
+      _this.props.onScroll(_this.scrollComponent.scrollLeft + (wheelDistance(e) * -20))
+     }
+      
 
       if (e.ctrlKey || e.metaKey || e.altKey) {
         e.preventDefault();
@@ -78,6 +104,7 @@ function (_Component) {
       } else if (e.shiftKey) {
         e.preventDefault(); // shift+scroll event from a touchpad has deltaY property populated; shift+scroll event from a mouse has deltaX
        
+        
         _this.props.onScroll(_this.scrollComponent.scrollLeft + (e.deltaY || e.deltaX)); // no modifier pressed? we prevented the default event, so scroll or zoom as needed
 
       }

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant