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

Updating the statusbar color resets the pagination indicator #38

Open
SandroMachado opened this issue Sep 26, 2016 · 7 comments
Open

Updating the statusbar color resets the pagination indicator #38

SandroMachado opened this issue Sep 26, 2016 · 7 comments

Comments

@SandroMachado
Copy link
Contributor

Hi @FuYaoDe,

I am trying to update the status bar color (in Android) to match background of each page of the onboard.

My render function looks like this:

  render() {
    return (
      <View>
      <StatusBar
        backgroundColor={shadeStatusBarColor(this.state.statusBarColor, -0.3)}
      />
      <AppIntro
        onDoneBtnClick={this.doneBtnHandle}
        onSkipBtnClick={this.onSkipBtnHandle}
        onSlideChange={this.onSlideChangeHandle}
        pageArray={this.state.pageArray}
      />
      </View>
    );
  }

On the slide change callback I have this:

onSlideChangeHandle = (index, total) => {
    this.setState({ statusBarColor: this.state.pageArray[index].backgroundColor, currentPage: index });
  }

Doing this, the color of the statusbar changes, but the pagination is reset to the first position.

baconmhc19qsandromachado09262016140353

I also tried to do this change directly in the library (I want to make a PR to add this feature to the library also), but the behaviour is the same, the page position is not persisted.

Do you have any tips to fix this?

Thanks for the great work.

@nelsonkam
Copy link

Hello @SandroMachado this behaviour is due to the use of setState in your callback. Using setState triggers the render method thereby reinitializing the AppIntro component (and resetting pagination to first position).

@SandroMachado
Copy link
Contributor Author

@nelsonkam I know, but the component should know that it is not required to redraw the component, since I am not changing any variable that affects the component.

@FuYaoDe
Copy link
Owner

FuYaoDe commented Sep 28, 2016

Hi @SandroMachado
You can use defaultIndex temporarily fix the bug

  render() {
    return (
      <View>
      <StatusBar
        backgroundColor={shadeStatusBarColor(this.state.statusBarColor, -0.3)}
      />
      <AppIntro
        onDoneBtnClick={this.doneBtnHandle}
        onSkipBtnClick={this.onSkipBtnHandle}
        onSlideChange={this.onSlideChangeHandle}
        pageArray={this.state.pageArray}
        defaultIndex={this.state.currentPage}
      />
      </View>
    );
  }
onSlideChangeHandle = (index, total) => {
    this.setState({ 
      statusBarColor: this.state.pageArray[index].backgroundColor,
      currentPage: index 
    });
  }

And I will look for the unusual render

@SandroMachado
Copy link
Contributor Author

Another fix for this is using the imperative method available in the StatusBar.

StatusBar.setBackgroundColor(shadeStatusBarColor(this.pageArray[index].backgroundColor, -0.3), false);

This will not cause the re-render of the AppIntro component.

@SandroMachado
Copy link
Contributor Author

This is kind of fixed by #42.

@jonathanpalma
Copy link

Do you know a way to make this works for Advanced Usage?

@shareefhiasat
Copy link

Didnt the newest versions of the library have this sorted ?! yet .

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

No branches or pull requests

5 participants