Skip to content

Commit defa76d

Browse files
committed
Fix bug on LinearGradient's stops on Android
This patch fixes an issue reported on `react-native-community/react-native-svg` repository that made `LinearGradient` throw an error when it has two or more `Stop` with the same offset. ISSUE=software-mansion/react-native-svg#385
1 parent 555d125 commit defa76d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class ContentLoader extends Component {
3030
'-2', '-1.5', '-1'
3131
],
3232
offsets: [
33-
'0', '0', '0'
33+
'0.0001', '0.0002', '0.0003' // Avoid duplicate value cause error in Android
3434
],
3535
frequence: props.duration / 2
3636
}
@@ -73,7 +73,14 @@ export default class ContentLoader extends Component {
7373
offsetValues[0] = this.offsetValueBound(newState.offsetValues[0]);
7474
offsetValues[1] = this.offsetValueBound(newState.offsetValues[1]);
7575
offsetValues[2] = this.offsetValueBound(newState.offsetValues[2]);
76-
this.setState({offsets: offsetValues});
76+
77+
// Make sure at least two offsets is different
78+
// original fix from: https://github.com/virusvn/react-native-svg-animated-linear-gradient/commit/b9558aab3bbd8f5be50204dd5cb67c9348c60fb9
79+
if (offsetValues[0] !== offsetValues[1] ||
80+
offsetValues[0] !== offsetValues[2] ||
81+
offsetValues[1] !== offsetValues[2]) {
82+
this.setState({offsets: offsetValues});
83+
}
7784
if (t < 1) {
7885
requestAnimationFrame(this._animation);
7986
}

0 commit comments

Comments
 (0)