11import React , { Component } from 'react' ;
22import PropTypes from 'prop-types' ;
3- import {
4- Animated ,
5- Easing ,
6- View ,
7- ViewPropTypes ,
8- } from 'react-native' ;
3+ import { Animated , Easing , View , ViewPropTypes } from 'react-native' ;
94
105const INDETERMINATE_WIDTH_FACTOR = 0.3 ;
11- const BAR_WIDTH_ZERO_POSITION = INDETERMINATE_WIDTH_FACTOR / ( 1 + INDETERMINATE_WIDTH_FACTOR ) ;
6+ const BAR_WIDTH_ZERO_POSITION =
7+ INDETERMINATE_WIDTH_FACTOR / ( 1 + INDETERMINATE_WIDTH_FACTOR ) ;
128
139const RNViewPropTypes = ViewPropTypes || View . propTypes ;
1410
@@ -52,7 +48,9 @@ export default class ProgressBar extends Component {
5248 const progress = Math . min ( Math . max ( props . progress , 0 ) , 1 ) ;
5349 this . state = {
5450 width : 0 ,
55- progress : new Animated . Value ( props . indeterminate ? INDETERMINATE_WIDTH_FACTOR : progress ) ,
51+ progress : new Animated . Value (
52+ props . indeterminate ? INDETERMINATE_WIDTH_FACTOR : progress
53+ ) ,
5654 animationValue : new Animated . Value ( BAR_WIDTH_ZERO_POSITION ) ,
5755 } ;
5856 }
@@ -78,10 +76,9 @@ export default class ProgressBar extends Component {
7876 props . indeterminate !== this . props . indeterminate ||
7977 props . progress !== this . props . progress
8078 ) {
81- const progress = ( props . indeterminate
79+ const progress = props . indeterminate
8280 ? INDETERMINATE_WIDTH_FACTOR
83- : Math . min ( Math . max ( props . progress , 0 ) , 1 )
84- ) ;
81+ : Math . min ( Math . max ( props . progress , 0 ) , 1 ) ;
8582
8683 if ( props . animated ) {
8784 const { animationType, animationConfig } = this . props ;
@@ -104,14 +101,14 @@ export default class ProgressBar extends Component {
104101 easing : Easing . linear ,
105102 isInteraction : false ,
106103 useNativeDriver : this . props . useNativeDriver ,
107- } ) . start ( ( endState ) => {
104+ } ) . start ( endState => {
108105 if ( endState . finished ) {
109106 this . animate ( ) ;
110107 }
111108 } ) ;
112109 }
113110
114- handleLayout = ( event ) => {
111+ handleLayout = event => {
115112 if ( ! this . props . width ) {
116113 this . setState ( { width : event . nativeEvent . layout . width } ) ;
117114 }
@@ -134,7 +131,7 @@ export default class ProgressBar extends Component {
134131 ...restProps
135132 } = this . props ;
136133
137- const innerWidth = Math . max ( 0 , width || this . state . width ) - ( borderWidth * 2 ) ;
134+ const innerWidth = Math . max ( 0 , width || this . state . width ) - borderWidth * 2 ;
138135 const containerStyle = {
139136 width,
140137 borderWidth,
@@ -146,27 +143,35 @@ export default class ProgressBar extends Component {
146143 const progressStyle = {
147144 backgroundColor : color ,
148145 height,
149- transform : [ {
150- translateX : this . state . animationValue . interpolate ( {
151- inputRange : [ 0 , 1 ] ,
152- outputRange : [ innerWidth * - INDETERMINATE_WIDTH_FACTOR , innerWidth ] ,
153- } ) ,
154- } , {
155- translateX : this . state . progress . interpolate ( {
156- inputRange : [ 0 , 1 ] ,
157- outputRange : [ innerWidth / - 2 , 0 ] ,
158- } ) ,
159- } , {
160- // Interpolation a temp workaround for https://github.com/facebook/react-native/issues/6278
161- scaleX : this . state . progress . interpolate ( {
162- inputRange : [ 0 , 1 ] ,
163- outputRange : [ 0.0001 , 1 ] ,
164- } ) ,
165- } ] ,
146+ transform : [
147+ {
148+ translateX : this . state . animationValue . interpolate ( {
149+ inputRange : [ 0 , 1 ] ,
150+ outputRange : [ innerWidth * - INDETERMINATE_WIDTH_FACTOR , innerWidth ] ,
151+ } ) ,
152+ } ,
153+ {
154+ translateX : this . state . progress . interpolate ( {
155+ inputRange : [ 0 , 1 ] ,
156+ outputRange : [ innerWidth / - 2 , 0 ] ,
157+ } ) ,
158+ } ,
159+ {
160+ // Interpolation a temp workaround for https://github.com/facebook/react-native/issues/6278
161+ scaleX : this . state . progress . interpolate ( {
162+ inputRange : [ 0 , 1 ] ,
163+ outputRange : [ 0.0001 , 1 ] ,
164+ } ) ,
165+ } ,
166+ ] ,
166167 } ;
167168
168169 return (
169- < View style = { [ containerStyle , style ] } onLayout = { this . handleLayout } { ...restProps } >
170+ < View
171+ style = { [ containerStyle , style ] }
172+ onLayout = { this . handleLayout }
173+ { ...restProps }
174+ >
170175 < Animated . View style = { progressStyle } />
171176 { children }
172177 </ View >
0 commit comments