react-native-keyboard-aware-scroll-view: this.refs.scroll.scrollToFocusedInput is not a function

Ok I’m a bit tired of getting this error. I followed the example you gave:

Error: this.refs.scroll.scrollToFocusedInput is not a function. (In ‘this.refs.scroll.scrollToFocusedInput(reactNode)’, ‘this.refs.scroll.scrollToFocusedInput’ is undefined)

_scrollToInput (reactNode: any) { this.refs.scroll.scrollToFocusedInput(reactNode) }

render() {
    const { title, featured_image, publish_date, author_name, post_body } = this.props.navigation.state.params;
    var datePosted = new Date(publish_date).toString();
    var imageHttps = featured_image.replace(/^http:\/\//i, 'https://');
    return(
        <KeyboardAwareScrollView ref="scroll" style={styles.page}>
            <View style={styles.card}>
                <Image style={styles.image} source={{uri: imageHttps}} />
                <View style={styles.content}>
                    <Text style={styles.title}>{title}</Text>
                    <Text style={styles.postInfo}>Por {author_name}, {datePosted.substr(4,11)}</Text>
                    <View style={styles.separator}></View>
                    {/* REDES SOCIALES (SHARE) */}
                    <Text style={styles.body}>{post_body.replace(/<.+?>/g, '').replace(/&nbsp;/g, ' ')}</Text>
                    {/* REDES SOCIALES (SHARE) */}
                    <View style={styles.separator}></View>
                    <Text style={styles.commentLabel}>Nombre*</Text>
                    <TextInput
                        ref="commentName"
                        style={styles.commentInput}
                        onChangeText={(commentName) => this.setState({commentName})}
                        value={this.state.commentName}
                        onFocus={(event: Event) => {this._scrollToInput(findNodeHandle(event.target))}}
                    />
                </View>
            </View>
        </KeyboardAwareScrollView>
    );
}

Nothing works, please help.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 16

Most upvoted comments

Try this.scroll.props.scrollToFocusedInput(reactNode)

@martimarkov I solved it using following code.

  scrollToTop = () => {
    this.templateFlatList._component.scrollToOffset({ offset: 0, animated: false });
  }

Sorry for the late answer. I did what you told me and I’m still getting the same error: "_this.refs.scroll.scrollToFocusedInput is not a function..." Maybe I’m getting this because I have to views nested inside the KeyboardAwareScrollView? Thanks for the help.