Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native Modal with SafeAreaView-wrapper not working

We have a FilterComponent which renders a Modal, but on iPhone X it's Header is in the Statusbar.

I tried to render it with SafeAreaView but seems like this is not working:

return (
  <SafeAreaView>
    <Modal
      { ...defaultModalProps }
      onRequestClose={ close }
      style={ styles.container }
      visible={ visible }
    >
      <ModalNavbar close={ close }>
        Filter
      </ModalNavbar>
      <View style={ styles.content }>
        ...
      </View>
    </Modal>
  </SafeAreaView>
);

When FilterModal is openend on iPhoneX it still is in the Statusbar and you cant click on anything.

Any idea how to solve this?

thanks.

like image 733
Michael Ploeckinger Avatar asked Jan 31 '18 09:01

Michael Ploeckinger


People also ask

Should I use SafeAreaView in react native?

You have to only use when any screen has headerMode:none or it out side of the navigation. If you are using full screen modal then you should use <SafeAreaView> . I don't thing having navigation handles it. For android it might but for iOS with swipe gesture to go to home on bottom, one must use safeareview.

How do I hide SafeAreaView in react native?

You could try react-navigation's SafeAreaView. Just set it's forceInset prop to { bottom: 'never' } and you'll see it behaves as your expectation.

How do I get SafeAreaView height in react native?

import { useSafeAreaInsets } from 'react-native-safe-area-context'; ... const insets = useSafeAreaInsets(); Then you can get the bottom safe area height from safeAreaInsets.

Is SafeAreaView working in Android?

The purpose of SafeAreaView is to render content within the safe area boundaries of a device. It is currently only applicable to iOS devices with iOS version 11 or later.


2 Answers

Put SafeAreaView inside the Modal component

return (
  <Modal
    {...defaultModalProps}
    onRequestClose={close}
    style={styles.container}
    visible={visible}
  >
    <SafeAreaView style={{ flex: 1, backgroundColor: "transparent" }}>
      <ModalNavbar close={close}>Filter</ModalNavbar>
      <View style={styles.content}>...</View>
    </SafeAreaView>
  </Modal>
);
like image 92
RANVIR GORAI Avatar answered Oct 03 '22 04:10

RANVIR GORAI


A Modal fill the entire screen, so you need to provide extra spacing inside the Modal. Margin / Padding will not effect on Modal if applied on parent of Modal.

<Modal {...}>
  <TouchableWithoutFeedback onPress={closeModal}>
    <SafeAreaView {...}>
      {...}
    </SafeAreaView>
  </TouchableWithoutFeedback>
</Modal>
like image 25
Pir Shukarullah Shah Avatar answered Oct 03 '22 04:10

Pir Shukarullah Shah