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.

SNAP event should support snapPoint(s)

See original GitHub issue

Like the issue #53 , Is there a way to know the snapPoint that triggers the SNAP event?

I want to perform an action whenever the snapPoint changes. I thought of triggering the action after ref.current.snapTo() but I realized dragging also fires the SNAP event.

Thanks for the library!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stipsancommented, Jan 24, 2021

You’re welcome 🙂

I’ll think about it, I don’t want to increase the complexity too much yet as I got some other ideas I want to explore first.

For now you could store a reference to the snap points yourself, and keep track of any other variable you need:

export default function Example() {
  const snapPointsRef = React.useRef([]);
  return (
    <BottomSheet
      snapPoints={({ minHeight, maxHeight }) => {
        const snapPoints = [minHeight, maxHeight];
        snapPointsRef.current = snapPoints;
        return snapPoints;
      }}
    />
  );
}

The snapPoints function is always called whenever any of its arguments changes. The only thing to remember is that the real snap points are filtered and do not contain illegal variables. In most cases this isn’t a problem, but should it turn out to be you could use the defaultSnap function to access snapPoints:

export default function Example() {
  const snapPointsRef = React.useRef([]);
  return (
    <BottomSheet
      defaultSnap={({ lastSnap, snapPoints }) => {
        snapPointsRef.current = snapPoints;
        return lastSnap || Math.max(...snapPoints);
      }}
    />
  );
}
0reactions
elitenoirecommented, Jan 24, 2021

Oh I didn’t see that, thanks. Okay what about accessing the defined snapPoints? Supposing my snapPoints are derived from the maxHeight and headerHeight , And I need to compare them in the SNAP event to the current snapPoint.

If I store the defined snapPoints in state, I’ll have to always update it whenever the sheet resizes I guess.

Maybe you could also expose the other params minHeight, maxHeight, footerHeight the same way as the height? Or even the snapPoints in a getter function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting the Snap Point - Steinberg Help
The snap point for an event is displayed as a vertical line in the Project window. Note. You can also set the snap...
Read more >
The set event snap point is not at the event start position
When the output audio is re imported into the audio project, the set event snap point is not at the event start position,...
Read more >
Snapping events and options enhancements for 4.x
Emit events when a snap is about to occur. Properties should include the location of the cursor, the snap point, the target layer, ......
Read more >
How to Use the Snap Function in Cubase | Q&A with Greg Ondo
What is the snap function available Cubase and how can it help you? Well Greg's there to elaborate on editing based on snap....
Read more >
Event Snap Point In Cubase - YouTube
How to use the Event Snap Point in Cubase to move audio events while aligning to beats and bars. ... Your browser can...
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