0

I want to hide android navigation when calling a modal window, but I can’t do it, it is always shown when the modal is opened.

I tried solutions to this question but it didn't work (Hide Android Navigation Bar in React Native)

1
  • To achieve this you will have to use a package. Give react-native-system-navigation-bar a try. Commented Dec 19, 2023 at 16:07

1 Answer 1

0

I advise you to use react-native-immersive, this an example code

import React, { useState, useEffect } from 'react';
import { View, Text, Modal, Button } from 'react-native';
import Immersive from 'react-native-immersive';

const YourComponent = () => {
  const [isModalVisible, setModalVisible] = useState(false);

  useEffect(() => {
    // Enable immersive mode when the component mounts
    Immersive.on();
    return () => {
      // Disable immersive mode when the component unmounts
      Immersive.off();
    };
  }, []);

  const openModal = () => {
    setModalVisible(true);
    // Disable immersive mode when the modal is opened
    Immersive.off();
  };

  const closeModal = () => {
    setModalVisible(false);
    // Enable immersive mode when the modal is closed
    Immersive.on();
  };

  return (
    <View>
      <Button title="Open Modal" onPress={openModal} />
      <Modal visible={isModalVisible} animationType="slide">
        <View>
          <Text>Your Modal Content</Text>
          <Button title="Close Modal" onPress={closeModal} />
        </View>
      </Modal>
    </View>
  );
};

export default YourComponent;

because React Native does not provide a direct API to control the visibility of the Android navigation bar out of the box.

Sign up to request clarification or add additional context in comments.

Comments

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.