简体   繁体   English

我如何在React Native中实现以下设计?

[英]How can i achieve below design in react native?

I'm little bit stuck here to achieve below design in one of my app. 我有点想在我的应用程序中实现低于设计的水平。

图片

My code is here, 我的代码在这里,

<View style={{flex: 1, backgroundColor: '#fff', alignItems: 'center'}}>
        <View style={{backgroundColor: 'rgb(25,195,192)', width: '100%', height: '40%', borderBottomLeftRadius: 100, borderBottomRightRadius: 100}}>
        </View>
</View>

I've not added text yet, but i want to border curved like image and it's not getting. 我还没有添加文本,但是我想像图像一样弯曲边界,但没有得到。

Any help would be appreciated. 任何帮助,将不胜感激。

Use the following style to your curved view, 对弯曲的视图使用以下样式,

curvedViewStyle: {
    borderRadius: window.width,
    width: window.width * 2,
    height: window.width * 2,
    marginLeft: -(window.width / 2),
    position: "absolute",
    bottom: 0,
    overflow: "hidden",
    backgroundColor: "red"
  },

and don't forgot to add 'window' on top, const window = Dimensions.get("window"); 并且不要忘记在顶部添加“ window”, const window = Dimensions.get("window");

In order to get a circle, you need to create a square (width === height) and set the borderRadius to halve of its width or height. 为了得到一个圆,您需要创建一个正方形(宽度===高度),并将borderRadius设置为其宽度或高度的一半。

In your case; 就你而言 you need to calculate the value for getting only the 30% of the bottom side showing (use negative marginTop), and also calculate how the value for making sure the center of the circle to be the same as the center of screen width (use negative marginLeft). 您需要计算仅获取显示的底侧的30%的值(使用负marginTop),还需要计算确保圆心与屏幕宽度的中心相同的值(使用负数marginLeft)。 Below are an example of this. 下面是一个示例。

render() {
    return (
      <View style={myStyle.container}>
        <View style={myStyle.top_background}>
          <View style={myStyle.top_content}>
            <Text style={myStyle.text1}>Hey there</Text>
            <Text style={myStyle.text1}>WHAT'S UP</Text>
            <Text style={myStyle.text1}>Doc'?</Text>
            <Text style={myStyle.text2}>BUGS BUNNY</Text>
          </View>
        </View>
      </View>
    );
}

and the stylesheet 和样式表

const sWidth  = Dimensions.get('window').width;
const sHeight = Dimensions.get('window').height;
const ratio   = sWidth / sHeight; //sWidth = ratio * sHeight
const myStyle = StyleSheet.create({
  container: {
    width: sWidth,
    height: sHeight,
    backgroundColor: '#fff'
  },
  top_background: {
    width: sHeight * 2,
    height: sHeight * 2,
    borderRadius: sHeight * 1,
    borderTopLeftRadius: 0,
    borderTopRightRadius: 0,
    backgroundColor: '#aaa',
    alignItems: 'center',
    marginLeft: ((ratio * sHeight) * 0.5) - (sHeight),
    marginTop: -sHeight * 1.7,
    paddingTop: sHeight * 1.7,
  },
  top_content: {
    paddingTop: sHeight * 0.02,
    width: sWidth,
    height: sHeight * 0.3,
    alignItems: 'center',
  },
  text1: {
    fontSize: 14,
    color: '#fff'
  },  
  text2: {
    marginTop: sHeight * 0.1,
    fontSize: 25,
    fontWeight: 'bold',
    color: '#fff'
  }
});

the marginTop and paddingTop in top_background is for only using the top 30% of the screen and starts the content in the section that can be seen in the screen respectively. top_background中的marginTop和paddingTop仅用于使用屏幕的前30%,并分别在屏幕上可以看到的部分中启动内容。

You can achieve this curve design using SVG. 您可以使用SVG实现此曲线设计。 SVG provides several elements and with its properties (Rect, Circle, Line, Polyline, Polygon, G, etc). SVG提供了几种元素及其属性(Rect,Circle,Line,Polyline,Polygon,G等)。 You can customize design according to your need. 您可以根据需要自定义设计。

https://www.npmjs.com/package/react-native-svg?activeTab=versions https://www.npmjs.com/package/react-native-svg?activeTab=versions

import Svg,{ Circle } from 'react-native-svg';


<Circle 
       cx={screenWidth / 2}
       cy={`-${898 - headerHeight + 2}`} 
       r="898.5" fill="#87ceeb"
       stroke="#87ceeb" 
      strokeWidth="2" 
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在React Native中实现以下设计 - How can i achieve below design in react native 如何在React Native中实现以下设计? - How to achieve below design in react native? 如何在 React Native 中实现“视图滑入”效果? - How can I achieve the "View slide-in" effect in react native? 我如何在 React Native 中使用 SectionList 实现这种布局 - How can i achieve this layout using SectionList in React native 我怎样才能在 React Native 中实现这个 3 方形布局? - How can I achieve this 3 square layout in react native? 考虑到我不能在 React Native 中使用 calc() 或子选择器,如何在 React Native 中实现这个非常简单的布局? - How to achieve this very simple layout in React Native considering I can't use calc() or child selectors in React Native? 如何实现在React Native上具有活动的尖/箭头/三角形选项卡? - How can I achieve to have active pointy/arrow/triangle tabs on React Native? 当用户按下按钮时,如何在 react-native 中实现以下代码 - How do you achieve the below code in react-native when user presses a button 如何在 React Native 中实现涟漪效果 - How to achieve the ripple effect in React Native 我怎样才能实现该 react-bootstrap 组件的 100% 可重用性? - How can i achieve 100% reusability of that react-bootstrap component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM