Skip to content

Commit ea75cce

Browse files
committed
[change] ProgressBar using CSS animations
Fix #299
1 parent cfc56a1 commit ea75cce

File tree

5 files changed

+37
-86
lines changed

5 files changed

+37
-86
lines changed

src/apis/AppRegistry/__tests__/__snapshots__/renderApplication-test.js.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
exports[`apis/AppRegistry/renderApplication getApplication 1`] = `
22
"<style id=\"react-native-stylesheet\">
3+
/* React Native StyleSheet*/
34
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0)}
45
body{margin:0}
56
button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
67
input::-webkit-inner-spin-button,input::-webkit-outer-spin-button,input::-webkit-search-cancel-button,input::-webkit-search-decoration,input::-webkit-search-results-button,input::-webkit-search-results-decoration{display:none}
7-
.rn_pointerEvents\\:auto, .rn_pointerEvents\\:box-only, .rn_pointerEvents\\:box-none * {pointer-events:auto}.rn_pointerEvents\\:none, .rn_pointerEvents\\:box-only *, .rn_pointerEvents\\:box-none {pointer-events:none}
8-
@keyframes rn-ActivityIndicator-animation {0% { -webkit-transform: rotate(0deg); transform: rotate(0deg); }100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); }}
8+
@keyframes rn-ActivityIndicator-animation{0%{-webkit-transform: rotate(0deg); transform: rotate(0deg);}100%{-webkit-transform: rotate(360deg); transform: rotate(360deg);}}
9+
@keyframes rn-ProgressBar-animation{0%{-webkit-transform: translateX(-100%); transform: translateX(-100%);}100%{-webkit-transform: translateX(400%); transform: translateX(400%);}}
10+
.rn_pointerEvents\\:auto,.rn_pointerEvents\\:box-only,.rn_pointerEvents\\:box-none *{pointer-events:auto}.rn_pointerEvents\\:none,.rn_pointerEvents\\:box-only *,.rn_pointerEvents\\:box-none{pointer-events:none}
911
.rn-bottom\\:0px{bottom:0px;}
1012
.rn-left\\:0px{left:0px;}
1113
.rn-position\\:absolute{position:absolute;}

src/apis/StyleSheet/initialize.js

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,33 @@ import StyleRegistry from './registry';
33

44
const initialize = () => {
55
injector.addRule(
6-
'html-reset',
6+
'reset',
7+
'/* React Native StyleSheet*/\n' +
78
'html{' +
89
'font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;' +
910
'-webkit-tap-highlight-color:rgba(0,0,0,0)' +
10-
'}'
11-
);
12-
13-
injector.addRule(
14-
'body-reset',
15-
'body{margin:0}'
16-
);
17-
18-
injector.addRule(
19-
'button-reset',
20-
'button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}'
21-
);
22-
23-
injector.addRule(
24-
'input-reset',
11+
'}\n' +
12+
'body{margin:0}\n' +
13+
'button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}\n' +
2514
'input::-webkit-inner-spin-button,input::-webkit-outer-spin-button,' +
2615
'input::-webkit-search-cancel-button,input::-webkit-search-decoration,' +
2716
'input::-webkit-search-results-button,input::-webkit-search-results-decoration{display:none}'
2817
);
29-
3018
injector.addRule(
31-
'pointer-events',
32-
'.rn_pointerEvents\\:auto, .rn_pointerEvents\\:box-only, .rn_pointerEvents\\:box-none * {pointer-events:auto}' +
33-
'.rn_pointerEvents\\:none, .rn_pointerEvents\\:box-only *, .rn_pointerEvents\\:box-none {pointer-events:none}'
19+
'keyframes',
20+
'@keyframes rn-ActivityIndicator-animation{' +
21+
'0%{-webkit-transform: rotate(0deg); transform: rotate(0deg);}' +
22+
'100%{-webkit-transform: rotate(360deg); transform: rotate(360deg);}' +
23+
'}\n' +
24+
'@keyframes rn-ProgressBar-animation{' +
25+
'0%{-webkit-transform: translateX(-100%); transform: translateX(-100%);}' +
26+
'100%{-webkit-transform: translateX(400%); transform: translateX(400%);}' +
27+
'}'
3428
);
35-
3629
injector.addRule(
37-
'activity-indicator-animation',
38-
'@keyframes rn-ActivityIndicator-animation {' +
39-
'0% { -webkit-transform: rotate(0deg); transform: rotate(0deg); }' +
40-
'100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); }' +
41-
'}'
30+
'pointer-events',
31+
'.rn_pointerEvents\\:auto,.rn_pointerEvents\\:box-only,.rn_pointerEvents\\:box-none *{pointer-events:auto}' +
32+
'.rn_pointerEvents\\:none,.rn_pointerEvents\\:box-only *,.rn_pointerEvents\\:box-none{pointer-events:none}'
4233
);
4334

4435
StyleRegistry.initialize();

src/components/ActivityIndicator/__tests__/__snapshots__/index-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ rn-textDecoration:none"
3838
role="progressbar"
3939
style={Object {}}>
4040
<div
41-
className="rn-ActivityIndicator-animation
41+
className="
4242
rn-alignItems:stretch
4343
rn-animationDuration:0.75s
4444
rn-animationIterationCount:infinite
@@ -151,7 +151,7 @@ rn-textDecoration:none"
151151
role="progressbar"
152152
style={Object {}}>
153153
<div
154-
className="rn-ActivityIndicator-animation
154+
className="
155155
rn-alignItems:stretch
156156
rn-animationDuration:0.75s
157157
rn-animationIterationCount:infinite

src/components/ActivityIndicator/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class ActivityIndicator extends Component {
7272
>
7373
<View
7474
children={svg}
75-
className='rn-ActivityIndicator-animation'
7675
style={[
7776
indicatorSizes[size],
7877
styles.animation,

src/components/ProgressBar/index.js

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import Animated from '../../apis/Animated';
21
import applyNativeMethods from '../../modules/applyNativeMethods';
32
import ColorPropType from '../../propTypes/ColorPropType';
43
import StyleSheet from '../../apis/StyleSheet';
54
import View from '../View';
65
import React, { Component, PropTypes } from 'react';
76

8-
const indeterminateWidth = '25%';
9-
const translateInterpolation = { inputRange: [ 0, 1 ], outputRange: [ '-100%', '400%' ] };
10-
117
class ProgressBar extends Component {
128
static displayName = 'ProgressBar';
139

@@ -26,21 +22,6 @@ class ProgressBar extends Component {
2622
trackColor: 'transparent'
2723
};
2824

29-
constructor(props) {
30-
super(props);
31-
this.state = {
32-
animationTranslate: new Animated.Value(0)
33-
};
34-
}
35-
36-
componentDidMount() {
37-
this._manageAnimation();
38-
}
39-
40-
componentDidUpdate() {
41-
this._manageAnimation();
42-
}
43-
4425
render() {
4526
const {
4627
color,
@@ -51,8 +32,6 @@ class ProgressBar extends Component {
5132
...other
5233
} = this.props;
5334

54-
const { animationTranslate } = this.state;
55-
5635
const percentageProgress = indeterminate ? 50 : progress * 100;
5736

5837
return (
@@ -67,43 +46,16 @@ class ProgressBar extends Component {
6746
{ backgroundColor: trackColor }
6847
]}
6948
>
70-
<Animated.View style={[
71-
styles.progress,
72-
{ backgroundColor: color },
73-
indeterminate ? {
74-
transform: [
75-
{ translateX: animationTranslate.interpolate(translateInterpolation) }
76-
],
77-
width: indeterminateWidth
78-
} : {
79-
width: `${percentageProgress}%`
80-
}
81-
]} />
49+
<View
50+
style={[
51+
styles.progress,
52+
indeterminate ? styles.indeterminate : { width: `${percentageProgress}%` },
53+
{ backgroundColor: color }
54+
]}
55+
/>
8256
</View>
8357
);
8458
}
85-
86-
_manageAnimation() {
87-
const { animationTranslate } = this.state;
88-
89-
const cycleAnimation = (animation) => {
90-
animation.setValue(0);
91-
Animated.timing(animation, {
92-
duration: 1000,
93-
toValue: 1
94-
}).start((event) => {
95-
if (event.finished) {
96-
cycleAnimation(animation);
97-
}
98-
});
99-
};
100-
101-
if (this.props.indeterminate) {
102-
cycleAnimation(animationTranslate);
103-
} else {
104-
animationTranslate.stopAnimation();
105-
}
106-
}
10759
}
10860

10961
const styles = StyleSheet.create({
@@ -114,6 +66,13 @@ const styles = StyleSheet.create({
11466
},
11567
progress: {
11668
height: '100%'
69+
},
70+
indeterminate: {
71+
animationDuration: '1s',
72+
animationName: 'rn-ProgressBar-animation',
73+
animationTimingFunction: 'linear',
74+
animationIterationCount: 'infinite',
75+
width: '25%'
11776
}
11877
});
11978

0 commit comments

Comments
 (0)