ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.02k stars 13.51k forks source link

Ionic 4 Modal not appearing with transparent background #18589

Open AshishSanu opened 5 years ago

AshishSanu commented 5 years ago

Ionic version:

[x] 4.x

I'm submitting a ...

[ ] bug report [ ] feature request

Current behavior:

My Modal is appearing with a solid background/Overlay

Expected behavior:

I want my modal to appear with a transparent background/overlay Steps to reproduce:

Related code:

insert short code snippets here
modal.scss  :
 .main_view{
      background: transparent;
    }
    .overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 1;
      opacity: .5;
      background-color: #333;

    }

modal.html:
<ion-content padding class="main_view">
  <div class="overlay" (click)="dismiss()"></div>
  <div class="modal_content">
    <div class="circle"></div>
    <div class="modal-content">
        <ion-progress-bar type="indeterminate"></ion-progress-bar>
  <h2>Waiting for Driver confirmation</h2>
    </div>
  </div>

</ion-content>

and .ts to invoke modal in my app:

  async confirm(){

    const modal = await this.modalCtrl.create({
      component: ModalPage,
      // componentProps: {value : "test"},
    });
    await modal.present();
    modal.onDidDismiss().then(res => {
      console.log(JSON.stringify(res))
      this.isModalDismiss = res.data.isDismiss;
      console.log(this.isModalDismiss)
      this.routeDriver();
    });
  }

Other information:

Ionic info:

insert the output from ionic info here
AshishSanu commented 5 years ago

My Modal Looks like this Screenshot (57) I want the overlay to be transparent

liamdebeasi commented 5 years ago

Hi there,

Thanks for the issue. I can confirm that this is a bug. It looks like ion-modal does accept a --background CSS variable, but if you are using components like ion-header and ion-content you would never see it since those default to white backgrounds.

A temporary workaround would be to set the --background CSS variable for ion-content to transparent in addition to setting the --background CSS variable for ion-modal.

We will look into a solution for this. Thanks!

AshishSanu commented 5 years ago

hi @liamdebeasi workaround is also not working

ManjeetKSingh commented 5 years ago

I am also facing the same issue...becuse of this our App is delayed to be shhipped for production. @ionic-team , could you please resolve this issue ASAP.

gminhaneli commented 5 years ago

Você consegue resolver colocando no arquivo global.scss .modal-transparency { --background: var(--ion-background-color, rgba(0, 0, 0, 0.2)) !important ; }

codeherk commented 5 years ago

@AshishSanu Going off what @gminhaneli and @liamdebeasi is proposing, here is a temporary solution.

To produce solution:

CSS Class

modal-transparency { 
  --background: transparent; 
  --height: 80%;

 // ion-toolbar {
 //   --background: transparent;
 //   color: white;
 // }
 // ion-content {
 //   --background: transparent;
 // }
}

Function

async confirm(){
  const modal = await this.modalCtrl.create({
    component: ModalPage,
    cssClass: 'modal-transparency'
    // componentProps: {value : "test"},
  });
  await modal.present();
  modal.onDidDismiss().then(res => {
    console.log(JSON.stringify(res))
    this.isModalDismiss = res.data.isDismiss;
    console.log(this.isModalDismiss)
    this.routeDriver();
  });
}

Hope this helps.

AshishSanu commented 5 years ago

@codeherk @gminhaneli thanks for the response, I tried this but it isn't working

codeherk commented 5 years ago

I followed the steps I provided and copied your modal.html..

Screen Shot 2019-06-28 at 5 49 37 AM

Only thing I did not copy was your modal.scss. You did not include the styling for circle and modal-content, so I ignored it altogether.

Here is a screenshot with the stylings from modal.scss applied.

Screen Shot 2019-06-28 at 6 04 57 AM

The div that has the overlay class has a fixed position and it is applied directly over the content, covering the whole screen.

ae-asseke commented 5 years ago

to have a good transparent (ionic 4), I made this 1) - modal.scss { ion-content { --ion-background-color : transparent !important; }' 2) - global.scss { modal-transparency { --background: transparent!important } 3) - and I call modal like this async confirm(){ const modal = await this.modalCtrl.create({ ... cssClass: 'modal-transparency' ... });

I hope it can help u.

testanddeploy commented 5 years ago

@ae-asseke This not work for me on chrome with ionic serve.

niravtrivedi21 commented 3 years ago

Hi @ionic-team, I am facing the same issue in Ionic 5, can you please guide me to resolve this issue?