Как мне добиться того, чтобы на React Native были активны вкладки с остроконечными / стрелками / треугольниками? - PullRequest
0 голосов
/ 12 февраля 2019

Кажется, что мне нужно использовать некоторые дополнительные 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

Так что мне все еще не хватает заостренногочасть вкладки.

Что еще мне нужно сделать?

Ответы [ 2 ]

0 голосов
/ 12 февраля 2019

Вы можете использовать rotate свойство Transforms, как описано здесь .Минимальный пример:

<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>

Пример закуски здесь

0 голосов
/ 12 февраля 2019

Если вам нужно решение в чистом стиле, а не изображение, вы можете сделать следующее:

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.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...