From 89940105c4ee7521c07e9e4aa46b8441f492cd44 Mon Sep 17 00:00:00 2001 From: Vadim Dalecky Date: Sat, 24 Feb 2018 13:32:40 +0000 Subject: [PATCH] feat: add delay prop to and h(ShowDocs, {md: require('../../../docs/en/Overlay.md')})) + .add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/Render.md')})) .add('Defaults', () =>
{({value}) => @@ -21,9 +21,24 @@ storiesOf('Animation/Render', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', - top: (value * 100) - 100, + top: (value * 100), + left: 100 + }}>{value}
+ }
+ + ) + .add('Entry with delay', () => +
+ {({value}) => +
{value}
}
diff --git a/src/Render/index.ts b/src/Render/index.ts index 301b8205..bf268124 100644 --- a/src/Render/index.ts +++ b/src/Render/index.ts @@ -3,6 +3,7 @@ import {render, createEnhancer} from 'react-universal-interface'; import {h} from '../util'; export interface IRenderProps { + delay?: number; ms?: number; } @@ -17,6 +18,7 @@ export class Render extends Component { ms: 300 }; + timeout = null; frame = null; state = { @@ -26,6 +28,21 @@ export class Render extends Component { }; componentDidMount () { + const {delay} = this.props; + + if (delay) { + this.timeout = setTimeout(this.start, delay); + } else { + this.start(); + } + } + + componentWillUnmount () { + cancelAnimationFrame(this.frame); + clearTimeout(this.timeout); + } + + start = () => { const now = Date.now(); this.setState({ @@ -37,10 +54,6 @@ export class Render extends Component { }); } - componentWillUnmount () { - cancelAnimationFrame(this.frame); - } - onFrame = () => { const now = Date.now(); const value = Math.min((now - this.state.start) / this.props.ms, 1); diff --git a/src/RenderInterval/__story__/story.tsx b/src/RenderInterval/__story__/story.tsx index 472e66f6..5c02e061 100644 --- a/src/RenderInterval/__story__/story.tsx +++ b/src/RenderInterval/__story__/story.tsx @@ -6,26 +6,56 @@ import {RenderInterval} from '..'; import ShowDocs from '../../../.storybook/ShowDocs' storiesOf('Animation/RenderInterval', module) - // .add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/Overlay.md')})) + .add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/RenderInterval.md')})) .add('Defaults', () => -
- {({value}) => -
{value}
- }
-
- ) - .add('Entry animation', () => -
- {({value}) => -
{value}
- }
-
- ) +
+ {({value}) => +
{value}
+ }
+
+) +.add('Entry animation', () => +
+ {({value}) => +
{value}
+ }
+
+) +.add('Entry with delay', () => +
+ {({value}) => +
{value}
+ }
+
+) +.add('Custom fps', () => +
+ {({value}) => +
{value}
+ }
+
+) diff --git a/src/RenderInterval/index.ts b/src/RenderInterval/index.ts index 955e63e7..34d42f32 100644 --- a/src/RenderInterval/index.ts +++ b/src/RenderInterval/index.ts @@ -1,16 +1,13 @@ import {Component} from 'react'; import {render, createEnhancer} from 'react-universal-interface'; import {h} from '../util'; +import {IRenderProps, IRenderState} from '../Render'; -export interface IRenderIntervalProps { +export interface IRenderIntervalProps extends IRenderProps { fps?: number; - ms?: number; } -export interface IRenderIntervalState { - start?: number; - now?: number; - value?: number; +export interface IRenderIntervalState extends IRenderState { } export class RenderInterval extends Component { @@ -19,8 +16,9 @@ export class RenderInterval extends Component { const now = Date.now(); - this.delay = 1000 / this.props.fps; + this.interval = 1000 / this.props.fps; this.setState({ start: now, now, value: 0 }, () => { - this.timeout = setTimeout(this.onFrame, this.delay); + this.timeout = setTimeout(this.onFrame, this.interval); }); } componentDidUpdate (props) { if (props.fps !== this.props.fps) { - this.delay = 1000 / this.props.fps; + this.interval = 1000 / this.props.fps; } } componentWillUnmount () { clearTimeout(this.timeout); + clearTimeout(this.timeoutDelay); } onFrame = () => { @@ -59,7 +68,7 @@ export class RenderInterval extends Component { - this.timeout = setTimeout(this.onFrame, this.delay); + this.timeout = setTimeout(this.onFrame, this.interval); }; } diff --git a/src/Tween/__story__/story.tsx b/src/Tween/__story__/story.tsx index 5c51410b..43c8100b 100644 --- a/src/Tween/__story__/story.tsx +++ b/src/Tween/__story__/story.tsx @@ -25,7 +25,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -40,7 +40,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -55,7 +55,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -70,7 +70,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -85,7 +85,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -100,7 +100,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -115,7 +115,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -130,7 +130,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -145,7 +145,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -160,7 +160,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -175,7 +175,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -190,7 +190,7 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, position: 'relative', top: (value * 300), left: 100 @@ -205,7 +205,37 @@ storiesOf('Animation/Tween', module) width: 100, height: 100, background: 'tomato', - opacity: value, + opacity: .1 + .9 * value, + position: 'relative', + top: (value * 300), + left: 100 + }}>{value}
+ } + + ) + .add('With cubic-bezier', () => +
+ {({value}) => +
{value}
+ }
+
+ ) + .add('With delay', () => +
+ {({value}) => +
) - .add('With cubic-bezier', () => -
- {({value}) => -
{value}
- }
-
- )