RN封装三角形组件(只支持上下箭头)

js 复制代码
import React from 'react';
import { View, StyleSheet } from 'react-native';

const Triangle = ({ direction, width, height, color }) => {
  // 根据方向选择三角形的样式
  const triangleStyle =
    direction === 'up'
      ? {
          borderTopWidth: 0,
          borderBottomWidth: height,
          borderLeftWidth: width / 2,
          borderRightWidth: width / 2,
          borderTopColor: 'transparent',
          borderBottomColor: color,
          borderLeftColor: 'transparent',
          borderRightColor: 'transparent',
        }
      : {
          borderTopWidth: height,
          borderBottomWidth: 0,
          borderLeftWidth: width / 2,
          borderRightWidth: width / 2,
          borderTopColor: color,
          borderBottomColor: 'transparent',
          borderLeftColor: 'transparent',
          borderRightColor: 'transparent',
        };

  return <View style={[styles.triangle, triangleStyle]} />;
};

const styles = StyleSheet.create({
  triangle: {
    width: 0,
    height: 0,
    backgroundColor: 'transparent',
    borderStyle: 'solid',
  },
});

export default Triangle;

direction(方向)、size(大小)和 color(颜色)作为属性来指定三角形的样式参数 使用

js 复制代码
import Triangle from './uitl.js'

export default function App(){
	return(
		//红色向上箭头,尺寸20
		<Triangle direction="up" width={20} height={10} color="red" />
		// 蓝色向下箭头,尺寸20
		<Triangle direction="down" width={20} height={10} color="blue" />
	)
}

效果图

相关推荐
Doris8936 分钟前
【 Vue】 Vue3全面讲解文档
前端·javascript·vue.js
Hexene...16 分钟前
【前端Vue】如何快速直观地查看引入的前端依赖?名称版本、仓库地址、开源协议、作者、依赖介绍、关系树...(Node Modules Inspector)
前端·javascript·vue.js
fanruitian18 分钟前
div水平垂直居中
前端·javascript·html
旭久21 分钟前
react+antd实现一个支持多种类型及可新增编辑搜索的下拉框
前端·javascript·react.js
aesthetician31 分钟前
Spotify 网页版前端技术全面解析
前端
咩图32 分钟前
Sketchup软件二次开发+Ruby+VisualStudioCode
java·前端·ruby
Можно44 分钟前
从零开始:Vue 框架安装全指南
前端·javascript·vue.js
蜗牛攻城狮1 小时前
CSS中的 `dvh` 与 `vh`: 深入理解视口单位
前端·css
啥都不懂的小小白1 小时前
Shell脚本编程入门:从零基础到实战掌握
前端·shell
东东5162 小时前
校园短期闲置资源置换平台 ssm+vue
java·前端·javascript·vue.js·毕业设计·毕设