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

159
Visualizações
React Native: View not covering parent height

Issue

There are 2 tabs stacked horizontally and in the first tab, the view in green color isn’t able to fill the parent's height when the content is different in both the Tabs.

enter image description here

Reproducible in Expo

https://snack.expo.dev/@vinay-sharma/92706e

Code

import React from "react";
import { Text, View } from "react-native";

const Tab = ({ textNodes }) => {
  return (
    <View style={{ flex: 1, backgroundColor: "red" }}>
      <View style={{ flexDirection: "row" }}>
        <View style={{ backgroundColor: "blue", width: 10 }}></View>

        {/* the green view isn’t able to fill parent's height*/}
        <View style={{ backgroundColor: "green", flex: 1 }}>
          {textNodes.map((node) => (
            <Text>{node}</Text>
          ))}
        </View>
      </View>

      <View style={{ height: 10, backgroundColor: "black" }} />
    </View>
  );
};

export default function App() {
  return (
    <View style={{ flexDirection: "row", marginTop: 25 }}>
      <Tab textNodes={[1, 2, 3]} />
      <Tab textNodes={[1, 2, 3, 4]} />
    </View>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Just add style property height: '100%' in the row view in your Tab() function

The first element is not taking 100% of the height because it has less Childs (default behaviour of a View, doc)

import React from 'react';
import { Text, View } from 'react-native';

const Tab = ({ textNodes }) => {
  return (
    <View style={{ flex: 1, backgroundColor: 'red' }}>
      <View style={{ flexDirection: 'row', height: '100%' }}> //here add height 100%
        <View style={{ backgroundColor: 'blue', width: 10 }}></View>

        {/* the green view isn’t able to fill parent's height*/}
        <View style={{ backgroundColor: 'green', flex: 1 }}>
          {textNodes.map((node)=><Text>{node}</Text>)}
        </View>
      </View>

      <View style={{ height: 10, backgroundColor: "black" }} />
    </View>
  )
}

export default function App() {
  return (
    <View style={{ flexDirection: 'row', marginTop: 25 }}>
      <Tab textNodes={[1, 2, 3]} />
      <Tab textNodes={[1, 2, 3, 4]} />
    </View>
  );
}
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