Last active
July 6, 2019 05:22
-
-
Save natew/55d8e1ae1a739c75f0d7ebecc22c8698 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { animation, Button, Card, Geometry, Row, Title, View } from '@o/ui' | |
import React from 'react' | |
export const TestCarousel = () => { | |
const apps = [{ title: 'ok' }, { title: 'ok2' }, { title: 'ok3' }, { title: 'o4' }] | |
const carousel = animation(() => ({ | |
scrollLeft: 0, | |
zoomed: false, | |
})) | |
/** | |
* animation() is a helper, but desugars into props somewhat like: | |
* scrollLeft={spring(...)} | |
* animated | |
* lets us control it using .set without being fully controlled | |
*/ | |
return ( | |
<View width="100%" height="100%"> | |
<Button onClick={() => carousel.set(cur => ({ zoomed: !cur.zoomed }))}>zoom</Button> | |
<Button onClick={() => carousel.set(cur => ({ scrollLeft: 100 + cur.scrollLeft }))}> | |
scroll 100px right | |
</Button> | |
<Row flex={1} scrollable="x" space={100} {...carousel}> | |
{apps.map((app, index) => ( | |
<Geometry key={index}> | |
{geometry => ( | |
<Card | |
onClick={() => { | |
carousel.set({ | |
scrollLeft: geometry.offset(index), | |
}) | |
}} | |
onDoubleClick={() => { | |
carousel.set(current => ({ | |
scrollLeft: geometry.offset(index), | |
zoomed: !current.zoomed, | |
})) | |
}} | |
transform={{ | |
rotateY: () => (index - geometry.frame(index)) * 10, | |
scale: () => (carousel.zoomed ? 1 : Math.abs(geometry.frame(index))), | |
}} | |
> | |
<Title>{app.title}</Title> | |
</Card> | |
)} | |
</Geometry> | |
))} | |
</Row> | |
</View> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This one is simpler and a bit clearer: