添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
文雅的椅子  ·  Solved: Alteryx ...·  1 周前    · 
爱吹牛的稀饭  ·  Setting Up SerialEM·  6 月前    · 
笑点低的荒野  ·  android AudioTrack ...·  11 月前    · 

The CSS property called z-Index allows us to control the stacking order of elements on a web page. This concept works similarly in React Native, where the z-Index attribute enables the specif­ication of element display order on the screen. By assigning a higher value to an element’s z-index, Elements with a higher z-index value appear on top of elements with lower values. In this article, we will see the working of the Z-index attribute in React Native.

Syntax

<Component style={{ zIndex: value }} />

Here, the Component is the component you want to apply the zIndex to, and the value is the integer representing the stacking order.

Pre-requisites

  • Introduction to React Native
  • React Native Components
  • Expo CLI
  • Node.js and npm
  • Steps to Create a React Native Application

    Step 1: Create a react native application by using this command

    npx create-expo-app <Project-Name>
    

    Step 2: After creating your project folder, i.e. zindexApp, use the following command to navigate to it:

    cd <Project-Name>
    

    Project Structure

    The project structure will look like this:

    Table of Content

  • Using Inline Styling
  • Using External CSS
  • Approach 1: Using Inline Styling

    In this approach, The app showcases a title (“Geeksfo­rgeeks”), a paragraph descr­ibing the purpose (“Z Index Examp­le”), and three styled cards. Each card has its own unique backg­round color and text content. To control the stacking order of these cards, the z-Index property is applied, assigning the lowest value to the first card and incre­ase it up to the highest value for the third card.

    Example: Suppose in this code if we change the z-Index value to 5 then the card one (Which has the background white) will overlay one card two and card three.

    Javascript

    Step 3: To run the React native application, open the command prompt or terminal and enter the command listed below.

    npx expo start
    
  • To run on Android:
  • npx react-native run-android
    
  • To run on iOS:
  • npx react-native run-ios
    

    Output:

    Approach 2: Using External CSS

    The “z-index Property” heading is displayed on top of an image by utilizing its higher zIndex value (1), while the image is posit­ioned bottom the heading with a lower zIndex value (-1).

    Example: This example shows the use of the above-explained approach.

    Javascript

                    source={{
                    style={styles.img}
            </View>
    const styles = StyleSheet.create({
        container: {
            flex: 1,
            justifyContent: "center",
            alignItems: "center",
            position: "absolute",
            margin: 40,
        heading: {
            zIndex: 1, // The heading will be shown on the top of the image
            padding: 10,
            borderRadius: 5,
            fontSize: 20,
            margin: 0,
            color: "crimson",
            fontWeight: "bold",
        img: {
            position: "absolute",
            left: 0,
            top: 0,
            // The image will be shown on the 
            // bottom of the heading
            zIndex: -1, 
            width: 200,
            height: 200,
            borderRadius: 10,
    export default App;
    Create a Card View in React native using react-native-paper
    React Native is a framework developed by Facebook for creating native-style apps for iOS &amp; Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UIs for both platforms. Approach: In this ar
    Create an Activity Indicator in react-native using react-native-paper library
    React Native is a framework developed by Facebook for creating native-style apps for iOS &amp; Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UIs for both platforms. Prerequisites: Basic
    How to add a Progress Bar in react-native using react-native-paper library ?
    React native is a framework developed by Facebook for creating native-style apps for iOS &amp; Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UI's for both platforms. Approach: In this a
    How to add a divider in react-native using react-native-paper library ?
    React native is a framework developed by Facebook for creating native-style apps for iOS &amp; Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UI's for both platforms. Prerequisites: Basi
    How to create a button in react-native using react-native-paper library ?
    React-native is a framework developed by Facebook for creating native-style apps for iOS &amp; Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UI's for both platforms. Prerequisites: Basi
    How to create Chip in react-native using react-native-paper ?
    React native is a framework developed by Facebook for creating native-style apps for iOS &amp; Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render mobile UI's for both platforms. Prerequisites: Basi
    How to Use Routing with React Navigation in React Native ?
    Almost every mobile application requires navigating between different screens. React Native provides an elegant and easy-to-use library to add navigation to native applications: react-navigation. It is one of the most popular libraries used for routing and navigating in a React Native application. Transitioning between multiple screens is managed b
    How to use Flexbox in React Native ?
    Flexbox is used to provide consistency to a layout. It is used to make the layout adaptive to the screen size of the device it is running on. Using flexbox design you can specify that a certain element of layout will span to this fraction of the available space. In React Native, Flexbox is the same as it is for basic CSS. The only difference being
    Should we use TypeScript with React Native ?
    React Native is used to creating apps for Both Android and iOS platforms. It allows you to use a single codebase for both platforms. One of the biggest advantages React Native provides is that it's easy to learn because you don't need to learn a whole new programming language for it. Because it uses well-known javascript under the hood. So develope
    What is the use of ScrollView component in React Native ?
    In this article, we are going to learn about the uses of the ScrollView Component. So firstly let's know what is ScrollView? The ScrollView Component is an inbuilt react-native component that serves as a generic scrollable container, with the ability to scroll child components and views inside it. It provides the scroll functionality in both direct
    We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy  Cookies are not collected in the GeeksforGeeks mobile applications. Got It !
    Please go through our recently updated Improvement Guidelines before submitting any improvements.
    This article is being improved by another user right now. You can suggest the changes for now and it will be under the article's discussion tab.
    You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!
    Please go through our recently updated Improvement Guidelines before submitting any improvements.
    Suggest Changes
    Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.