Transparent overlay in React Native

后端 未结 6 1576
陌清茗
陌清茗 2020-12-23 13:38

I\'m trying to get a transparent overlay sliding down in an app, pretty much like this here (all/filter-by):

\"t

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 14:13

    The key to your ListView not moving down, is to set the positioning of the overlay to absolute. By doing so, you can set the position and the width/height of the view manually and it doesn't follow the flexbox layout anymore. Check out the following short example. The height of the overlay is fixed to 360, but you can easily animate this or make it dynamic.

    'use strict';
    
    var React = require('react-native');
    var Dimensions = require('Dimensions');
    
    // We can use this to make the overlay fill the entire width
    var { width, height } = Dimensions.get('window');
    
    var {
      AppRegistry,
      StyleSheet,
      Text,
      View,
    } = React;
    
    var SampleApp = React.createClass({
      render: function() {
        return (
          
            
              Welcome to the React Native Playground!
            
            
          
        );
      }
    });
    
    var styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
      },
      welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
      },
      // Flex to fill, position absolute, 
      // Fixed left/top, and the width set to the window width
      overlay: {
        flex: 1,
        position: 'absolute',
        left: 0,
        top: 0,
        opacity: 0.5,
        backgroundColor: 'black',
        width: width
      }  
    });
    
    AppRegistry.registerComponent('SampleApp', () => SampleApp);
    
    module.exports = SampleApp;
    

提交回复
热议问题