react-native - React Native - Animated.View 中的可触摸不透明度正在触发背景 ListView 的事件

标签 react-native

我有一个带有 ScrollView 的列表,我正在尝试为其添加过滤器选项。单击过滤器图标时,会出现 position:absolute 的叠加层将显示在 Animated.View 中。我在覆盖 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>
      );
    }
  }

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

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

    }

现在,当我点击过滤器中的 TouchableOpacity 文本时,点击事件在 FadeView 后面的 Listview 中触发。

有人可以让我知道如何在动画绝对 View 中添加新闻事件。

提前致谢。

最佳答案

使用来自“react-native-gesture-handler”而不是“react-native”的 TouchableOpacity。

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

关注这个帖子 Cannot click TouchableOpacity in animated.view using React native

关于react-native - React Native - Animated.View 中的可触摸不透明度正在触发背景 ListView 的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55221850/

相关文章:

reactjs - 如何在 react 中添加或删除状态数组中的项目

reactjs - 如何动态设置高度为动画值后动画的组件的高度?

react-native - 如何在 Fetch 的 promise 链之外获取响应数据?

javascript - 如何更改 React Native Text 中的特定单词颜色

react-native - 从谷歌地图中删除标记 react 原生

javascript - react-native-init 配置文件 - 不确定要编辑哪些文件作为绝对导入路径

javascript - putFile 不是函数

javascript - 如何访问 saga 函数内的操作值

react-native - react 原生模型

android - 从 Playstore 下载的 Apk 和发布仪表板给出不同的哈希值