You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By refactoring out the useEffect mess and replacing it with a proper state machine the following improvements were made:
- new event type `SNAP`, fired whenever transitioning to a snap point. Usually when dragging ends, or when `ref.snapTo` got called.
- new data attribute added: `data-rsbs-state`, it can be set to any of `closed | opening | open | dragging | snapping | resizing | closing`.
- resize events can no longer happen while closing, fixing a bug in Android when closing a bottom sheet with a soft keyboard active.
Copy file name to clipboardExpand all lines: README.md
+13-6Lines changed: 13 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,13 +140,13 @@ iOS Safari, and some other mobile culprits, can be tricky if you're on a page th
140
140
141
141
## Events
142
142
143
-
All events receive `SprinngEvent` as their argument. It has a single property, `type`, which can be `'OPEN'|'RESIZE'|'CLOSE'` depending on the scenario.
143
+
All events receive `SprinngEvent` as their argument. It has a single property, `type`, which can be `'OPEN'|'RESIZE'|'SNAP'|'CLOSE'` depending on the scenario.
144
144
145
145
### onSpringStart
146
146
147
147
Type: `(event:SpringEvent) =>void`
148
148
149
-
Fired on: `OPEN|RESIZE|CLOSE`.
149
+
Fired on: `OPEN|RESIZE|SNAP|CLOSE`.
150
150
151
151
If you need to delay the open animation until you're ready, perhaps you're loading some data and showing an inline spinner meanwhile. You can return a Promise or use an async function to make the bottom sheet wait for your work to finish before it starts the open transition.
152
152
@@ -170,8 +170,6 @@ function Example() {
170
170
}
171
171
```
172
172
173
-
The `CLOSE` event also supports async/await and promises, if you need to delay the close transition. The `RESIZE` event does not await on anything, but nothing bad will happen if you give it an async function.
174
-
175
173
### onSpringCancel
176
174
177
175
Type: `(event:SpringEvent) =>void`
@@ -185,18 +183,27 @@ In order to be as fluid and delightful as possible, the open state can be interr
185
183
- the user swipes the sheet below the fold, triggering an `onDismiss` event.
186
184
- the user hits the `esc` key, triggering an `onDismiss` event.
187
185
- the parent component sets `open` to `false` before finishing the animation.
186
+
- a `RESIZE` event happens, like when an Android device shows its soft keyboard when an text editable input receives focus, as it changes the viewport height.
188
187
189
188
#### CLOSE
190
189
191
190
If the user reopens the sheet before it's done animating it'll trigger this event. Most importantly though it can fire if the bottom sheet is unmounted without enough time to clean animate itself out of the view before it rolls back things like `body-scroll-lock`, `focus-trap` and more. It'll still clean itself up even if React decides to be rude about it. But this also means that the event can fire after the component is unmounted, so you should avoid calling setState or similar without checking for the mounted status of your own wrapper component.
192
191
192
+
#### RESIZE
193
+
194
+
Fires whenever there's been a window resize event, or if the header, footer or content have changed its height in such a way that the valid snap points have changed. In the future (#53) you'll be able to differentiate between what triggered the resize.
195
+
196
+
#### SNAP
197
+
198
+
Fired after dragging ends, or when calling `ref.snapTo`, and a transition to a valid snap point is happening.
199
+
193
200
### onSpringEnd
194
201
195
202
Type: `(event:SpringEvent) =>void`
196
203
197
204
Fired on: `CLOSE`.
198
205
199
-
The `yin` to `onSpringStart`'s `yang`. It has the same characteristics. `RESIZE` don't mind if you give it an async function, but it also won't wait for it to finish before carrying on with the resizing. `OPEN` is siding with `RESIZE` on this one too while `CLOSE` still supports awaiting on async work. For `CLOSE` it gives you a hook into the step right after it has cleaned up everything after itself, and right before it unmounts itself. This can be useful if you have some logic that needs to perform some work before it's safe to unmount.
206
+
The `yin` to `onSpringStart`'s `yang`. It has the same characteristics. Including `async/await` and Promise support for delaying a transition. For `CLOSE` it gives you a hook into the step right after it has cleaned up everything after itself, and right before it unmounts itself. This can be useful if you have some logic that needs to perform some work before it's safe to unmount.
Same signature as the `defaultSnap` prop, calling it will animate the sheet to the new snap point you return. You can either call it with a number, which is the height in px (it'll select the closest snap point that matches your value): `ref.current.snapTo(200)`. Or:
217
224
218
225
```js
219
-
ef.current.snapTo(({ // Showing all the available props
226
+
ref.current.snapTo(({ // Showing all the available props
Copy file name to clipboardExpand all lines: pages/_app.tsx
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,24 @@
1
+
import{inspect}from'@xstate/inspect'
1
2
importtype{InferGetStaticPropsType}from'next'
2
3
importtype{AppProps}from'next/app'
3
4
importHeadfrom'next/head'
4
5
import{capitalize}from'../docs/utils'
6
+
import{debugging}from'../src/utils'
5
7
6
8
import'../docs/style.css'
7
9
import'../src/style.css'
8
10
11
+
// Setup xstate debugging, but only when in dev mode
12
+
if(debugging){
13
+
inspect({
14
+
url: 'https://statecharts.io/inspect',
15
+
iframe: false,
16
+
})
17
+
console.log(
18
+
'@xstate/inspect setup and running! Open https://statecharts.io/inspect in another tab to see the nitty gritty details. It also works with the Redux DevTools, but it lacks chart visualization.'
19
+
)
20
+
}
21
+
9
22
exportasyncfunctiongetStaticProps(){
10
23
const[
11
24
{ version, description, homepage, name, meta ={}},
0 commit comments