【发布时间】:2020-09-26 01:57:50
【问题描述】:
我有一个动画 SafeAreaView,里面有 2 个按钮,视图有 position: absolute。 当我单击按钮时,它会通过它,并点击 de 按钮后面的元素。 我目前正在使用zIndex和elevation,并尝试了很多在Stack Overflow上找到的解决方案,例如:
- 使用 TouchableHighlight
- 使用 onPressIn 代替 onPress
- 从 react-native-gesture-handler 而不是 react-native 导入 TouchableOpacity
如果我在父容器中使用 position: relative,则该按钮有效。
这是我的代码,Button 组件是样式化的 TouchableOpacity,我还尝试删除包装器,将主容器更改为 TouchableOpacity 而不是 SafeAreaView,但没有。 ..
return (
<Wrapper
isAndroid={Platform.OS === 'android'}
style={{
transform: [
{
translateY: translateValue.interpolate({
inputRange: [0, 1],
outputRange: [500, 0]
})
}
]
}}>
<ButtonsWrapper>
<ActionButton
inverted
secondary
onPress={() => {
console.log('teste');
}}
accessible
accessibilityLabel="Continuar com Facebook">
<Icon name="edit" secondary size={20} />
<BtnText bold noPadding secondary>
Editar
</BtnText>
</ActionButton>
<ActionButton
inverted
primary
onPress={() => {
console.log('teste');
}}
accessible
accessibilityLabel="Continuar com Facebook">
<Icon name="x-circle" primary size={20} />
<BtnText bold noPadding primary>
Encerrar
</BtnText>
</ActionButton>
</ButtonsWrapper>
</Wrapper>
);
});
const Wrapper = Animated.createAnimatedComponent(styled.SafeAreaView`
width: 100%;
border-top-width: 1px;
border-top-color: ${({ theme: { border } }) => border};
background: ${({ theme: { background } }) => background};
z-index: 1;
position: absolute;
flex-direction: row;
justify-content: space-between;
align-items: center;
bottom: 0;
left: 0;
${({ isAndroid }) => isAndroid && 'elevation: 1'}
height: 150px;
`);
const ButtonsWrapper = styled.View`
flex: 1;
align-items: center;
justify-content: center;
padding: 10px;
`;
const ActionButton = styled(Button)``;
const BtnText = styled(Text)`
padding-right: 20px;
flex: 1;
text-align: center;
${({ noPadding }) =>
noPadding &&
`
padding: 0px;
`}
`;
【问题讨论】:
标签: javascript css reactjs react-native