forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ion-backdrop): new ion-backdrop can prevent background scrolling
closes ionic-team#6656
- Loading branch information
1 parent
f6f1634
commit b54da18
Showing
21 changed files
with
151 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@import "../../globals.core"; | ||
|
||
// Backdrop | ||
// -------------------------------------------------- | ||
|
||
$backdrop-color: #000 !default; | ||
|
||
ion-backdrop { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
z-index: $z-index-backdrop; | ||
display: block; | ||
|
||
width: 100%; | ||
height: 100%; | ||
|
||
background-color: $backdrop-color; | ||
opacity: 0.01; | ||
transform: translateZ(0); | ||
} | ||
|
||
ion-backdrop.hide-backdrop { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {Directive, ViewEncapsulation, HostListener, ElementRef, Input} from '@angular/core'; | ||
import {isTrueProperty} from '../../util/util'; | ||
/** | ||
* @private | ||
*/ | ||
@Directive({ | ||
selector: 'ion-backdrop', | ||
host: { | ||
'role': 'presentation', | ||
'tappable': '', | ||
'disable-activated': '' | ||
}, | ||
}) | ||
export class Backdrop { | ||
private static nuBackDrops: number = 0; | ||
|
||
private static push() { | ||
if (this.nuBackDrops == 0) { | ||
console.debug("adding .stop-scrolling to body"); | ||
document.body.classList.add("stop-scroll"); | ||
} else { | ||
console.warn("several backdrops on screen? probably a bug"); | ||
} | ||
this.nuBackDrops++; | ||
} | ||
|
||
private static pop() { | ||
if (this.nuBackDrops == 0) { | ||
console.error("pop requires a push"); | ||
return; | ||
} | ||
this.nuBackDrops--; | ||
if (this.nuBackDrops == 0) { | ||
console.debug("removing .stop-scrolling from body"); | ||
document.body.classList.remove("stop-scroll") | ||
} | ||
} | ||
|
||
private pushed: boolean = false; | ||
@Input() preventScroll: boolean = true; | ||
|
||
constructor(public elementRef: ElementRef) {} | ||
|
||
ngOnInit() { | ||
if(isTrueProperty(this.preventScroll)) { | ||
Backdrop.push(); | ||
this.pushed = true; | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
if(this.pushed) { | ||
Backdrop.pop(); | ||
this.pushed = false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.