Chìa khóa để ListView của bạn không di chuyển xuống, là đặt vị trí của lớp phủ thành absolute
. Bằng cách đó, bạn có thể đặt vị trí và chiều rộng/chiều cao của chế độ xem theo cách thủ công và nó không theo bố cục flexbox nữa. Hãy xem ví dụ ngắn sau đây. Chiều cao của lớp phủ được cố định thành 360, nhưng bạn có thể dễ dàng tạo hiệu ứng này hoặc làm cho nó động.
'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 (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to the React Native Playground!
</Text>
<View style={[styles.overlay, { height: 360}]} />
</View>
);
}
});
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;
Tôi nghĩ rằng bạn có thể thử [thành phần này] (https://github.com/xotahal/react-native-pullable-view) . Tôi có nghĩa là bạn chỉ nên đặt 'vị trí: 'tuyệt đối' 'để xem đó là kéo xuống và nó có thể làm việc. –