bamlab / react-native-image-header-scroll-view

ScrollView with an image in header which becomes a navbar
MIT License
990 stars 94 forks source link

Fix a faulty setState call when container could be unmounted in future #54

Closed darekg11 closed 5 years ago

darekg11 commented 5 years ago

Hello, we have been using this great library but there is a issue when you use HeaderImageScrollView inside a View that also has onLayout callback attached then rotating the device will cause the error to come up in React-Native warning box stating that setState can't be used on unmounted component.

This is happening because:

onContainerLayout = () => {
    if (!this.container) {
      return;
    }
    this.container.measureInWindow((x, y) => this.setState(() => ({ pageY: y })));
};

The actual callback with this.setState call might indeed happen when the component is unmounted. Therefore I have added additional guard inside that callback to make sure that setState won't fire if container does not exist anymore.

Nhacsam commented 5 years ago

Thanks for you contribution :-)

darekg11 commented 5 years ago

Thank you for merging :+1: Are you planning to release new version any time soon? I would love to switch to a official npm distribution in my package.json instead of using my forked github repo :)

Nhacsam commented 5 years ago

Done ! Sorry for the delay https://github.com/bamlab/react-native-image-header-scroll-view/releases/tag/0.9.0

darekg11 commented 5 years ago

Thank you @Nhacsam 👍