Skip to content

Conversation

@pietropizzi
Copy link
Contributor

It can be undefined thus causing app crashes.

Here's a screenshot from the crash report in fabric:

screen shot 2016-11-16 at 10 44 40

It can be undefined causing app crashes
@alvaromb
Copy link
Collaborator

So this means that componentDidMount doesn't get fired in some cases?

@pietropizzi
Copy link
Contributor Author

I am not sure honestly. They are being set to undefined in getInitialState which maybe is called more often than we think (?). I'm not sure if it is a good idea that getInitialState has side effects, it should just return the initial state.

@alvaromb
Copy link
Collaborator

The execution order is getInitialState, componentDidMount and then componentWillUnmount. This is why I don't know why is this happening.

@alvaromb
Copy link
Collaborator

Ok, we should move the Keyboard.addListener to the componentWillMount lifecycle event.

@alvaromb
Copy link
Collaborator

Do you want to change your PR to provide this? If not, I can change it later today.

@pietropizzi
Copy link
Contributor Author

@alvaromb you think that will fix it?

I am not sure you should be adding subscriptions in this lifecycle method.

screen shot 2016-11-16 at 11 17 14

I am not sure it would be a fix, but I am pretty sure you don't need the this. keyboardWillShowEvent = undefined in getInitialState. It will be undefined to start with anyway.

Since I don't really understand why it is happening, I think the safeguard makes sense, no?

@alvaromb
Copy link
Collaborator

We should introduce your safety check, for sure. About moving the Keyboard.addListener, this is how the Keyboard module is in the React Native documentation:

screen shot 2016-11-16 at 11 20 09

I just read React docs and honestly I'm not sure which path is correct ¯_(ツ)_/¯

It seems that at some point your component unmounts before calling componentDidMount, so the listeners are undefined. Releasing the fix now, thanks!

@alvaromb alvaromb merged commit 70b7955 into APSL:master Nov 16, 2016
@pietropizzi
Copy link
Contributor Author

@alvaromb thanks!

@alvaromb
Copy link
Collaborator

Hi @pietropizzi!

How do you feel about being a collaborator of this library? I have tons of work and other libraries to maintain and I would love to have some help here. Please feel free to ping me if you want to collaborate ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants