Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
Keyboard covers input text (one long vertical input), text also runs off the screen without actively being scrolled to (react native)

It's been 7 hours, I've read all the docs and similar SO questions, so any help would be appreciated.

My goal: have an app screen where the top 1/3 of the screen is made up of custom components (not the problem), and then the bottom 2/3 of the screen is a giant full-width super-long scrollable textfield for the user to enter several paragraphs (the problem)

The problem: Either the on-screen keyboard covers the text from the textfield, the textfield isn't scrollable, or when typing and you go off the bottom of the screen you aren't scrolled along with what you're typing - or a mix of all the 3.

Here is a rough image of what I desire: enter image description here

Currently, my code looks like this:

export default function Post() {

    const [text, setText] = useState("");
    return (

        <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
        <SafeAreaView >
        <KeyboardAvoidingView enabled behavior='height' keyboardVerticalOffset={40} >

                <View>
                    <TextInput scrollEnabled={true} placeholderTextColor={LIGHT} maxLength={300000} placeholder="enter text" multiline={true} onChangeText={(newVal) => setText(prev => {prev + newVal})} value={text}/>
                </View>
           
        </KeyboardAvoidingView>

        </SafeAreaView>
        </TouchableWithoutFeedback>

    );
}

const styles = StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: WHITE,
      alignItems: 'center',
      justifyContent: 'flex-center',
      alignItems: "center",
      marginHorizontal: 15,
    //   height: "100%",
    },
    textfield: {
        textAlign: "left",
        textAlignVertical: "top",
        backgroundColor: "lavender",
        height: "100%",
        flex: 1,
    },
    scroll: {
        // width: "100%"
    }
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Couple of issues with your approach and code in general.

textfield isn't scrollable

Placing anything scrollable inside a touchable is really weird and rarely behaves as you expect it, so avoid if possible, or if you really need it then pass a onStartShouldSetResponder={() => true} to your inner scroll view. But in your case, I suspect you don't actually want the keyboard to close if the user clicks inside the textInput, do you? He probably wants to add a word to a previous sentence or fix a type. Instead I suggest catching the touch outside of the textInput only, e.g. in your top third. Something like this (scrabble snack) should work:

import React, { useState } from 'react';
import { Text, View, StyleSheet, Touchable, TouchableWithoutFeedback, SafeAreaView, KeyboardAvoidingView, TextInput, Keyboard } from 'react-native';

export default function App() {
    const [text, setText] = useState("");
    return (
      <KeyboardAvoidingView style={{flex: 1, marginTop: 45}} behavior="padding">
          <View style={styles.upperContainer} onTouchStart={Keyboard.dismiss}>
            <Text>My content in top third </Text>
          </View>
          <View style={styles.lowerContainer}>
            <TextInput 
              scrollEnabled={true} 
              placeholderTextColor={"lightgrey"} 
              maxLength={300000} 
              placeholder="enter text" 
              multiline={true} 
              onChangeText={(newVal) => setText(prev => {prev + newVal})} 
              value={text}
            />
          </View>
      </KeyboardAvoidingView>
    );
}

const styles = StyleSheet.create({
  upperContainer: {
    flex: 1, 
    borderWidth: 2, 
    borderColor: "grey", 
    alignItems: "center", 
    justifyContent: "center"
  },
  lowerContainer: {
    flex: 2, 
    borderColor: "black", 
    borderWidth: 2, 
    padding: 10
  }
})

Notice how I pass flex 1 and 2 to the two child views to style them how you required it. The border is just added for better visibility.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda