Skip to content

Conversation

@yury
Copy link
Contributor

@yury yury commented Apr 4, 2017

In our app redux can switch navigation when input is in focus.
When this happen we get crash:

TypeError
undefined is not an object (evaluating 'this.refs._rnkasv_keyboardView.getScrollResponder')

This PR make getScrollResponder a little bit safer.

@Swordsman-Inaction
Copy link
Collaborator

It does look safer with this changes, but I'd like to know why this.refs._rnkasv_keyboardView becomes undefined.

@yury
Copy link
Contributor Author

yury commented Apr 5, 2017 via email

@Swordsman-Inaction
Copy link
Collaborator

@yury
Hi, I created a demo with the code below. A new scene would be open while the TextInput is still in focus, but cannot reproduce the error. Can you help me to find the cause?

import React, { Component } from 'react';
import ReactNative, {
  View,
  Text,
  TextInput,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';

export class First extends Component {

  static navigationOptions = {
    title: 'First',
  }

  constructor(props) {
    super(props);

    this.onChangeText = this.onChangeText.bind(this);
  }

  onChangeText(text) {
    if (text === '123') {
      this.props.navigation.navigate('Second');
    }
  }

  render() {
    return (
      <KeyboardAwareScrollView extraHeight={80}>
        <TextInput style={{height: 44, marginTop: 500, backgroundColor: 'green'}} onChangeText={this.onChangeText} />
      </KeyboardAwareScrollView>
    );
  }
}

class Second extends Component {

  static navigationOptions = {
    title: 'Second',
  };

  render() {
    return (
      <Text>Test</Text>
    );
  }

}

const AppContainer = StackNavigator({
  First: { screen: First },
  Second: { screen: Second },
});

export default AppContainer;

@yury
Copy link
Contributor Author

yury commented Apr 5, 2017

@Swordsman-Inaction

This is minimal repo I came up with.

It is something with linking...

Here is the video

Better to run device in release configuration.

Not 100% reproducible every time. But it happens from time to time.

@Swordsman-Inaction
Copy link
Collaborator

@yury Awesome!!! I debugged with your code, and I already find the cause.

  • After the App is resumed from the Deep link, the keyboard would show again, and the updateKeyboardSpace would be called again.
  • We are using async functions which are UIManager.viewIsDescendantOf, UIManager.measureInWindow and a timeout in scrollToFocusedInput.
  • Before those async functions finish their job, the App will start handling the deep link in _handleOpenURL which replaces the Screen1 with Screen3 . So KeyboardAwareScrollView would be unmount for sure.
  • After those async functions finish their job, the KeyboardAwareScrollView doesn't exist anymore which causes this error.
  • The reason it's not 100% reproducible is sometimes those async functions are too slow, so UIManager.viewIsDescendantOf and UIManager.measureInWindow would fail because the component doesn't exist and the app would only give a warning in console, or those async functions finished their job before the component is unmounted so nothing happens.

So we found the cause :) ! This PR could prevent the app from crashing for sure, but it also covers the real problem we have. The solution for this could be adding unmount-checking in the callbacks.

Would you like to update this PR or create another PR to solve the problem?

@yury
Copy link
Contributor Author

yury commented Apr 6, 2017

This isMounted?

@Swordsman-Inaction
Copy link
Collaborator

@yury Yes, I know it looks bad. I thought about doing some clean in the willUnmount function, but I cannot find a good way to cancel the callbacks. But we can use clearTimeout() for that timeout. It would be great if you have a better way to do it.

@alvaromb
Copy link
Collaborator

alvaromb commented May 3, 2017

In the meantime, I think this PR makes sense.

@yury
Copy link
Contributor Author

yury commented May 3, 2017

I looked at react native FlatList they do similar thing thing

PS: Do you plan to refactor and do not use mixins?

@alvaromb
Copy link
Collaborator

@yury yes, it's on my roadmap but I'm busy as hell right now.

@alvaromb alvaromb merged commit dcb3568 into APSL:master May 18, 2017
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

Successfully merging this pull request may close these issues.

3 participants