0

Hi so I am trying to conditionally set the visibility of a modal (react-native-modal) in the useEffect function of one of my components. The issue is the modal sometimes doesn't show even though the visibility is set to true. Also when this happens it prevents me from interacting with the page below it pretty much breaking the app and causing the user to have to clear it before proceeding.

Here is how i render my modal in the return(the view is just a placeholder):

<Modal
    isVisible={guidanceVisible}
    style={styles.guidanceModalContainer}
    onBackdropPress={() => null}
    backdropOpacity={.75}
  >
    <View style={{
      width: '100%',
      height: '100%',
      backgroundColor: 'green'
    }}/>
  </Modal>

Initialize State: const [guidanceVisible, setGuidanceVisible] = useState(false);

setGuidance in useEffect:

useEffect(() => {
if(myPosts.length > 1){
  // setTimeout(() => {
    setGuidanceVisible(true)
  // }, 500)
}}, []);

As you can see I have already tried using a setTimeout but then I run into a different error. If a user interacts with the page while the timeout is waiting to be called then the same issue as before with the page being uninteractable happens again. Please let me know if you have any ideas or spot any mistakes. Thanks ahead of time!

3
  • the fact you indicated: "it prevents me from interacting with the page", most probably lead to the issue being in HTML/CSS (z-index, position, display...) and not in React, since if the page looks like a freezing one (no interaction) then the back drop is being displayed (overlaying) on the page. Commented Apr 5, 2022 at 19:42
  • Can you please share your whole useEffect? not just the snippet, but the full function. Commented Apr 5, 2022 at 19:51
  • Sorry for the late reply today has been a little hectic. I have just uploaded my useEffect. Also here is my styling guidanceModalContainer:{width: vw(90), height: vh(58), alignSelf: 'center', backgroundColor: 'red', zIndex: 8, position:'absolute', }, Let me know if you see any errors with the way i have it setup. Also i would like to say that there is no backdrop opacity on the page when it isn't intractable. Commented Apr 6, 2022 at 5:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.