diff --git a/package.json b/package.json index 3de00a11..8ad2f02d 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name": "react-content-loader", - "version": "5.0.1", "description": "SVG-Powered component to easily create placeholder loadings (like Facebook cards loading)", "repository": { "type": "git", diff --git a/src/native/Svg.tsx b/src/native/Svg.tsx index 66e50f13..19d49de1 100644 --- a/src/native/Svg.tsx +++ b/src/native/Svg.tsx @@ -10,9 +10,10 @@ import Svg, { import uid from '../shared/uid' import { IContentLoaderProps } from './' -import offsetValueBound from './offsetValueBound' -class NativeSvg extends Component { +const AnimatedLinearGradient = Animated.createAnimatedComponent(LinearGradient) + +class NativeSvg extends Component { static defaultProps = { animate: true, backgroundColor: '#f5f6f7', @@ -22,8 +23,6 @@ class NativeSvg extends Component { style: {}, } - state = { offset: -1 } - animatedValue = new Animated.Value(0) fixedId = this.props.uniqueKey || uid() @@ -50,18 +49,6 @@ class NativeSvg extends Component { componentDidMount = () => { if (this.props.animate) { this.setAnimation() - - this.animatedValue.addListener(({ value }) => { - this.setState({ - offset: value, - }) - }) - } - } - - componentWillUnmount = () => { - if (this.props.animate) { - this.animatedValue.removeAllListeners() } } @@ -75,9 +62,17 @@ class NativeSvg extends Component { ...props } = this.props - const offset1 = offsetValueBound(this.state.offset - 1) - const offset2 = offsetValueBound(this.state.offset) - const offset3 = offsetValueBound(this.state.offset + 1) + const x1Animation = this.animatedValue.interpolate({ + extrapolate: 'clamp', + inputRange: [-1, 2], + outputRange: ['-100%', '100%'], + }) + + const x2Animation = this.animatedValue.interpolate({ + extrapolate: 'clamp', + inputRange: [-1, 2], + outputRange: ['0%', '200%'], + }) const rtlStyle: object = rtl ? { transform: [{ rotateY: '180deg' }] } : {} const svgStyle = Object.assign(Object.assign({}, style), rtlStyle) @@ -101,17 +96,17 @@ class NativeSvg extends Component { {children} - - - - - + + + + ) diff --git a/src/native/__tests__/__snapshots__/snapshots.test.tsx.snap b/src/native/__tests__/__snapshots__/snapshots.test.tsx.snap index 3eec8f55..5943d111 100644 --- a/src/native/__tests__/__snapshots__/snapshots.test.tsx.snap +++ b/src/native/__tests__/__snapshots__/snapshots.test.tsx.snap @@ -62,8 +62,8 @@ exports[`ContentLoader snapshots renders correctly the basic version 1`] = ` @@ -72,11 +72,11 @@ exports[`ContentLoader snapshots renders correctly the basic version 1`] = ` stopColor="#f5f6f7" /> @@ -146,8 +146,8 @@ exports[`ContentLoader snapshots renders correctly with viewBox defined 1`] = ` @@ -156,11 +156,11 @@ exports[`ContentLoader snapshots renders correctly with viewBox defined 1`] = ` stopColor="#f5f6f7" /> @@ -230,8 +230,8 @@ exports[`ContentLoader snapshots renders correctly with viewBox defined and size @@ -240,11 +240,11 @@ exports[`ContentLoader snapshots renders correctly with viewBox defined and size stopColor="#f5f6f7" /> @@ -314,8 +314,8 @@ exports[`ContentLoader snapshots renders correctly with viewBox empty 1`] = ` @@ -324,11 +324,11 @@ exports[`ContentLoader snapshots renders correctly with viewBox empty 1`] = ` stopColor="#f5f6f7" /> diff --git a/src/native/__tests__/offsetValueBound.test.ts b/src/native/__tests__/offsetValueBound.test.ts deleted file mode 100644 index 0c804a3d..00000000 --- a/src/native/__tests__/offsetValueBound.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import offsetValueBound from '../offsetValueBound' - -describe('offset value bound ', () => { - it('should return an integer', () => { - expect(offsetValueBound(-1)).toBe(0) - expect(offsetValueBound(0)).toBe(0) - }) - - it('should return a max value 1', () => { - expect(offsetValueBound(1)).toBe(1) - expect(offsetValueBound(1.1)).toBe(1) - expect(offsetValueBound(2)).toBe(1) - }) -}) diff --git a/src/native/__tests__/presets/__snapshots__/BulletListStyle.test.tsx.snap b/src/native/__tests__/presets/__snapshots__/BulletListStyle.test.tsx.snap index 71b150bb..b3c00ff3 100644 --- a/src/native/__tests__/presets/__snapshots__/BulletListStyle.test.tsx.snap +++ b/src/native/__tests__/presets/__snapshots__/BulletListStyle.test.tsx.snap @@ -74,8 +74,8 @@ exports[`BulletListStyle renders correctly 1`] = ` @@ -84,11 +84,11 @@ exports[`BulletListStyle renders correctly 1`] = ` stopColor="#f5f6f7" /> diff --git a/src/native/__tests__/presets/__snapshots__/CodeStyle.test.tsx.snap b/src/native/__tests__/presets/__snapshots__/CodeStyle.test.tsx.snap index 157e5acf..4d45b6c8 100644 --- a/src/native/__tests__/presets/__snapshots__/CodeStyle.test.tsx.snap +++ b/src/native/__tests__/presets/__snapshots__/CodeStyle.test.tsx.snap @@ -78,8 +78,8 @@ exports[`CodeStyle renders correctly 1`] = ` @@ -88,11 +88,11 @@ exports[`CodeStyle renders correctly 1`] = ` stopColor="#f5f6f7" /> diff --git a/src/native/__tests__/presets/__snapshots__/FacebookStyle.test.tsx.snap b/src/native/__tests__/presets/__snapshots__/FacebookStyle.test.tsx.snap index 19fd1fd0..4cb50b91 100644 --- a/src/native/__tests__/presets/__snapshots__/FacebookStyle.test.tsx.snap +++ b/src/native/__tests__/presets/__snapshots__/FacebookStyle.test.tsx.snap @@ -62,8 +62,8 @@ exports[`FacebookStyle renders correctly 1`] = ` @@ -72,11 +72,11 @@ exports[`FacebookStyle renders correctly 1`] = ` stopColor="#f5f6f7" /> diff --git a/src/native/__tests__/presets/__snapshots__/InstagramStyle.test.tsx.snap b/src/native/__tests__/presets/__snapshots__/InstagramStyle.test.tsx.snap index 3eb021f1..e726d2de 100644 --- a/src/native/__tests__/presets/__snapshots__/InstagramStyle.test.tsx.snap +++ b/src/native/__tests__/presets/__snapshots__/InstagramStyle.test.tsx.snap @@ -51,8 +51,8 @@ exports[`InstagramStyle renders correctly 1`] = ` @@ -61,11 +61,11 @@ exports[`InstagramStyle renders correctly 1`] = ` stopColor="#f5f6f7" /> diff --git a/src/native/__tests__/presets/__snapshots__/ListStyle.test.tsx.snap b/src/native/__tests__/presets/__snapshots__/ListStyle.test.tsx.snap index b8ae0df2..486e803c 100644 --- a/src/native/__tests__/presets/__snapshots__/ListStyle.test.tsx.snap +++ b/src/native/__tests__/presets/__snapshots__/ListStyle.test.tsx.snap @@ -70,8 +70,8 @@ exports[`ListStyle renders correctly 1`] = ` @@ -80,11 +80,11 @@ exports[`ListStyle renders correctly 1`] = ` stopColor="#f5f6f7" /> diff --git a/src/native/offsetValueBound.ts b/src/native/offsetValueBound.ts deleted file mode 100644 index a9f639b6..00000000 --- a/src/native/offsetValueBound.ts +++ /dev/null @@ -1,13 +0,0 @@ -const offsetValueBound = (value: number): number => { - if (value > 1) { - return 1 - } - - if (value < 0) { - return 0 - } - - return value -} - -export default offsetValueBound