import React from 'react'; import { Animation, interpolate } from '@douyinfe/semi-animation-react'; const styles = { container: { height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', willChange: 'background', }, shape: { width: 300, height: 300, willChange: 'transform' }, }; export default class SimpleAnimation extends React.Component { state = { toggle: true }; toggle = () => { this.setState(state => ({ toggle: !state.toggle })); if (this.handler && this.handler.reverse) { this.handler.reverse(); this.handler.start(); } }; render() { const shapeFrom = [20, 380, 380, 380, 380, 380, 200, 20, 20, 380]; const shapeTo = [20, 20, 20, 380, 380, 380, 380, 20, 20, 20]; const prefixes = ['M', ',', ' L', ',', ' L', ',', ' L', ',', ' L', ',']; return ( (this.handler = handler)} onRest={() => { if (this.handler) { this.handler.reverse(); this.handler.start(); } }} // to={{ // coords: toggle ? [0, 0] : [50, 50], // color: toggle ? '#247BA0' : '#70C1B3', // start: toggle ? '#B2DBBF' : '#B2DBBF', // end: toggle ? '#247BA0' : '#F3FFBD', // scale: toggle ? 0.3 : 0.4, // shape: toggle ? TRIANGLE : RECTANGLE, // stop: toggle ? '0%' : '50%', // rotation: toggle ? '0deg' : '45deg', // }} > {({ value }) => { const ratio = value / 50; // hsl(48, 16%, 57%) => hsl(71, 100%, 87%) const start = `hsl(${(71 - 48) * ratio + 48}, ${(100 - 16) * ratio + 16}%, ${(87 - 57) * ratio + 57}%)`; const stop = `${value}%`; const end = `hsl(${value * 5 + 50}, 90%, 60%)`; // hsl(170, 40%, 60%) => hsl(198, 63%, 38%) // const color = `hsl(${value * 6 + 40}, 90%, 60%)`; const color = `hsl(${(198 - 170) * ratio + 170}, ${(63 - 40) * ratio + 40}%, ${(38 - 60) * ratio + 60}%)`; const scale = 0.1 * ratio + 0.3; const rotation = 45 * ratio + 'deg'; const coords = [value, value]; const shape = interpolate(shapeFrom, shapeTo, ratio) .map((v, idx) => '' + (prefixes[idx] || '') + v) .join('') + ' Z'; return (
); }}
); } }