我正在根据设计师的设计开发React原生应用程序.设计中有几个地方有一条对角线的按钮或形状(参见下面的示例).我试过使用SkewX,但这似乎只是旋转了整个形状(而且似乎在Android上也不起作用).如何绘制一侧有对角线边框的矩形/按钮?

button with diagonal border

推荐答案

您可以将css应用于View类并创建所需的输出,

import React, { Component } from 'react';
import { View, StyleSheet } from 'react-native';
import { Constants } from 'expo';

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>

        <View style={styles.triangleCorner}></View>
        <View style={styles.triangleCornerLayer}></View>
         <View style={styles.triangleCorner1}></View>

      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
  },triangleCorner: {
    position: 'absolute',
    top:105,
    left:0,
    width: 300,
    height: 100,
    backgroundColor: 'transparent',
    borderStyle: 'solid',
    borderRightWidth: 50,
    borderTopWidth: 80,
    borderRightColor: 'transparent',
    borderTopColor: 'gray'
  },triangleCorner1: {
    position: 'absolute',
    top:100,
    left:0,
    width: 130,
    backgroundColor: 'transparent',
    borderStyle: 'solid',
    borderRightWidth: 50,
    borderTopWidth: 90,
    borderRightColor: 'transparent',
    borderTopColor: 'green'
  },triangleCornerLayer: {
    position: 'absolute',
    top:107,
    left:0,
    width:297,
    height: 100,
    backgroundColor: 'transparent',
    borderStyle: 'solid',
    borderRightWidth: 47,
    borderTopWidth: 75,
    borderRightColor: 'transparent',
    borderTopColor: 'white'
  }
});

Result:

enter image description here

React-native相关问答推荐

如何在renderItem中显示每个项目的索引号,保持分页的前一个下一个按钮

NativeWind边框 colored颜色 在Reaction Native应用程序中未按预期工作

任务:react-native-async-storage_async-storage:generateDebugRFile FAILED

ReactNative:在所有组件和操作之间共享 sqlite 实例的最佳方法

如何 break .map 功能

react-native (expo)加载markdown 文件

create-react-native-app myproject和react-native init myproject之间的真正区别是什么

react native foreach 循环

如何以编程方式在 react-native 中截屏

如何在 React Native 中获取 TextInput 相对于其父级或屏幕的光标位置

如何在 React Native 中按下按钮时更改文本值?

mapDispatchToProps:有什么意义吗?

获取没有地理位置 API React-native 的国家/城市?

使用 Jest 测试 React Native 应用程序

React Native 创建自定义组件/库

使用条码 scanner 掩码的透明视图react-native相机

Animated.View 的样式props的Typescript定义

React Native Image 不显示,我该如何解决?

在 React-Native 中手动设置 opacity 的 onPress of TouchableOpacity 的音量

如何在react-native中显示toast消息