-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
afterChange is not triggered when adaptiveHeight is true #1262
Comments
So I changed it to "beforeChange()" |
Same issue here! |
I saw this before adding adaptiveHeight = true. My slides can have variable heights, and if the height of the img element changes the afterChange event fails to dispatch. If you add adaptiveHeight=true, it gets exponentially worse. |
it looks like the animationEndCallback is never executed under these conditions - haven't found where it should be executed from yet |
So I figured out why this happen in our case. We use What happens in library is that when slide is moved, slider height is changed to accomodate for higher/shorter slide height, this triggers window resize (in our case) and I'm not sure how to fix this as I'm not sure why |
Oh wow I struggled with this for about an hour before I stumbled upon this thread. After reading this, let me share with you the workaround I used: const speed: number = 500;
const settings: Settings = {
adaptiveHeight: true,
// NOTE: afterChange is broken when adaptiveHeight is set to true. See:
// https://github.com/akiran/react-slick/issues/1262. Therefoe this hacky solution.
beforeChange: (current, next) =>
setTimeout(() => this.setState(prevState => ({ ...prevState, currentSlide: next })), speed),
speed
}; |
I debugged the issue a little bit and the problem is that the callback to this timeout: react-slick/src/inner-slider.js Line 397 in 93c37bd
is not executing because during the wait period react-slick/src/inner-slider.js Lines 213 to 214 in 93c37bd
The react-slick/src/inner-slider.js Line 84 in 93c37bd
|
Here's what worked for me, just include this in your settings object:
|
Damn... took me a while to figure this out. Is anyone working on a proper solution to this issue? Btw, this only seems to be a problem in cases where custom buttons are used for the navigation that utilizes the next / prev methods. The default buttons provided by the slider works fine even if Here's my own sandbox if anyone is interested https://codesandbox.io/s/mykn4lq78j. |
Any update on this issue? The workaround does not work for me. |
So I've found a workaround now. The slider in my application needs to keep track of the slider's dragging state because whether the user swipes or not depends on if the item in the slider is clickable. The items are only clickable if the user does not swipe. constructor(props, context) {
super(props, context);
// set states in constructor
this.state = {
dragging: false,
hasAdaptiveHeight: true
};
}
render() {
const settings = {
adaptiveHeight: this.state.hasAdaptiveHeight,
beforeChange: (current, next) => {
this.setState({ dragging: true }, () => {
if (this.state.hasAdaptiveHeight) {
setTimeout(() => {
this.setState({ dragging: false });
}, 1000);
}
});
},
afterChange: next => {
// this is only called if adaptiveHeight is set to false
this.setState({ dragging: false });
}
}
return (
<Slider {...settings}>
// your items here
</Slider>
);
} |
This work arounds perfectly works on me, thanks :) |
…en adaptiveHeight is true see [Issue](akiran/react-slick#1262)
We just ran into this, especially on Safari 13. In our case, we're not using adaptiveHeight but changes in the slider coincide with changes in flow elsewhere on the page (e.g. we're using the slider as a timeline component, below which other content appears based on what slide of the timeline is selected). So, perhaps a better title for this issue should be that "afterChange does not get called if slider animation causes page dimensions to change". |
This does not completely solve the issue as the transition is not working with this approach. Are there any updates on this issue? |
https://codesandbox.io/s/k6n066ox5
The text was updated successfully, but these errors were encountered: