Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
How to dynamically change zIndex in react native?

I'm new to react native, how do I dynamically change the Zindex in react native? or how do I hide/show using some other dynamic way?

import { styles } from './App_styles';

 export default function App() {

  return (
    <View style={styles.body}>
      
      <Pressable onPress={()=>{styles.popup.zIndex=0}}>
      <View style={styles.popup}>
        
      </View>
      </Pressable>

      <View style={styles.main_content}>

      </View>

    </View>
  );
  }

App_styles:

export const styles = StyleSheet.create({

    body:{
        backgroundColor: 'gray',
        height:'100%',
    },

    popup: {
        position:'absolute',
        backgroundColor: 'rgba(0,0,0, 0.5)',
        height:'100%',
        width:'100%',
        zIndex:1,
        alignSelf:'center',
        marginTop:'30%',
    },
    
    main_content:{
        backgroundColor: 'red',
        width:'100%',
        height:'100%'

    },
    
});

I'm not sure how to dynamically change properties in react native using js

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use state to update the style of the popup:

import { styles } from './App_styles';
import {useState} from 'React';

 export default function App() {

  const [zIndex, setZIndex] = useState(1);

  return (
    <View style={styles.body}>
      
      <Pressable onPress={()=>{setZIndex(0)}}>
      <View style={[styles.popup, {zIndex: zIndex}]}>
        
      </View>
      </Pressable>

      <View style={styles.main_content}>

      </View>

    </View>
  );
  }
about 4 years ago · Juan Pablo Isaza Report

0

Just use useState hook

  import { styles } from './App_styles';

  export default function App() {
  const [show, setShow] = useState(true)

  return (
   <View style={styles.body}>
   {show && <View style={styles.popup}>
    
  </View>}
  
  <TouchableOpacity onPress={()=>setShow(!show)}>
  <Text>Show/Hide</Text>
  </TouchableOpacity>

  <View style={styles.main_content}>

  </View>

</View>
  );
 }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!