Skip to content
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

Closed
wants to merge 13 commits into from
Closed

Conversation

michalchudziak
Copy link
Contributor

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.

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';
Copy link
Member

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

@@ -0,0 +1 @@
export { default as Linear } from './Linear';
Copy link
Member

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,
}

Copy link
Member

@grabbou grabbou Nov 28, 2016

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.

Copy link
Contributor Author

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

Copy link
Member

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.

@@ -0,0 +1,193 @@
/* @flow */
Copy link
Member

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.


type Props = {
color: string;
emptyColor: string;
Copy link
Member

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

};

static defaultProps: Props = {
color: blueA200,
Copy link
Member

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.


static defaultProps: Props = {
color: blueA200,
emptyColor: blue100,
Copy link
Member

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.


import { blueA200, blue100 } from '../../styles/colors';

const roundProgress = (progress: ?number): number => Math.min(Math.max((progress || 0), 0), 1);
Copy link
Member

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.

constructor(props) {
super(props);

const interval = setInterval(() => {
Copy link
Member

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, {
Copy link
Member

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);
Copy link
Member

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),
Copy link
Member

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.

constructor(props) {
super(props);

this.interval = setInterval(() => {
Copy link
Member

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.

};
}

state = {
Copy link
Member

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.

render() {
return (
<View style={styles.container}>
<Headline style={styles.text}>Linear</Headline>
Copy link
Member

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';
Copy link
Member

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);
Copy link
Member

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) {
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destructure theme above

@ferrannp
Copy link
Collaborator

This is stale. Re-check issue: #11.

@ferrannp ferrannp closed this Sep 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants