Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
Flexbox - React Native

i am new to react native and i am trying to make a chat app layout. enter image description here

As you can see in screenshot that i have attached, i want text box to take as much space as the text in it. For example, if i send 'Hi', it should only be stretched as much space 'Hi' needs. If i send a long text, then it should stretch and take as much space as that text is. Like it happens in almost all texting apps.

The text box code is:

<TouchableOpacity>
        <View style={styles.containerSent}>
          <View style={{flex: 3}}>
            <Text style={styles.message}>{item.message}</Text>
          </View>
          <View style={{flex: 1}}>
            <Image
              source={require('../assets/images/check.png')}
              style={styles.image}
            />
            <Text style={{textAlign: 'right', color: 'white'}}>
              {msToTime(item.timestamp)}
            </Text>
          </View>
        </View>
      </TouchableOpacity>

Stylesheet

  containerSent: {
    flex: 1,
    maxWidth: '70%',
    // minWidth: '30%',
    marginTop: 20,
    paddingTop: 20,
    paddingHorizontal: 10,
    paddingBottom: 10,
    borderWidth: 1,
    backgroundColor: '#6F2232',
    borderRadius: 20,
    alignSelf: 'flex-end',
    flexDirection: 'row',
    justifyContent: 'space-between',
    // justifyContent: 'flex-end',
  },

  message: {
    color: 'white',
    fontSize: 15,
    fontWeight: 'bold',
    textAlign: 'left',
    alignSelf: 'stretch',
  },

  image: {
    width: 15,
    height: 15,
    marginLeft: 20,
    marginBottom: 5,
    alignSelf: 'flex-end',
  },
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Set View style to flex: 0 so it‘s just taken as Maus h space as necessary.

  <TouchableOpacity>
    <View style={styles.containerSent}>
      <View style={{ flex: 0 }}>
        <Text style={styles.message}>{'q.a'}</Text>
      </View>
      <View style={{ flex: 0, paddingLeft: 10 }}>
        <Text style={styles.message}>{'eeeee.message'}</Text>
      </View>
    </View>
  </TouchableOpacity>

Take a look at my sample

about 4 years ago · Juan Pablo Isaza Denunciar

0

How I have implemented this is that I removed flex: 3 and flex: 1 from both the elements so that they don't expand to take the max space, and I added flexShrink: 1 to the text, so that it always shrinks keeping the right element intact.

Snack link

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda