【问题标题】:React Native touchableOpacity on android borderRadius cant workReact Native touchableOpacity on android borderRadius无法工作
【发布时间】:2018-03-11 07:30:31
【问题描述】:

我在按钮的样式中使用了边框半径,样式显示正确,但是,单击裁剪半径的区域仍然有效。

这是我的实现示例。

<View style={Style.userCircleContainerParent}>
    <TouchableOpacity style={Style.userCircleContainer} onPress={() => this.onAvatarClick()}>
        {this.props.state.pictureUrl
          ? <Image source={{uri: this.props.state.pictureUrl}} style={Style.userCircleImage} />
          : <Image source={loadingImage} style={Style.userCircleImage} />}
    </TouchableOpacity>
</View>

样式

  userCircleContainerParent: {
    alignSelf: 'center',
    height: userIconSize,
    width: userIconSize,
    borderRadius: userIconSize / 2,
    backgroundColor: 'white'
  },

  userCircleContainer: {
    alignSelf: 'center',
    height: userIconSize,
    width: userIconSize,
    borderRadius: userIconSize / 2,
    backgroundColor: 'white'
  },

  userCircleImage: {
    alignSelf: 'center',
    height: userIconSize - 5,
    width: userIconSize - 5,
    marginTop: 2.5,
    borderRadius: (userIconSize - 5) / 2,
    backgroundColor: 'transparent'
  },

图片 active click area

【问题讨论】:

    标签: javascript react-native


    【解决方案1】:

    将此道具添加到第一个视图

    pointerEvents = {'box-none'}
    

    https://facebook.github.io/react-native/docs/view.html#pointerevents

    【讨论】:

    • 同样的故事...问题是 TouchableOpacity 保持正方形,无论它在视图内是什么,它都会捕获半径角落之外的事件...
    猜你喜欢
    • 2022-01-24
    • 2021-08-18
    • 2022-08-22
    • 2018-09-11
    • 2020-03-13
    • 2022-12-26
    • 2022-08-19
    • 2019-05-29
    • 1970-01-01
    相关资源
    最近更新 更多