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(/ /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.
try :
_scrollToInput = (reactNode: any) => { this.refs.scroll.scrollToFocusedInput(reactNode) }
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.
Works on my side. You can try to bind the component to _scrollToInput function in constructor, like:
constructor(props) {
super(props);
this._scrollToInput = this._scrollToInput.bind(this);
}
@tibbus just realized it has the same effect with yours answer
Thanks for the answer, but no, still the same error.
@pzehle Can you provide a minimum sample to re-produce this issue? I cannot re-produce it.
Please @pzehle send us a minimum example to try to reproduce the issue.
Thanks!
There's a big change coming in the library, https://github.com/APSL/react-native-keyboard-aware-scroll-view/pull/173
This problem should be addressed by now.
Try this.scroll.props.scrollToFocusedInput(reactNode)
I am facing same problem for flatlist. I am trying to scroll to top but no luck. What I wrote is
this.refs.templateFlatList.scrollToOffset({
offset: 0,
animated: false
})
Having the same issue using the latest version.
@martimarkov I solved it using following code.
scrollToTop = () => {
this.templateFlatList._component.scrollToOffset({ offset: 0, animated: false });
}
@jbaek7023 that worked for me! Anyway that author can update the documentation? That took way too much time to figure out
Thank you @jbaek7023 !
@NoHurryNoPause @webdevinci
Glad it helped 馃憤
The name of function scrollToFocusedInput isn't correct.
Instead of that, please use this function. _scrollToFocusedTextInput.
Most helpful comment
Try this.scroll.props.scrollToFocusedInput(reactNode)