Reputation: 445
I have a hamburger button that triggers a side menu in a mobile app. The button doesn't respond when position is set to absolute. I have seen similar issue which suggest wrapping the button with <View> </View>
and setting its position to absolute, however this didn't work in my case. The button doesn't respond when being clicked on IOS. Android works perfectly fine
Code Snippet:
import React, { useState, useEffect } from "react";
import { View, StyleSheet } from "react-native";
import Hamburger from "@psyycker/rn-animated-hamburger";
function HamburgerIcon({ navigation }) {
const [status, setStatus] = useState(false);
useEffect(() => {
const unsubscribe = navigation.addListener("drawerClose", (e) => {
setStatus(false);
});
return unsubscribe;
}, [navigation]);
async function callBack() {
setStatus(true);
navigation.toggleDrawer();
}
return (
<View style={styles.btnContainer}>
<View style={{ marginTop: 40, marginLeft: 20 }}>
<Hamburger
active={status}
type="spinArrow"
color="blue"
onPress={() => callBack()}
></Hamburger>
</View>
</View>
);
}
const styles = StyleSheet.create({
btnContainer: {
position: "absolute",
flex: 1,
},
});
Upvotes: 1
Views: 1499
Reputation: 445
Solved by wrapping around SafeAreaView
and setting zIndex
to a high number.
<SafeAreaView style={{ position: "absolute", margin: 40, marginLeft: 20, zIndex:99999 }}>
<Hamburger active={status}
type="spinArrow"
color="blue"
onPress={() => callBack()}
>
</Hamburger>
</SafeAreaView>
Upvotes: 3