Skip to content

Commit

Permalink
chore(demos): fix viewpager
Browse files Browse the repository at this point in the history
use-measure initially returns 0
  • Loading branch information
joshuaellis committed Apr 25, 2021
1 parent 1d1a2c5 commit c9288bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions demo/src/sandboxes/viewpager/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ const pages = [
function Viewpager() {
const index = useRef(0)
const [ref, { width }] = useMeasure()
const [props, api] = useSprings(pages.length, i => ({
x: i * width,
scale: 1,
display: 'block',
}))
const [props, api] = useSprings(
pages.length,
i => ({
x: i * width,
scale: width === 0 ? 0 : 1,
display: 'block',
}),
[width]
)
const bind = useDrag(({ active, movement: [mx], direction: [xDir], distance, cancel }) => {
if (active && distance > width / 2) {
index.current = clamp(index.current + (xDir > 0 ? -1 : 1), 0, pages.length - 1)
Expand Down
1 change: 1 addition & 0 deletions demo/src/sandboxes/viewpager/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ body,
#root {
height: 100%;
width: 100%;
overflow: hidden;
}

body {
Expand Down

0 comments on commit c9288bf

Please sign in to comment.