-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linear progress bar. #88
Conversation
src/index.js
Outdated
@@ -12,6 +12,8 @@ export { default as Paper } from './components/Paper'; | |||
export { default as RadioButton } from './components/RadioButton'; | |||
export { default as TouchableRipple } from './components/TouchableRipple'; | |||
|
|||
export * as Progress from './components/Progress'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should not know how individual components are exported. Let's change it to
export { default as Progress } from './components/Progress
src/components/Progress/index.js
Outdated
@@ -0,0 +1 @@ | |||
export { default as Linear } from './Linear'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be changed to
import Linear from './Linear';
export default {
Linear,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any benefits? Not sure if thats the same though. Chudziak's code has named exports whereas yours exports a default object with properties. Not sure if that's guarnateed to behave the same way or it's just Babel inter-op with require, but yeah, I'd stick with the former.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think then we can use export { default as Progress } from './components/Progress
from the comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mike866 No I wanted to export an object here instead of named exports.
src/components/Progress/Linear.js
Outdated
@@ -0,0 +1,193 @@ | |||
/* @flow */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a convention I usually name the component (and file) as ProgressLinear
instead of Linear
. That way when it's shown in error messages ProgressLinear
will be shown which is more informative.
src/components/Progress/Linear.js
Outdated
|
||
type Props = { | ||
color: string; | ||
emptyColor: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is same as style={{ backgroundColor: color }}
, right? In that case, let's remove the prop
src/components/Progress/Linear.js
Outdated
}; | ||
|
||
static defaultProps: Props = { | ||
color: blueA200, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should use the accent color from theme by default.
src/components/Progress/Linear.js
Outdated
|
||
static defaultProps: Props = { | ||
color: blueA200, | ||
emptyColor: blue100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be achieved by lightening the color I believe.
src/components/Progress/Linear.js
Outdated
|
||
import { blueA200, blue100 } from '../../styles/colors'; | ||
|
||
const roundProgress = (progress: ?number): number => Math.min(Math.max((progress || 0), 0), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add description, took me a while to figure out. Basically it's used to return a number between bounds (0, 1), otherwise upper or lower limit.
example/src/ProgressExample.js
Outdated
constructor(props) { | ||
super(props); | ||
|
||
const interval = setInterval(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think better to move this out of the state. This is something the UI doesn't depend upon, so shouldn't be in state. I'd do this._interval
this._startIndeterminateAnimation(); | ||
} | ||
|
||
Animated.spring(this.state.visibleAnimationValue, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to check if this.props.visible
is true
|
||
const defaultBarXPosition = indeterminateWidth / (1 + indeterminateWidth); | ||
|
||
const { width, height } = StyleSheet.flatten(props.style); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't rely on user to pass height and width. We should have default height in styles and width should be detected automatically using onLayout
Also instead of animating height, we should use a scale animation (will need to use together with translate since we don't have transform origin support)
const { width, height } = StyleSheet.flatten(props.style); | ||
|
||
this.state = { | ||
progressAnimationValue: new Animated.Value(props.indeterminate ? indeterminateWidth : progress), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use scale instead of animating width? Scale animations are much smoother than width/height.
example/src/ProgressExample.js
Outdated
constructor(props) { | ||
super(props); | ||
|
||
this.interval = setInterval(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to componentDidMount
instead? Also change it to this._interval
.
Doesn't matter here, but it's better to have side effects in componentDidMount
, since in plain React you don't usually want them to trigger on the server while server-rendering.
example/src/ProgressExample.js
Outdated
}; | ||
} | ||
|
||
state = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is declared twice. I think better to get rid of the constructor. And move interval stuff to componentDidMount
.
example/src/ProgressExample.js
Outdated
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<Headline style={styles.text}>Linear</Headline> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Headline, Subheading etc have a default vertical margin of 4px. I think you don't need the additional style
Easing, | ||
View, | ||
} from 'react-native'; | ||
import color from 'color'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove new line between imports
constructor(props: Props) { | ||
super(props); | ||
|
||
const progress: number = roundProgress(props.progress); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove new lines between const
declarations
easing: Easing.linear, | ||
isInteraction: false, | ||
}).start((animationState) => { | ||
if (animationState.finished) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we had Animated.loop
} = this.props; | ||
const { width, height } = this.state; | ||
|
||
const progressColor = this.props.color || this.props.theme.colors.accent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructure theme
above
This is stale. Re-check issue: #11. |
Implementation of linear progress bar in two states.
Determinate:
When indicators are determinate they indicate how long an operation will take when the percentage complete is detectable.
Indeterminate:
When indicators are indeterminate they request that the user wait while something finishes when it’s not necessary to indicate how long it will take.