React Native - Animated.View 内的可触摸不透明度正在触发背景列表视图的事件

Sai*_*ddy 5 react-native

我有一个带有滚动视图的列表,我正在尝试为其添加过滤器选项。当单击过滤器图标时,position:absolute将在 Animated.View 内显示一个叠加层。我在覆盖视图内有按钮TouchableOpacity

过滤器.js

    export default class FilterFade extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
          visible: props.visible,
        };
    };

    componentWillMount() {
      this._visibility = new Animated.Value(this.props.visible ? 1 : 0);
    }

    componentWillReceiveProps(nextProps) {

        if (nextProps.visible) {
          this.setState({ visible: true });
        }
        Animated.timing(this._visibility, {
          toValue: nextProps.visible ? 1 : 0,
          duration: 300,
        }).start(() => {
          this.setState({ visible: nextProps.visible });
        });
    }

    render() {
      const { visible, style, children, ...rest } = this.props;

      const containerStyle = {
        opacity: this._visibility.interpolate({
          inputRange: [0, 1],
          outputRange: [0, 1],
        }),
        transform: [
          {
            scale: this._visibility.interpolate({
              inputRange: [0, 1],
              outputRange: [1.1, 1],
            }),
          },
        ],
      };

      const combinedStyle = [containerStyle, style];
      return (
        <Animated.View style={combinedStyle} {...rest}>
          {children}
        </Animated.View>
      );
    }
  }
Run Code Online (Sandbox Code Playgroud)

视图.js

<FilterFade visible={this.state.isFilterVisible}>
          <View style={styles.filterView}>
              <TouchableOpacity onPress={() => this.getFilteedStories}>
                <Text style={styles.filterOption}> My Stories </Text>
              </TouchableOpacity>
                <TouchableOpacity onPress={() => this.getFilteedStories}>
              <Text style={styles.filterOption}> All Stories </Text>
              </TouchableOpacity>
          </View>
 </FilterFade>
Run Code Online (Sandbox Code Playgroud)

风格

 filterView :{
      position: 'absolute',
      top: 0,
      right: 5,
      backgroundColor: #CCC,
      width: 150,
      paddingTop: 15,
      paddingBottom: 15,
      zIndex: 999,
    },
    filterOption: {
      color: "#FFF",
      fontSize: 15

    }
Run Code Online (Sandbox Code Playgroud)

现在,当我单击 Filter 中的 TouchableOpacity Text 时,会在 FadeView 后面的 Listview 中触发单击事件。

有人可以告诉我如何在动画绝对视图中添加新闻事件吗?

提前致谢。

小智 -3

使用“react-native-gesture-handler”中的 TouchableOpacity,而不是“react-native”中的 TouchableOpacity。

从'react-native-gesture-handler'导入{TouchableOpacity};

关注这篇文章Cannot click TouchableOpacity inanimate.view using React native