question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(Android) 'statusBarTranslucent' prop not working properly

See original GitHub issue

Platforms

Android (emulator, Galaxy Fold 2)

Versions

  • react-native-modal: 12.0.2
  • react-native: 0.64.1
  • react: 17.0.1

Description

When set ‘statusBarTranslucent’ prop, backdrop doesn’ fill the screen full.

This is the legacy Modal component with statusBarTranslucent = true

스크린샷 2021-06-24 오후 3 55 38

And this is React Native Modal with statusBarTranslucent = true

스크린샷 2021-06-24 오후 4 02 48

I guess that this happens when device has safe area.

This bug can be fixed with modifying

https://github.com/react-native-modal/react-native-modal/blob/60ea392df7d26a598628b1f3a06440b7ecccacd9/src/modal.tsx#L698-L707

701th line, height: this.getDeviceHeight(), to height: '100%',

(But I cannot ensure whether or not side-effects exist)

스크린샷 2021-06-24 오후 4 58 29

Reproducible Demo

import React from 'react';
import {View, SafeAreaView, StatusBar, Text, StyleSheet} from 'react-native';
import Modal from 'react-native-modal';

const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
    },
    titleText: {
        fontSize: 30,
        fontWeight: 'bold',
        textAlign: 'center',
        marginBottom: 50,
    },
    dialogStyle: {
        width: 200,
        height: 100,
        backgroundColor: '#FFFFFF',
        alignItems: 'center',
        justifyContent: 'center'
    }
});

const App = () => {
    const [visible, setVisible] = React.useState(true);

    return (
        <>
            <StatusBar barStyle="dark-content" backgroundColor="#FFFFFF" />
            <SafeAreaView style={styles.container}>
                <Text style={styles.titleText}>
                    Modal Test
                </Text>
                <Modal
                    isVisible={visible}
                    onBackdropPress={() => {
                        setVisible(false);
                    }}
                    statusBarTranslucent
                    style={{
                        alignItems: 'center'
                    }}
                >
                    <View style={styles.dialogStyle}>
                        <Text>React Native Modal</Text>
                        <Text>MODAL CONTENT</Text>
                    </View>
                </Modal>
            </SafeAreaView>
        </>
    );
};
export default App;

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
SUCHMOKUOcommented, Nov 2, 2022

customBackdrop and Dimensions.get('screen') solved this problem.

<Modal
  statusBarTranslucent
  backdropOpacity={0.4}
  customBackdrop={<View style={{ backgroundColor: 'black', ...Dimensions.get('screen') }} />}
  ...
>
    ...
</Modal>
3reactions
avlondercommented, Jul 11, 2021

Alternatively, you can just set the deviceHeight prop to ‘100%’. However, it’s type is null. Maybe, this is a bug too?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to hide the statusBar when react-native modal shown?
Use statusBarTranslucent. If your status bar is translucent , you can set statusBarTranslucent to the modal . Added since React Native 0.62
Read more >
Modal - React Native
Android. ​. The statusBarTranslucent prop determines whether your modal should go under the system statusbar.
Read more >
react-native-modal - npm
The modal background doesn't animate properly. Are you sure you named the isVisible prop correctly? Make sure it is spelled correctly: isVisible ...
Read more >
Configuring the status bar - Expo Documentation
Configuring the status bar while app is loading (Android only). This type of configuration is currently only available on Android. On iOS, it...
Read more >
React Native Modal Component - GeeksforGeeks
It is only for android devices. onDismiss: This prop allows passing a function that will be called once the modal has been dismissed....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found