Skip to content
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

SNAP event should support snapPoint(s) #87

Closed
elitenoire opened this issue Jan 21, 2021 · 6 comments
Closed

SNAP event should support snapPoint(s) #87

elitenoire opened this issue Jan 21, 2021 · 6 comments
Labels
enhancement New feature or request released

Comments

@elitenoire
Copy link

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!

@stipsan
Copy link
Owner

stipsan commented Jan 21, 2021

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

Stay tuned 👍

@stipsan stipsan added the enhancement New feature or request label Jan 21, 2021
stipsan added a commit that referenced this issue Jan 21, 2021
github-actions bot pushed a commit that referenced this issue Jan 21, 2021
# [3.2.0](v3.1.4...v3.2.0) (2021-01-21)

### Bug Fixes

* better velocity physics ([65390c7](65390c7))
* only animate on RESIZE if the source = element ([ceb3671](ceb3671))
* use layout effect to prevent tearing on Safari ([6b62559](6b62559))

### Features

* add height getter to ref ([51c8510](51c8510))
* add source to RESIZE events ([383e206](383e206)), closes [#53](#53)
* override source and velocity in snapTo ([1afe79f](1afe79f))
* SNAP events now have `source` ([240c212](240c212)), closes [#87](#87)
@github-actions
Copy link

🎉 This issue has been resolved in version 3.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@elitenoire
Copy link
Author

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.

@stipsan
Copy link
Owner

stipsan commented Jan 23, 2021

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

@elitenoire
Copy link
Author

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.

@stipsan
Copy link
Owner

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

github-actions bot pushed a commit to la55u/react-spring-bottom-sheet-updated that referenced this issue Jun 18, 2023
# 1.0.0 (2023-06-18)

### Bug Fixes

* add 18 to react peer dep ([d89c0bb](d89c0bb))
* add CSS sourcemap ([04bf99f](04bf99f))
* add keywords ([05f4399](05f4399))
* add more NaN type guards ([7664d1a](7664d1a))
* API cleanup ([dc2b126](dc2b126))
* avoid dividing by zero during prerender ([ca2b9ae](ca2b9ae))
* better type declarations ([c19dd44](c19dd44))
* better velocity physics ([65390c7](65390c7))
* can be clicked through the overlay on IOS ([b9a2d95](b9a2d95))
* **deps:** bump focus-trap ([a099a54](a099a54))
* **deps:** update dependency @reach/portal to ^0.13.0 ([stipsan#94](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/94)) ([1cc8056](1cc8056))
* **deps:** update dependency focus-trap to v6.2.2 ([9f79d35](9f79d35))
* doh, semantic release pushed v1.0 instead of v0.2 :( ([a5837bd](a5837bd))
* dragging can overshoot if onDismiss is undefined ([stipsan#43](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/43)) ([549ab30](549ab30))
* export prop types ts definitions ([36cf999](36cf999))
* fade out correctly on snap ([17234bc](17234bc))
* filter out taps on drag ([bc709a0](bc709a0))
* guard against NaN in minSnap and maxSnap handlers ([7dbf037](7dbf037))
* improve rubber band effect when out of bounds ([stipsan#29](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/29)) ([4f2fe09](4f2fe09))
* improve TS definitions ([a8102bf](a8102bf))
* iOS display cutouts caused a scrollbar in some cases ([45c182c](45c182c))
* make open transitions more interruptible on iOS ([stipsan#23](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/23)) ([f898dd0](f898dd0))
* microbundle defaults to preact, changed it back to react ([4f52355](4f52355))
* more stable defaultSnap RESIZE sync ([230dbe2](230dbe2))
* only animate on RESIZE if the source = element ([ceb3671](ceb3671))
* readjust defaultSnap on resize ([b812786](b812786))
* remove padding wrappers ([stipsan#57](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/57)) ([60657fb](60657fb))
* RESIZE should never animate the content opacity ([2470ccc](2470ccc))
* rewrite interpolations to always be in frame sync ([cc43467](cc43467))
* TS in microbundle breaks on [...(new Set)], swapping to Array.from ([2402b5a](2402b5a))
* update readme ([ceb55d3](ceb55d3))
* updated readme with more API docs and examples ([6a48fab](6a48fab))
* use layout effect to prevent tearing on Safari ([6b62559](6b62559))
* use rAF instead of timeout to schedule unmount ([7f3c018](7f3c018))
* v2 api ready, just need to clean up and write docs ([96f158e](96f158e))
* xstate deprecation warning on null events ([e44e273](e44e273))

### Features

* add height getter to ref ([51c8510](51c8510))
* Add RESIZE events ([b3ff691](b3ff691))
* add sibling prop support ([767215b](767215b))
* add skipInitialTransition to make skipping opt-in ([f200ad0](f200ad0))
* add source to RESIZE events ([383e206](383e206)), closes [stipsan#53](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/53)
* add springConfig prop ([1a96832](1a96832))
* allow the developer to disable focus trap ([stipsan#138](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/138)) ([ef176b3](ef176b3))
* expand on content drag ([stipsan#141](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/141)) ([ec733a5](ec733a5))
* initial version ([ef3ecfa](ef3ecfa))
* override source and velocity in snapTo ([1afe79f](1afe79f))
* refactor to xstate ([stipsan#46](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/46)) ([6b2f92a](6b2f92a))
* SNAP events now have `source` ([240c212](240c212)), closes [stipsan#87](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/87)
* V2 ([stipsan#17](https://github.com/la55u/react-spring-bottom-sheet-updated/issues/17)) ([8331800](8331800))

### BREAKING CHANGES

* The resize observer logic is rewritten to no longer require wrapper elements like `[data-rsbs-footer-padding]`. If you're not using custom CSS and are simply importing `react-spring-bottom-sheet/dist/style.css` in your app then this isn't a breaking change for you.

If you're using custom CSS, here's the breaking changes:
- `[data-rsbs-header-padding]` removed, update selectors to `[data-rsbs-header]`
- `[data-rsbs-content-padding]` removed, update selectors to `[data-rsbs-scroll]`
- `[data-rsbs-footer-padding]` removed, update selectors to `[data-rsbs-footer]`
- `[data-rsbs-antigap]` removed, update selectors to `[data-rsbs-root]:after` and make sure to add `content: '';`.
- `[data-rsbs-content]` is changed, update selectors to `[data-rsbs-scroll]`.
- The `<div style="overflow:hidden;">` wrapper that used to be between `[data-rsbs-content]` and `[data-rsbs-content-padding]` is now within `[data-rsbs-scroll]`, and no longer hardcode `overflow: hidden`, add `[data-rsbs-content] { overflow: hidden; }` to your CSS.
* this is the real initial release, `v1` is fake software.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

No branches or pull requests

2 participants