Browse Source

yet another buggy version like for prod

Ivan Asmer 3 years ago
parent
commit
886cc1cc1e
1 changed files with 6 additions and 13 deletions
  1. 6 13
      src/SliderSiblingOnly.js

+ 6 - 13
src/SliderSiblingOnly.js

@@ -113,6 +113,7 @@ export default ({images = [], imgWidth=377, className, onChange, onClick, ref, s
                     imgs.current[1].src   = currentImages[1]
                     imgs.current[2].src   = currentImages[2]
                     containerRef.current.scrollTo({left: imgWidth, behavior: 'auto'})
+                    onChange(newCurrent)
 
                     //afterAutoscroll.current = true
                 }
@@ -123,7 +124,7 @@ export default ({images = [], imgWidth=377, className, onChange, onClick, ref, s
 
 
                 console.log(diffRef.current, newCurrent)
-            }, 500)
+            }, 200)
             return;
         }
 
@@ -147,20 +148,12 @@ export default ({images = [], imgWidth=377, className, onChange, onClick, ref, s
             const clickX                    = e.clientX -e.target.getBoundingClientRect().x 
             const {scrollLeft}              = containerRef.current;
             if (clickX > viewPortWidth * 0.75) {
-                if (i < images.length -1){
-                    currentScrollPosition.current = scrollLeft + (imgs?.[i].getBoundingClientRect().width || 0)
-                    setCurrent(i +1)
-                    scrollToCurrent()
-                    if (typeof onChange === 'function') onChange(i +1)
-                }
+                containerRef.current.scrollTo({left: scrollLeft + imgWidth*0.7, behavior: 'auto'})
+                onTouchEnd()
             }
             else if (clickX < viewPortWidth * 0.25) {
-                if (i > 0){
-                    currentScrollPosition.current = scrollLeft - (imgs?.[i-1].getBoundingClientRect().width || 0)
-                    setCurrent(i -1)
-                    scrollToCurrent()
-                    if (typeof onChange === 'function') onChange(i -1)
-                }
+                containerRef.current.scrollTo({left: scrollLeft - imgWidth*0.7, behavior: 'auto'})
+                onTouchEnd()
             }
             else if (typeof onClick === 'function'){
                 onClick(i)