Skip to content

Commit c6da59d

Browse files
authored
Merge pull request #229 from NikolaIliev/master
feat(native/svg.tsx native/index.ts): implement 'interval' prop for RN
2 parents 2997712 + 52c65e2 commit c6da59d

File tree

9 files changed

+18
-5
lines changed

9 files changed

+18
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const MyLoader = () => (
114114
| **`title?: string`** <br/> Defaults to `Loading interface...` | React DOM only | It's used to describe what element it is. <br />Use `''` (empty string) to remove. |
115115
| **`baseUrl?: string`**<br /> Defaults to an empty string | React DOM only | Required if you're using `<base url="/" />` document `<head/>`. <br/>This prop is common used as: <br/>`<ContentLoader baseUrl={window.location.pathname} />` which will fill the SVG attribute with the relative path. Related [#93](https://github.com/danilowoz/react-content-loader/issues/93). |
116116
| **`speed?: number`** <br /> Defaults to `1.2` | React DOM<br/>React Native | Animation speed in seconds. |
117-
| **`interval?: number`** <br /> Defaults to `0.25` | React DOM only | Interval of time between runs of the animation, <br/>as a fraction of the animation speed. |
117+
| **`interval?: number`** <br /> Defaults to `0.25` | React DOM<br/>React Native | Interval of time between runs of the animation, <br/>as a fraction of the animation speed. |
118118
| **`viewBox?: string`** <br /> Defaults to `undefined` | React DOM<br/>React Native | Use viewBox props to set a custom viewBox value, <br/>for more information about how to use it, <br/>read the article [How to Scale SVG](https://css-tricks.com/scale-svg/). |
119119
| **`gradientRatio?: number`** <br /> Defaults to `1.2` | React DOM only | Width of the animated gradient as a fraction of the view box width. |
120120
| **`rtl?: boolean`** <br /> Defaults to `false` | React DOM<br/>React Native | Content right-to-left. |

src/native/Svg.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class NativeSvg extends Component<IContentLoaderProps> {
2020
foregroundColor: '#eee',
2121
rtl: false,
2222
speed: 1.2,
23+
interval: 0.25,
2324
style: {},
2425
}
2526

@@ -32,13 +33,15 @@ class NativeSvg extends Component<IContentLoaderProps> {
3233
idGradient = `${this.fixedId}-animated-diff`
3334

3435
setAnimation = () => {
35-
// Turn in seconds to keep compatible with web one
36-
const durInSeconds = this.props.speed * 1000
36+
// props.speed is in seconds as it is compatible with web
37+
// convert to milliseconds
38+
const durMs = this.props.speed * 1000
39+
const delay = durMs * this.props.interval
3740

3841
Animated.timing(this.animatedValue, {
3942
toValue: 2,
40-
delay: durInSeconds,
41-
duration: durInSeconds,
43+
delay: delay,
44+
duration: durMs,
4245
useNativeDriver: true,
4346
}).start(() => {
4447
this.animatedValue.setValue(-1)

src/native/__tests__/__snapshots__/snapshots.test.tsx.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`ContentLoader snapshots renders correctly the basic version 1`] = `
44
<Svg
55
height={124}
6+
interval={0.25}
67
style={Object {}}
78
viewBox="0 0 476 124"
89
width={476}
@@ -87,6 +88,7 @@ exports[`ContentLoader snapshots renders correctly the basic version 1`] = `
8788
exports[`ContentLoader snapshots renders correctly with viewBox defined 1`] = `
8889
<Svg
8990
height={124}
91+
interval={0.25}
9092
style={Object {}}
9193
viewBox="0 0 100 100"
9294
width={476}
@@ -171,6 +173,7 @@ exports[`ContentLoader snapshots renders correctly with viewBox defined 1`] = `
171173
exports[`ContentLoader snapshots renders correctly with viewBox defined and sizes defined too 1`] = `
172174
<Svg
173175
height={100}
176+
interval={0.25}
174177
style={Object {}}
175178
viewBox="0 0 100 100"
176179
width={100}
@@ -255,6 +258,7 @@ exports[`ContentLoader snapshots renders correctly with viewBox defined and size
255258
exports[`ContentLoader snapshots renders correctly with viewBox empty 1`] = `
256259
<Svg
257260
height={124}
261+
interval={0.25}
258262
style={Object {}}
259263
viewBox=""
260264
width={476}

src/native/__tests__/presets/__snapshots__/BulletListStyle.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`BulletListStyle renders correctly 1`] = `
44
<Svg
55
height={125}
6+
interval={0.25}
67
style={Object {}}
78
viewBox="0 0 245 125"
89
width={245}

src/native/__tests__/presets/__snapshots__/CodeStyle.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`CodeStyle renders correctly 1`] = `
44
<Svg
55
height={84}
6+
interval={0.25}
67
style={Object {}}
78
viewBox="0 0 340 84"
89
width={340}

src/native/__tests__/presets/__snapshots__/FacebookStyle.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`FacebookStyle renders correctly 1`] = `
44
<Svg
55
height={124}
6+
interval={0.25}
67
style={Object {}}
78
viewBox="0 0 476 124"
89
width={476}

src/native/__tests__/presets/__snapshots__/InstagramStyle.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`InstagramStyle renders correctly 1`] = `
44
<Svg
55
height={460}
6+
interval={0.25}
67
style={Object {}}
78
viewBox="0 0 400 460"
89
width={400}

src/native/__tests__/presets/__snapshots__/ListStyle.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`ListStyle renders correctly 1`] = `
44
<Svg
55
height={110}
6+
interval={0.25}
67
style={Object {}}
78
viewBox="0 0 400 110"
89
width={400}

src/native/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface IContentLoaderProps extends SvgProps {
88
foregroundColor?: string
99
rtl?: boolean
1010
speed?: number
11+
interval?: number
1112
uniqueKey?: string
1213
}
1314

0 commit comments

Comments
 (0)