MOBILE-3320 ios: Fix ion-content outside split view scroll

main
Pau Ferrer Ocaña 2021-05-20 15:30:58 +02:00
parent a3a68e670e
commit 0db4971ae6
2 changed files with 43 additions and 0 deletions

View File

@ -24,6 +24,8 @@ export enum CoreSplitViewMode {
MenuAndContent = 'menu-and-content', // Shows both menu and content. MenuAndContent = 'menu-and-content', // Shows both menu and content.
} }
const disabledScrollClass = 'disable-scroll-y';
@Component({ @Component({
selector: 'core-split-view', selector: 'core-split-view',
templateUrl: 'split-view.html', templateUrl: 'split-view.html',
@ -36,6 +38,7 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy {
@Input() placeholderText = 'core.emptysplit'; @Input() placeholderText = 'core.emptysplit';
@Input() mode?: CoreSplitViewMode; @Input() mode?: CoreSplitViewMode;
isNested = false; isNested = false;
disabledScrollOuterContents: HTMLIonContentElement[] = [];
private outletRouteSubject: BehaviorSubject<ActivatedRouteSnapshot | null> = new BehaviorSubject(null); private outletRouteSubject: BehaviorSubject<ActivatedRouteSnapshot | null> = new BehaviorSubject(null);
private subscriptions?: Subscription[]; private subscriptions?: Subscription[];
@ -59,6 +62,9 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy {
*/ */
ngAfterViewInit(): void { ngAfterViewInit(): void {
this.isNested = !!this.element.nativeElement.parentElement?.closest('core-split-view'); this.isNested = !!this.element.nativeElement.parentElement?.closest('core-split-view');
this.disableScrollOnParent();
this.subscriptions = [ this.subscriptions = [
this.contentOutlet.activateEvents.subscribe(() => { this.contentOutlet.activateEvents.subscribe(() => {
this.updateClasses(); this.updateClasses();
@ -79,6 +85,8 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy {
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.subscriptions?.forEach(subscription => subscription.unsubscribe()); this.subscriptions?.forEach(subscription => subscription.unsubscribe());
this.enableScrollOnParent();
} }
/** /**
@ -122,4 +130,30 @@ export class CoreSplitViewComponent implements AfterViewInit, OnDestroy {
return CoreSplitViewMode.MenuAndContent; return CoreSplitViewMode.MenuAndContent;
} }
/**
* Will disable scroll on parent ion contents to enabled PTR on the ones inside the splitview.
* This error only happens on iOS.
* Another manual solution is to add scroll-y=false on the ion-contents outside the split view.
*/
protected disableScrollOnParent(): void {
let outerContent = this.element.nativeElement.parentElement?.closest('ion-content');
while (outerContent) {
if (outerContent?.getAttribute('scroll-y') != 'false' && !outerContent?.classList.contains(disabledScrollClass)) {
outerContent.classList.add(disabledScrollClass);
this.disabledScrollOuterContents.push(outerContent);
}
outerContent = outerContent.parentElement?.closest('ion-content');
}
}
/**
* Will enable scroll on parent ion contents previouly disabled.
*/
protected enableScrollOnParent(): void {
this.disabledScrollOuterContents.forEach((outerContent) => {
outerContent.classList.remove(disabledScrollClass);
});
}
} }

View File

@ -628,3 +628,12 @@ ion-input .native-input {
ion-checkbox { ion-checkbox {
--border-radius: 2px; --border-radius: 2px;
} }
// Disable scroll on parent ion contents to enabled PTR on the ones inside the splitview. See split-view component for more info.
ion-content.disable-scroll-y::part(scroll) {
touch-action: auto;
overflow-y: hidden;
overscroll-behavior-y: auto;
z-index: auto;
will-change: auto;
}