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

185
Vistas
Navigate and change item style

I am currently trying to make a header for my app which has items and these items need to appear with an active style when the user is in the screen corresponding to the item.

Currently, my header is devided in two components: one component for the item in the header (HeaderItem) and another for the header (Header) itself

When I click the item, it can set its style to active and it will navigate the user to another screen, so it's working as expected. But if I navigate to a screen through another button that is not a HeaderItem I cannot make its style change. I was expecting that when I change the screen (even through another button) and my HeaderItem renders again it would check if it should have another style, but it doesn't seem to work

This is my first app, so I might be getting something wrong.

Bellow are the components I referred above

// Basic
import React from 'react';
import {Image, View} from 'react-native';
import {RectButton} from 'react-native-gesture-handler';
import {useNavigation} from '@react-navigation/core';
import {useRoute} from '@react-navigation/native';

// Assets
import styles from '../HeaderItem/styles';

const HeaderItem = ({image, screen}) => {
  const route = useRoute();
  const navigation = useNavigation();
  let is_active = route.name === screen ? true : false;

  function goToScreen() {
    navigation.navigate(screen);
  }

  return (
    <RectButton
      style={is_active ? styles.menu_item__active : styles.menu_item}
      onPress={goToScreen}>
      <Image source={image} style={styles.image} />
      {is_active && <View style={styles.pseudo_border} />}
    </RectButton>
  );
};

export default HeaderItem;

// Basic
import React from 'react';
import {View} from 'react-native';

// Assets
import styles from '../Header/styles';
import images from '../../config/images';

// Components
import HeaderItem from '../HeaderItem';

const Header = () => {
  return (
    <View style={styles.wrapper}>
      <HeaderItem image={images.content} screen="Content" />
      <HeaderItem image={images.dentist} screen="Login" />
      <HeaderItem image={images.safety} screen="HealthPlan" />
      <HeaderItem image={images.calendar} screen="Content" />
      <HeaderItem image={images.medium_logo} screen="Map" />
    </View>
  );
};

export default Header;

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
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