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

Set progress text properly and runs the animation when the default progress is given #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mu29
Copy link

@mu29 mu29 commented Nov 22, 2018

Problem

Since progressValue is set to 0 on constructor, initial progress value didn't works well when combine with animated and showsText props. See code and screenshot below.

import React, {Component} from 'react';
import Circle from 'react-native-progress/Circle'
import {Platform, StyleSheet, Button, View} from 'react-native';

type ExampleState = {
  progress: number;
}

export default class Example extends React.Component<{}, ExampleState> {
  state = {
    progress: 0.1,
  }

  render() {
    return (
      <View style={styles.container}>
        <Circle
          color="#000000"
          unfilledColor="#FAFAFA"
          borderWidth={0}
          progress={this.state.progress}
          showsText
        />
        <Button title="click!" onPress={() => this.setState(s => ({ progress: s.progress + 0.1}))} />
      </View>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
});

2018-11-22 3 12 42

Expected behavior

Text shows 10% in the progress circle

Solution

Run progress animation on componentDidMount. This will not only update progress, but also animates progress circle to given default progress.

@mu29 mu29 changed the title Set progressValue to the value passed in props on constructor Runs the animation when the default progress is given Nov 22, 2018
@mu29 mu29 changed the title Runs the animation when the default progress is given Set progress text properly and runs the animation when the default progress is given Nov 22, 2018
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.

1 participant