Skip to content

Updating animation swipe duration from a custom toolbar button #293

Answered by igordanchenko
SenshiSentou asked this question in Q&A
Discussion options

You must be logged in to vote

Hi there! Unless you are building a reusable plugin, there is an easier way to implement this. You just need to create a state variable to store your swipe duration and read the initial value in a layout effect. You can add your custom button through the toolbar.buttons prop.

const [swipe, setSwipe] = useState(400);

useLayoutEffect(() => {
  const swipeValue = localStorage.getItem("swipe");
  if (swipeValue) {
    setSwipe(Number.parseInt(swipeValue, 10));
  }
}, []);

const toggleSwipe = () => {
  const swipeValue = swipe === 0 ? 400 : 0;
  setSwipe(swipeValue);
  localStorage.setItem("swipe", `${swipeValue}`);
};

// ...

<Lightbox
  // ...
  animation={{ swipe }}
  toolbar={{
    buttons

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SenshiSentou
Comment options

Answer selected by SenshiSentou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants