Skip to content

Instantly share code, notes, and snippets.

@asci
Created October 17, 2018 10:58
Show Gist options
  • Save asci/05bedfafd3e5bf4edb6083974c0b465e to your computer and use it in GitHub Desktop.
Save asci/05bedfafd3e5bf4edb6083974c0b465e to your computer and use it in GitHub Desktop.
Framer X connected components
import * as React from 'react';
import { animate } from 'framer';
// This is shared data, it should be imported
import { data } from './Examples';
export class Button extends React.Component {
render() {
return (
<div
style={style}
onClick={() => {
// The same code that is in Examples.RotateTrigger.onTap
animate.spring(data.rotation, data.rotation.get() + 90, {
tension: 250,
friction: 20,
});
}}
>
Rotate from code
</div>
);
}
}
// just styling, not important
const style: React.CSSProperties = {
backgroundColor: '#1199EE',
borderRadius: 11,
fontFamily: 'SF Pro Text',
fontSize: 14,
color: 'white',
padding: '10px',
minWidth: 126,
height: 43,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
boxShadow: '0px 2px 5px 0px rgba(0,0,0,0.25)',
overflow: 'visible',
};
import { Data, animate, Override, Animatable } from 'framer';
export const data = Data({ rotation: Animatable(0) });
export const RotateValue: Override = () => {
return {
rotation: data.rotation,
};
};
export const RotateTrigger: Override = props => {
data.rotation.set(props.rotation);
return {
onTap() {
animate.spring(data.rotation, data.rotation.get() + 90, {
tension: 250,
friction: 20,
});
},
};
};
@asci
Copy link
Author

asci commented Oct 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment