-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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 #6656
- Loading branch information
1 parent
c42bf97
commit a1a582b
Showing
21 changed files
with
153 additions
and
115 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,61 @@ | ||
import {Directive, ViewEncapsulation, HostListener, ElementRef, Input} from '@angular/core'; | ||
import {isTrueProperty} from '../../util/util'; | ||
|
||
const DISABLE_SCROLL = 'disable-scroll'; | ||
|
||
/** | ||
* @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 .disable-scroll to body'); | ||
document.body.classList.add(DISABLE_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 .disable-scroll from body'); | ||
document.body.classList.remove(DISABLE_SCROLL); | ||
} | ||
} | ||
|
||
private pushed: boolean = false; | ||
@Input() disableScroll = true; | ||
|
||
constructor(public elementRef: ElementRef) {} | ||
|
||
ngOnInit() { | ||
if (isTrueProperty(this.disableScroll)) { | ||
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.