8

I bought this Theme which in Expo works flawlessly, but as soon as I build the APK, the Keyboard will cover the whole screen and wont work as supposed.

I'm using expo for testing and it works just fine.

 return (
            <SafeAreaView style={styles.container}>
                <NavHeader title={thread.name} {...{navigation}} />
                <FlatList
                    inverted
                    data={messages}
                    keyExtractor={message => `${message.date}`}
                    renderItem={({ item }) => (
                        <Msg message={item} name={item.me ? name : thread.name} picture={thread.picture} />
                    )}
                />
                <KeyboardAvoidingView behavior={Platform.OS === "ios" ? "padding" : "height"} enabled>
                    <View style={styles.footer}>
                        <TextInput
                            style={styles.input}
                            placeholder="Write a message"
                            value={this.state.message}
                            onChangeText={message => this.setState({ message })}
                            autoFocus
                            blurOnSubmit={false}
                            returnKeyType="send"
                            onSubmitEditing={this.send}
                            underlineColorAndroid="transparent"
                        />
                        <TouchableOpacity primary transparent onPress={this.send}>
                            <Text style={styles.btnText}>Send</Text>
                        </TouchableOpacity>
                    </View>
                </KeyboardAvoidingView>
            </SafeAreaView>
        );

And the Styles

const styles = StyleSheet.create({
    container: {
        flex: 1
    },
    footer: {
        borderColor: Theme.palette.lightGray,
        borderTopWidth: 1,
        paddingLeft: Theme.spacing.small,
        paddingRight: Theme.spacing.small,
        flexDirection: "row",
        alignItems: "center"
    },
    input: {
        height: Theme.typography.regular.lineHeight + (Theme.spacing.base * 2),
        flex: 1
    },
    btnText: {
        color: Theme.palette.primary
    }
});

I have tried the following plugin

using the enableOnAndroid prop

https://github.com/APSL/react-native-keyboard-aware-scroll-view

with no success.

I have posted here:

https://github.com/APSL/react-native-keyboard-aware-scroll-view/issues/305

and here:

https://github.com/expo/expo/issues/2172

Donnie Darko
  • 509
  • 3
  • 15

2 Answers2

1

Unfortunately this is a known issue

https://github.com/expo/expo/issues/2172

Slbox
  • 10,957
  • 15
  • 54
  • 106
0

Depending on the complexity of your screen layout you could add a bottom margin or padding using Keyboard listeners provided by React Native.

import React, { Component } from 'react';
import { Keyboard, TextInput } from 'react-native';

class Example extends Component {
    componentDidMount () {
        this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
        this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
    }

    componentWillUnmount () {
        this.keyboardDidShowListener.remove();
        this.keyboardDidHideListener.remove();
    }

    _keyboardDidShow () {
        this.setState({
            marginBottom: 400
        })
    }

    _keyboardDidHide () {
        this.setState({
            marginBottom: 0
        })
    }

    render() {
        return (
            <TextInput
                style={{marginBottom: this.state.marginBottom}}
                onSubmitEditing={Keyboard.dismiss}
            />
        );
    }
}
basbase
  • 1,225
  • 7
  • 19
  • In this case, you are assuming that all Android keyboards height is 400? that sounds not safe don't you think? – Donnie Darko Sep 05 '18 at 21:11
  • It's just a suggestion, set it to a high enough value and you'll cover most use cases (really depends on your screen layout). If you need keyboard height you can try this answer: https://stackoverflow.com/a/46913772/10236907 – basbase Sep 05 '18 at 21:31