react-native - 如何强制模态中的内容为模态高度的 100%?
问题描述
我正在尝试使用 flexbox 使 Modalize 视图中的内容变为 Modal 视图的 100%。目前,它只会达到内容的高度,而不是模态。
使用此代码:
<Modalize
// onOpen={onOpen}
onOpened={() => console.log("ONOPEN")}
ref={modalizeRef}
modalStyle={{ flex: 1,
backgroundColor: 'yellow',
shadowColor: '#000', shadowOffset: { width: 0, height: 6 }, shadowOpacity: 0.45, shadowRadius: 16,
}}
alwaysOpen={85}
handlePosition="inside"
>
<View style={{ flex: 1, backgroundColor: 'green' }}>
<Text>
Data here
</Text>
</View>
</Modalize>
它看起来像这样:
我怎样才能使绿色背景填充模态的整个高度?
解决方案
用于Dimensions
设置高度。
示例:世博小吃
import * as React from 'react';
import { Text, View, StyleSheet, Dimensions } from 'react-native';
import Constants from 'expo-constants';
import { Modalize } from 'react-native-modalize';
const window = Dimensions.get('screen');
export default function App() {
const modalizeRef = React.useRef();
return (
<View style={styles.container}>
<Modalize
// onOpen={onOpen}
onOpened={() => console.log('ONOPEN')}
ref={modalizeRef}
modalStyle={{
flex: 1,
backgroundColor: 'yellow',
shadowColor: '#000',
shadowOffset: { width: 0, height: 6 },
shadowOpacity: 0.45,
shadowRadius: 16,
}}
alwaysOpen={85}
handlePosition="inside">
<View style={{ height: window.height * 0.85, backgroundColor: 'green' }}>
<Text>Data here</Text>
</View>
</Modalize>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});
推荐阅读
- java - 计算二维数组JAVA中单元周围的地雷数量
- javascript - 谷歌云任务未将正文发送到 http 云功能
- google-api - 如何从我们的网站安装 G Suite Marketplace 应用程序?(与谷歌按钮集成)
- c# - 在 C# 中以 O(1) 扩展列表 (AddRange)
- python - AttributeError:模块“pandas_ml”没有属性“imbaccessors”
- angular - 测试 HTTP 请求的请求和结果之间的条件
- python - 如何读取文件夹中的图像并存储它们的类号和图像数据?Python
- python - 将多维列表中的数据添加到数据框
- r - 我可以避免评估内联 Rmarkdown `r code` 块吗?
- machine-learning - 如何使用 SIFT/SURF 分割 ROI