android - Modal being displaced when setting visible from a parameter - Stack Overflow

I have this modal called LevelCompletePopup. It takes in parameters visible and onClose.The issue is w

I have this modal called LevelCompletePopup. It takes in parameters visible and onClose.

The issue is when I set the visible = {true}, it displays the gif correctly as expected -

  • takes up the entire screen
  • entire screen is transparent with 0.2 opacity
  • gif is on the screen center.

But as soon as I set visible={visible} from the parameter, the layout changes -

  • The screen is not shown with an opacity.
  • The gif moves to the top left of the screen.

The incoming parameter visible is set in the parent component in a function like -

const handleLevelComplete = () => {
    console.log ("handleLevelComplete")
    setLevelComplete(!isLevelComple)
}
import { View, Modal } from 'react-native';
import LottieView from 'lottie-react-native';

const LevelCompletePopup = ({ visible, onClose }) => {
    return (
    <Modal transparent animationType='fade' visible={true} onRequestClose={onClose}>
      <View
        style={{
          flex:1,
          justifyContent: 'center',
          alignItems: 'center',
          backgroundColor: 'rgba(0, 0, 0, 0.2)',
        }}
      >
        <LottieView
          source={require('../../assets/confetti/confetti.json')}
          autoPlay
          loop
          style={{ width: 500, height: 500}}
        />
      </View>
    </Modal>
    );
};

export default LevelCompletePopup;

react-native:"0.76.7"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744239885a4564654.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信