css - 如何在 native react 中添加 float 按钮?

标签 css reactjs react-native

我想在 React Native 中添加 float 按钮。我已经添加了 position: absolute但它显示在最后,即在屏幕的底部。目前它只显示在底部,即屏幕内容结束的地方。我想在右下 Angular 显示 float 按钮,当用户上下滚动屏幕时应该可见。

来自 react 原生纸的 float 按钮: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,
    }

在屏幕截图中,您可以看到按钮没有 float 在内容上,而是显示在屏幕底部。

截屏:

enter image description here

最佳答案

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,
}

关于css - 如何在 native react 中添加 float 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54402576/

相关文章:

html - 通过 Icomoon 导入时 SVG 宽度会扩大

javascript - Material-ui TextField dom元素如何自定义

firebase - 如何检查 Firebase 数据库中是否存在项目? - react native 火力基地

javascript - 如何创建正则表达式模式来从 React 中的字符串中删除多个子字符串?

reactjs - 如果在 HTML 元素上设置 role = ""会发生什么?

react-native - 堆栈导航器之间的 react 导航 goBack

jquery - 列在 wordpress 中具有 100% 的高度

html - 我的媒体查询不起作用

javascript - 如何让网站导航菜单在设定的秒数后出现?

javascript - webpack 开发服务器仅重新加载一次