gpt4 book ai didi

android - React native Touch 事件正在通过绝对 View 传递

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:37:53 24 4
gpt4 key购买 nike

我正在使用 react-navigation 并且我有一个 View ,我想在工具栏中按下一个图标时显示它,我已经使用另一个组件并将该组件设置为绝对显示,事情是,所有 touchEvents 都通过覆盖 View ,我尝试在 headerRightStyle 上设置 zIndex 和高程,这是绝对的 View ,即使在另一个 subview 中也是如此。我还尝试使用 TouchableWithoutFeedback 作为包装器,但这也没有解决问题。

这是我的组件

import React, { Component } from 'react';
import {
View,
Text,
UIManager,
LayoutAnimation,
Dimensions,
TouchableWithoutFeedback,
} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';

const styles = {
movieFilterListContainerStyle: {
position: 'absolute',
bottom: -300,
right: -10,
height: 300,
},
};

class MovieFilter extends Component {
constructor(props) {
super(props);
this.state = {
showFilterList: false,
filterListWidth: 0,
};
this.renderFilterList = this.renderFilterList.bind(this);
this.onShowFilterList = this.onShowFilterList.bind(this);
this.calculateFilterListWidth = this.calculateFilterListWidth.bind(this);
}

componentWillMount() {
UIManager.setLayoutAnimationEnabledExperimental(true);
this.calculateFilterListWidth();
Dimensions.addEventListener('change', this.calculateFilterListWidth);
}

componentWillUpdate() {
LayoutAnimation.spring();
}

componentWillUnmount() {
Dimensions.removeEventListener('change', () => {});
}

onShowFilterList() {
const { showFilterList } = this.state;
this.setState({ showFilterList: !showFilterList });
}

calculateFilterListWidth() {
this.setState({ filterListWidth: Dimensions.get('window').width });
}

renderFilterList() {
const { showFilterList, filterListWidth } = this.state;
const { movieFilterListContainerStyle } = styles;
if (showFilterList === true) {
return (
<View
style={[
movieFilterListContainerStyle,
{
width: filterListWidth,
},
]}
>
<TouchableWithoutFeedback onPress={() => {}}>
<View
style={{
flex: 1,
backgroundColor: '#FFFFFF',
elevation: 10,
zIndex: 999999,
paddingRight: 10,
paddingLeft: 10,
paddingTop: 10,
paddingBottom: 10,
}}
>
<View
style={{
flexDirection: 'row',
position: 'relative',
justifyContent: 'space-between',
}}
>
<Text>Year</Text>
<Text>Test</Text>
</View>
<View style={{ flexDirection: 'row', position: 'relative' }}>
<Text>Rating</Text>
<Text>Test</Text>
</View>
<View style={{ flexDirection: 'row', position: 'relative' }}>
<Text>Categories</Text>
<Text>Test</Text>
</View>
</View>
</TouchableWithoutFeedback>
</View>
);
}
return null;
}

render() {
return (
<View style={{ flex: 1 }}>
<Icon name="filter-list" size={30} onPress={this.onShowFilterList} />
{this.renderFilterList()}
</View>
);
}
}

export default MovieFilter;

这是我的导航器:

const MoviesTab = createStackNavigator(
{
MovieList: MoviesScreen,
},
{
navigationOptions: ({ navigation }) => ({
headerRight: (
<View
style={{
marginLeft: 10,
marginRight: 10,
flexDirection: 'row',
flex: 1,
}}
>
<Icon
onPress={navigation.getParam('logout')}
size={30}
name="logout-variant"
color="#000000"
/>
<MovieFilter />
</View>
),
headerRightContainerStyle: {
zIndex: 20,
elevation: 20,
},
headerLeft: (
<View style={{ flex: 1, flexDirection: 'row' }}>
<SearchBar />
</View>
),
}),
},
);

最佳答案

添加 pointerEvents 属性。可以在此处找到文档 http://facebook.github.io/react-native/docs/0.50/view#pointereventsrenderFilterList 方法中将 pointerEvents 添加到此 View

<View
style={[
movieFilterListContainerStyle,
{
width: filterListWidth,
},
]}
pointerEvents={'box-only'}
>

关于android - React native Touch 事件正在通过绝对 View 传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52556296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com