Open leanminmachine opened 7 years ago
try to change ScrollView on parent Form.js and change to KeyboardAwareScrollView
its worked for me
yes @PonorogoCreativeIT , it works for me too, thanks!
render() {
const { children, ...rest } = this.props
return (
<View style={{ flex: 1 }} onLayout={this.onLayout}>
<ScrollView>
<KeyboardAvoidingView behavior="position" contentContainerStyle={{ minHeight: this.state.height }}>
{ children }
</KeyboardAvoidingView>
</ScrollView>
</View>
)
}
@sun2rise how do you define this.state.height?
@truca in case it's still relevant, or relevant for others, this is (approximately) what I did. Not sure it's the ideal, but it preserves the minHeight in the ScrollView's contentContainer, when the keyboard is up. Hope that helps.
class AppWrap extends Component {
state = {
contentHeight: 0,
};
handleContentSizeChange = (contentWidth, contentHeight) => {
if (this.state.contentHeight === 0) {
this.setState({ contentHeight });
}
};
render() {
const { children, contentContainerStyle, style } = this.props;
return (
<KeyboardAvoidingView
style={{flex: 1}
behavior="padding"
>
<ScrollView
onContentSizeChange={this.handleContentSizeChange}
style={{
flex: 1,
width: "100%",
}}
contentContainerStyle={[
{
flex: 1,
width: "100%",
},
{ minHeight: this.state.contentHeight },
]}
>
{children}
</ScrollView>
</KeyboardAvoidingView>
);
}
}
Did you try this?
<ScrollView style={{ flex: 1 }}>
<KeyboardAvoidingView
enabled
behavior='position'
keyboardVerticalOffset={200}
>
<View style={{ flex: 1 }}>
{ children have TextInput}
</View>
</KeyboardAvoidingView>
</ScrollView>
You would need to set the value of keyboardVerticalOffset
to make the input display as expect while the keyboard display.
And don't forget <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
wrapper these code to make more friendly.
Do you still use the package? I stopped working with it because I just have rights on GitHub and not on npm and therefore it makes not really sense to continue with it. I guess @esbenp is to busy and also stopped maintenance.
I am just curious if it is still a topic for you. Because if Esben is also interested we can overhaul the package and update some stuff.
How do you use KeyboardAvoidingView with this library? Does not seem to work aka auto-scroll to input.
Tried https://github.com/APSL/react-native-keyboard-aware-scroll-view as well but same issue - it does not scroll