css - 如何在本机反应中添加浮动按钮?
问题描述
我想在本机反应中添加浮动按钮。我已经添加了它,position: absolute
但它显示在最后,即屏幕底部。目前它只显示在底部,即屏幕内容结束的地方。我想在右下角显示浮动按钮,并且在用户上下滚动屏幕时应该可见。
来自反应原生纸的浮动按钮: https ://callstack.github.io/react-native-paper/fab.html#usage
如果我使用 position: 'fixed' 那么它会给我错误https://imgur.com/a/JZJ7Pbl
代码:
<ScrollView>
// Some other View components
<FAB
style={styles.fab}
small
color="#00d048"
icon="add"
/>
</ScrollView>
CSS:
fab: {
position: 'absolute',
right: 0,
bottom: 0,
}
在屏幕截图中,您可以看到按钮没有浮动在内容上,而是显示在屏幕底部。
截屏:
解决方案
React Native 目前不支持position: fixed
,因此我们必须将元素添加到单独View
的绝对位置中。由于我们仍然想滚动其他内容,我们将不得不将这两个包装在另一个中View
:
<View style={{flex: 1}}>
<ScrollView>
// Your other components here
</ScrollView>
<View style={styles.fixedView}>
<Fab
style={styles.fab}
small
color="#00d048"
icon="add"
/>
</View>
</View>
和造型:
fixedView : {
position: 'absolute',
left: 0,
bottom: 0,
flexDirection: 'row',
justifyContent: 'flex-end',
}
可以选择在右侧和底部留出整齐的边距Fab
fab: {
margin-right: theme.spacing.unit * 2,
margin-bottom: theme.spacing.unit * 3,
}
推荐阅读
- html - 为 html 编辑器应用条件 css 样式表
- javascript - 如何使用 Webdatarocks 获取列的总计并在图表中使用它
- php - php 复制的文件上传问题($_FILES 不起作用
- c++ - 为什么我在此代码中收到 SIGSEGV 错误?
- r - 使用来自另一个数据框 R 的信息添加列
- c++ - C++ 隐式构造如何工作,结构初始化?
- javascript - JS Promise:调用一个在resolve中有return语句的函数
- flutter - 如何在 listView.builder 中找到可以跳转到的最后一个值?
- c++ - 刽子手游戏 - 如何在 C++ 中做“错误猜测”?
- azul-zulu - Azul Zulu JRE 中 crs-agent.jar 的用途是什么?