In React Native, how do I put a view on top of another view, with part of it lying outside the bounds of the view behind?

前端 未结 7 848
一向
一向 2020-12-23 18:50

I\'m trying to make a layout as per below with React Native.

\"enter

How do I

7条回答
  •  时光说笑
    2020-12-23 19:22

    You can use this OverlayContainer. The trick is to use absolute with 100% size. Check below an example:

    // @flow
    
    import React from 'react'
    import { View, StyleSheet } from 'react-native'
    
    type Props = {
      behind: React.Component,
      front: React.Component,
      under: React.Component
    }
    
    // Show something on top of other
    export default class OverlayContainer extends React.Component {
      render() {
        const { behind, front, under } = this.props
    
        return (
          
            
              
                {behind}
              
              {front}
            
            {under}
          
        )
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        alignItems: 'center',
        height: '100%',
        justifyContent: 'center',
      },
      center: {
        width: '100%',
        height: '100%',
        alignItems: 'center',
        justifyContent: 'center',
      },
      behind: {
        alignItems: 'center',
        justifyContent: 'center',
        position: 'absolute',
        left: 0,
        top: 0,
        width: '100%',
        height: '100%'
      }
    })
    

提交回复
热议问题