首页 > 解决方案 > 我们如何在 react-native 中设计箭头卡

问题描述

我正在开发一个示例应用程序,在此应用程序中需要使用箭头卡,它用于提供显示卡。我尝试了基于 react-native 形状,但我没有得到输出。

假设如果提供的文本自动增加,箭头设计形状也会增加

这是我的代码:

<View style={styles.container}>
                <View style={{ flex: 0.1, backgroundColor: "blue" }} />
                <View
                    style={{
                        flex: 0.9,
                        backgroundColor: "green",
                        justifyContent: "center",
                        alignItems: "center"
                    }}
                >
                    <View style={styles.baseTop} />
                    <View style={styles.baseBottom} />
                </View>
            </View>
baseTop: {
    borderBottomWidth: 35,
    borderBottomColor: "red",
    borderLeftWidth: 50,
    borderLeftColor: "transparent",
    borderRightWidth: 50,
    borderRightColor: "transparent",
    height: 0,
    width: 0,
    left: 0,
    top: -35,
    position: "absolute"
},
baseBottom: {
    backgroundColor: "red",
    height: 55,
    width: 100
}

我需要像这种类型的图像,这里引用图像:

在此处输入图像描述

标签: cssreact-nativereact-native-androidreact-native-ios

解决方案


这就是我实现与您的图像几乎相同的方式。

import React, { Component } from 'react';
import { Text, View,StyleSheet } from "react-native";

export default class App extends Component {
  render() {
       return (
           <View style={{flex:1}}>
             <View
                style={styles.wrapper}>
                <View style={styles.rectangle}><Text>6</Text> <Text>tens</Text> </View>
                <View style={styles.rectangle}><Text>6</Text> <Text>ones</Text> </View>>
                 <View style={styles.triangle}></View>

            </View>
           </View>
        );
  }
}

const styles = StyleSheet.create({
    wrapper: {
        flexDirection: "row",
        justifyContent: "flex-start",
        flex: 0.2,
        alignItems: "center",
        paddingLeft: 29,
        paddingTop: 0,
        marginTop: 0

    },
    rectangle: {
        width: 50,
        backgroundColor: "yellow",
        margin: 0,
        justifyContent: "center",
        alignItems: "center",
        height: 52,
        borderColor:"black"

    },
    triangle: {
        width: 0,
        height: 0,
        backgroundColor: 'transparent',
        borderStyle: 'solid',
        borderLeftWidth: 27,
        borderRightWidth: 27,
        borderBottomWidth: 43,
        borderLeftColor: 'transparent',
        borderRightColor: 'transparent',
        borderBottomColor:"yellow",
        transform: [
            { rotate: '90deg' }
        ],
        margin: 0,
        marginLeft: -6,
        borderWidth: 0,
        borderColor:"black"
    }
});

世博链接https://snack.expo.io/rycpKiAe7


推荐阅读