Giter Site home page Giter Site logo

Comments (6)

stipsan avatar stipsan commented on May 12, 2024 1

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);
      }}
    />
  );
}

from react-spring-bottom-sheet.

stipsan avatar stipsan commented on May 12, 2024

Hi! There isn't a way to do that atm but I'll add it 😄

Stay tuned 👍

from react-spring-bottom-sheet.

github-actions avatar github-actions commented on May 12, 2024

🎉 This issue has been resolved in version 3.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

from react-spring-bottom-sheet.

elitenoire avatar elitenoire commented on May 12, 2024

Thanks for looking into this but your release solves a different issue.

MY USE CASE:
I'm using two snapPoints to fake open and close the bottomsheet.
When SNAP event is detected, depending on what snapPoint the bottomsheet snaps to (doesn't matter the source),
I want to change my app state accordingly (min snapPoint - closed, max snapPoint - open).

Hence, I will like the snapPoint to be exposed or be a payload of the SNAP event.

Thanks again.

from react-spring-bottom-sheet.

stipsan avatar stipsan commented on May 12, 2024

Hey, you can access the current snap point on ref.current.height :)

from react-spring-bottom-sheet.

elitenoire avatar elitenoire commented on May 12, 2024

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.

from react-spring-bottom-sheet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.