react-native - React Native如何实现圆角的上层背景组件?

标签 react-native user-interface frontend

在我的一个使用 React Native 的副项目中,我试图为个人资料页面制作一个精美的 UI。我想制作一个可自定义的上半部分背景组件,例如 Creative Tim 的 Soft-UI 组件,但我不太确定最好的方法是什么。

这是我要完成的任务的快照。 Soft-UI profile page

如有任何帮助,我们将不胜感激。

最佳答案

这是我根据您的需要制作的完整示例 (https://snack.expo.dev/@heytony01/curious-apples)。我在下面解释我做了什么。

关键是理解flex boxposition absolute。学习flex box的好地方是( https://flexboxfroggy.com/ ) .阅读绝对位置的文档 ( https://reactnative.dev/docs/layout-props )

先用flex box让一个view覆盖屏幕底部2/3,顶部屏幕覆盖屏幕顶部1/3

<View style={{flex:1}}>

         {/* Top  1/3*/}
        <View style={{flex:1,justifyContent:"center",alignItems:"center"}}>
        
        </View>

        {/* Bottom  2/3*/}
       <View style={{flex:2,justifyContent:"center",alignItems:"center"}}>

      </View>

</View>

下一步制作顶级用户配置文件组件

<View style={{flex:1}}>

         {/* Top  1/3*/}
        <View style={{flex:1,justifyContent:"center",alignItems:"center"}}>
           
          {/* Purple card*/}
           <View style={{
            width:"90%",
            height:"90%",
            backgroundColor:"purple",
            borderRadius:"5%",
            justifyContent:"center",
            alignItems:"center",
            fontSize:10
            }}>
              
            </View>
        
        </View>

        {/* Bottom  2/3*/}
        
       <View style={{flex:1,justifyContent:"center",alignItems:"center"}}>

      </View>
</View>

接下来将跟随栏设为绝对位置,这样您就可以覆盖其他 View

<View style={{flex:1}}>

         {/* Top  1/3*/}
        <View style={{flex:1,justifyContent:"center",alignItems:"center"}}>
           
          {/* Purple card*/}
           <View style={{
            width:"90%",
            height:"90%",
            backgroundColor:"purple",
            borderRadius:"5%",
            justifyContent:"center",
            alignItems:"center",
            fontSize:10
            }}>
              
            </View>

           {/* Postion absloute bar*/}
           <View style={{
           zIndex:99, // Puts it above the other view
           position:"absolute",
           flexDirection:"row",
           bottom:-5,
        
           width:"70%",
           height:"20%",
           backgroundColor:"lightgray",
           borderRadius:10}}>
              
           </View>
        
        </View>

        {/* Bottom  2/3*/}
        
       <View style={{flex:1,justifyContent:"center",alignItems:"center"}}>
    
       </View>
      
</View>

关于react-native - React Native如何实现圆角的上层背景组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69906707/

相关文章:

javascript - Android 的错误代码 : 500 on react native 0. 56

python - 如何选择在 Python 中运行的类?

javascript - jQuery 工具(水平 Accordion )与 jQuery UI(选项卡)相结合?

javascript - 如何跟踪表单中的焦点元素

javascript - 如果启用了热模块替换,为什么在更改 HTML 时 LiveReload 在 Webpack 中不起作用?

android - android 上的自定义 editText

react-native - 如何通过单击 DrawerLayoutAndroid 更改场景(导航器)

react-native - react-native 导航栏中的侧边菜单

javascript - 可能的未处理 promise 拒绝(id :0) Warning in react native

java - 如何更改新 Material 主题中后退箭头的颜色?