maxmarinich / react-alice-carousel

React responsive component for building content galleries, content rotators and any React carousels
MIT License
832 stars 91 forks source link

onUpdate callback? #294

Closed bogdancss closed 11 months ago

bogdancss commented 11 months ago

We have a check that disables the prev/next carousel buttons based on isNextSlideDisabled and isPrevSlideDisabled from the carousel EventObject. I get access to this event in the onResized and onInitialized methods which works fine on init or resize.

However we have the ability to add/remove items after init - when we add/remove am item to/from the carousel, we need to update the prev/next buttons. Obviously the onResized and onInitialized methods are not triggered here, so there is no way to determine if these buttons should be active or not.

I noticed the UPDATE event is there, just there is not way to subscribe to it:

enum EventType {
  ACTION = 'action', // used if a general user action (button click or swipe)
  INIT = 'init',     // used if the initial event was triggered
  RESIZE = 'resize', // used if the gallery size was changed
  UPDATE = 'update', // used if the gallery was updated with props (activeIndex)
}
maxmarinich commented 11 months ago

Hi, @bogdancss! EventType.UPDATE fires when you have changed the activeIndex property (the gallery has been moved programmatically, without using a button action).

If you add/remove elements, you know what you are doing and what happened. Accordingly you can call callback after those actions.

It possible to reopen the issue with feature request label if you don't resolve your case.

bogdancss commented 11 months ago

@maxmarinich I get that, but I need the carousel to trigger an update method to update the isNextSlideDisabled and isPrevSlideDisabled props based on the new number of items

bogdancss commented 11 months ago

@maxmarinich - can you get back to the question above?

bogdancss commented 11 months ago

@maxmarinich we really this this addressed - is there a solution?

bogdancss commented 11 months ago

we have the carousel not render the prev/next buttons when it's not the case to (the number of items fits within the current view) also, we have the buttons disabled based on isNextSlideDisabled and isPrevSlideDisabled props the carousel provides.

However, the moment the number of items changes so that there are more than the current view fits we want the prev/next buttons to render. The only way to make the buttons show up after you add an item, is to resize, which in turn triggers the isNextSlideDisabled isPrevSlideDisabled to update.

There should be a way to do this onUpdate and not just onResize or onInit

maxmarinich commented 11 months ago

Added at v2.8.0 see https://maxmarinich.github.io/react-alice-carousel/#events