我怎样才能做到有活动尖尖/箭头/三角形上的标签作出反应本土?

问题描述 投票:0回答:2

这似乎是,如果我需要使用一些额外的CSS,以达到你会看到如下内容:enter image description here

我已经有这个组件:

  renderTabBar = props => (
    <View style={tabViewStyles.tabBar}>
      {props.navigationState.routes.map((route, i) => {
        return (
          <TouchableOpacity
            key={route.key}
            style={[
              tabViewStyles.tabItem,
              tabViewStyles.tabStyle,
              tabViewStyles[`tabStyle_${i}`],
            ]}
            onPress={() => this.setState({ index: i })}
          >
            <Text style={{ color: '#ffffff', fontFamily: 'montserratBold' }}>
              {route.title}
            </Text>
          </TouchableOpacity>
        );
      })}
    </View>
  );

有了这个CSS样式表上:


  container: {
    flex: 1,
  },
  tabBar: {
    flexDirection: 'row',
    paddingTop: Constants.statusBarHeight,
  },
  onWhite: {
    color: globalStyles.whiteColor.color,
    backgroundColor: globalStyles.whiteColor.backgroundColor,
  },
  bolderFont: {
    fontFamily: 'montserratBold',
  },
  tabItem: {
    flex: 1,
    alignItems: 'center',
    padding: 26,
  },
  tabStyle: {
    marginHorizontal: 10,
    marginTop: 20,
    borderRadius: 2,
  },
  tabStyle_0: {
    backgroundColor: '#ff5252',
  },
  tabStyle_1: {
    backgroundColor: '#3da7dc',
  },
});

有了上面我得到这个:enter image description here

因此,我仍然失踪的标签的尖尖的一部分。

我需要什么呢?

javascript css reactjs css3 react-native
2个回答
1
投票

您可以使用变换描述rotatehere财产。小例子:

<View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
      <View style={{width:50,height:50,backgroundColor:'green'}}></View>
      <View style={{transform:[{rotateZ:'45deg'}],width:8,height:8,backgroundColor:'green',marginTop:-4}}></View>
  </View>

小吃例如here


0
投票

如果你想要一个纯粹的风格的解决方案,而不是你可以做以下的图像:

const triangle = {
    width: 0,
    height: 0,
    backgroundColor: 'transparent',
    borderStyle: 'solid',
    borderLeftWidth: 50,
    borderRightWidth: 50,
    borderBottomWidth: 100,
    borderLeftColor: 'transparent',
    borderRightColor: 'transparent',
    borderBottomColor: '#ff5252',
    transform: [
      {rotate: '180deg'}
    ]
}

const Triangle = React.createClass({
  render: function() {
    return (
      <View style={[triangle, this.props.style]} />
    )
  }
})

https://codedaily.io/tutorials/22/The-Shapes-of-React-Native修改。

© www.soinside.com 2019 - 2024. All rights reserved.