首页 > 解决方案 > 反应原生自定义按钮仅在 iOS 上不可点击

问题描述

我有以下组件,onPress 方法在 Android 上完美运行,但在 iOS 上却不行:

export default class Tag extends React.PureComponent {

static propTypes = {
  title: PropTypes.string,
  accessibilityLabel: PropTypes.string,
  width: PropTypes.string,
  onPress: PropTypes.func,
  borderColor: PropTypes.string,
  backgroundColor: PropTypes.string,
  color: PropTypes.string
};

static defaultProps = {
  marginTop: 0,
  secureTextEntry: false,
  autoCapitalize: 'none',
  backgroundColor: "white",
  color: "black",
  marginLeft: 0
}

render() {
  const { onPress } = this.props;

  return (
    <TouchableHighlight onPress={onPress}style={[styles.tag, { backgroundColor: this.props.backgroundColor, marginLeft: this.props.marginLeft}]}>
      <Text style={{color: this.props.color, fontWeight:"bold", fontSize:15}}>{this.props.value}</Text>
  </TouchableHighlight>
);
}
}

  const styles = StyleSheet.create({
  tag: {
    padding: 5,
    color: 'white',
    borderRadius: 5,
    marginTop: 5,
  },
  });

我这样使用它:

<Tag onPress={() => console.log("TEST TEST")} marginLeft={0} value={"EDIT"}/>

但是控制台中没有打印任何内容。什么不见​​了 ?

标签: iosreact-native

解决方案


推荐阅读