question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onDraging slides doesn't return index of new visible element.

See original GitHub issue

Describe the feature you’d like: Currently, there is no good way of selecting a new slide on when you finish dragging on a tablet or phone. Add some property which will control which slide is visible now. Because all workarounds have a lot of bugs.

Suggested implementation: When on drag is finished and only when a new screen is shown return to a user index of a new visible slide

Describe alternatives you’ve considered: this code is working but it is kinda clunky

onTransitionEnd={ () => {
  if (!isOnDesktop) {
  const visible = document.querySelector('.videoSlider .carousel__slide--visible .video');
  console.log(visible);
  items.forEach(({ id: vId }, i) => {
    if (vId === visible) {
     console.log(i, 'i', vId);
      handleChangeVideo(i);
     }
  });
  console.log(items, visible.id, 'visible');
  }
} }

Teachability, Documentation, Adoption, Migration Strategy: onDragSlideEnd return an index of a new slide or return -1 if the slide has not changed.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
jimlowreycommented, Jan 15, 2020

@vignitres I believe this can be done with an HOC inside the CarouselProvider. Add a callback to the resulting HOC and it will get passed to your wrapped component. The wrapped component will have access to the props that the HOC provides your component.

import { WithStore } from 'pure-react-carousel';
import { CarouselProvider} from 'pure-react-carousel';

class Listener extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidUpdate() {
        if ( this.props.updatePlace) {
            this.props.updatePlace(this.props.currentSlide);
        }
    }
    render() {
          return null;
    }
}

const WrappedListener = WithStore(Listener, (state) => {
    return {
        currentSlide: state.currentSlide
    };
});

then the component rendering would have something like this,

updatePlace(place) {
  //process place
}
render() {
  return (
  ...
  <CarouselProvider ... >
         <WrappedListener updatePlace={this.updatePlace.bind(this)}/>
         //etc...
  </CarouselProvider>
  ...
  );
}
4reactions
vignitrescommented, Jan 16, 2020

@vignitres I believe this can be done with an HOC inside the CarouselProvider. Add a callback to the resulting HOC and it will get passed to your wrapped component. The wrapped component will have access to the props that the HOC provides your component.

import { WithStore } from 'pure-react-carousel';
import { CarouselProvider} from 'pure-react-carousel';

class Listener extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidUpdate() {
        if ( this.props.updatePlace) {
            this.props.updatePlace(this.props.currentSlide);
        }
    }
    render() {
          return null;
    }
}

const WrappedListener = WithStore(Listener, (state) => {
    return {
        currentSlide: state.currentSlide
    };
});

then the component rendering would have something like this,

updatePlace(place) {
  //process place
}
render() {
  return (
  ...
  <CarouselProvider ... >
         <WrappedListener updatePlace={this.updatePlace.bind(this)}/>
         //etc...
  </CarouselProvider>
  ...
  );
}

Yes! I managed to do that a few days ago. I guess I’m just used to dealing with this using events, but for some odd reason, this solution just feels right.

Thanks anyways!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detecting value of selected Draggable Item - GSAP - GreenSock
For some reason, I can't figure out how to access the id of the selected element in order to use the value in...
Read more >
Problem with slide show in Javascript. Slide index does't work
I try to create a slideshow with an active dot while a slide is visible. Unfortunately when I use slideIndex-1 or slideIndex+1 the...
Read more >
ASP.NET Core Blazor event handling - Microsoft Learn
Learn about Blazor's event handling features, including event argument types, event callbacks, and managing default browser events.
Read more >
5 Loading Web pages — HTML5 - W3C
When a Window object is indexed to retrieve an indexed property index , the value returned must be the WindowProxy object of the...
Read more >
Gestures and Touch Events | CodePath Android Cliffnotes
setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // Interpret MotionEvent data // Handle touch here ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found