question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CRASH with Swipeable when setting state on componentDidMount

See original GitHub issue

Argument 1 (NSNumber) of RNGestureHandlerModule.attachGestureHandler must not be null image

Gesture handler version: 1.0.1

I made a simple reproduction repo of the problem here: https://github.com/henrikra/gesture-handler-crash/blob/master/App.js

Steps to reproduce:

  1. Use Swipeable somewhere in your component
  2. Use setState in componentDidMount
  3. See crash! 💥

Workaround: Add setTimeout with 0 delay and it will not crash. But this is very flake workaround and should not be used

I hope this gets fixed soon since this is very critical bug 😕

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
waheedakhtar694commented, Nov 12, 2020

Still getting the same error

4reactions
adrienthierycommented, Jun 13, 2018

Hi there,

I encountered that error using a custom component as a child to PanGestureHandler that was using View but without passing the nativeProps down.

<PanGestureHandler
    {...this.props}
    onGestureEvent={this._onGestureEvent}
    onHandlerStateChange={this._onHandlerStateChange}
    id="dragbox"
>
    <MyComponent>...</MyComponent>
</PanGestureHandler>

Adding :

class MyComponent extends Component {
+    setNativeProps(props: Object) {
+        this.ref.setNativeProps(props);
+    }

+    getRef = (ref: View) => {
+        this.ref = ref;
+    };

    render() {
        return (
            <View
                {...this.props}
+                ref={this.getRef}
                style={[styles.view, this.props.style]}
            >
                ...
            </View>
        );
    }
}

to my component fixed it.

Hopefully it can help other devs looking at that issue to figure out what their problem is 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

CRASH with Swipeable when setting state on ... - GitHub
Use Swipeable somewhere in your component; Use setState in componentDidMount; See crash!. Workaround: Add setTimeout with 0 delay and ...
Read more >
Setting state on componentDidMount() - reactjs - Stack Overflow
According to the React Documentation it's perfectly OK to call setState() from within the componentDidMount() function ...
Read more >
Drawer Navigator | React Navigation
Whether the keyboard should be dismissed when the swipe gesture begins. Defaults to 'on-drag' . Set to 'none' to disable keyboard handling. unmountOnBlur...
Read more >
React Lifecycle Methods Render And ComponentDidMount
componentDidMount () method is the perfect place, where we can call the setState() method to change the state of our application and render()...
Read more >
How can I detect browser back button in react class component
react detect browser back button is clicked. onpopstate = e => { //your code } } 31 VirajReact redux: how to clear the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found