subtirelumihail / react-fullpage

A react implementation of fullpage.js
304 stars 105 forks source link

When I refresh my page, the fullpage always roll back to the first screen but hash value don't change. #46

Open dengshasha opened 6 years ago

dengshasha commented 6 years ago

Maybe this can solve : SectionsContainer.js:

constructor(props) {
            super(props);
            this.state = {
                activeSection: props.activeSection,
                scrollingStarted: false,
                sectionScrolledPosition: 0,
                windowHeight: window.innerHeight //modify 0 to window.innerHeight
            };
ghost commented 6 years ago

I have same issue, but unfortunately, previous code didn't help.

dengshasha commented 6 years ago

@dropsydice I'm sorry, I forget to specify which file I modified. when I refresh this page: image and I modify SectionsContainer.js:

constructor(props) {
            super(props);
            this.state = {
                activeSection: props.activeSection,
                scrollingStarted: false,
                sectionScrolledPosition: 0,
                windowHeight: window.innerHeight //modify 0 to window.innerHeight
            };

I refresh again: image would you try again?

ghost commented 6 years ago

My way of fixing it is calling this method:

componentDidUpdate () {
        setTimeout(this.refs.container._handleResize , 1);
    }

It's scroll to URL anchor when the viewport resizes

dengshasha commented 6 years ago

It's a good idea!@dropsydice

dhwrwm commented 6 years ago

Is there a proper fix for this.

alexandrebodin commented 6 years ago

Hey,

The cleanest way I found is too pass a activeSection prop to the SectionContainer and update it with the scrollCallback the first time it's set.

class Cmp extends React {
  constructor() {
    super();
    this.state = {
      initialActiveSection: null
    };
  }
  onScroll(p) {
    if (this.state.initialActiveSection === null)
      this.setState(() => ({ initialActiveSection: p.activeSection }));
  }
  render() {
    const { initialActiveSection } = this.state;
    return (
      <SectionsContainer
        {...options}
        activeSection={initialActiveSection}
        scrollCallback={this.onScroll}
      />
    );
  }
}