fix: parallax broken since safari 16.4

Moves the parallax effect into a directive which injects required elements into the shadow DOM and adds `part` attributes, so it can be styled from a global stylesheet.
This commit is contained in:
Thea Schöbl
2023-05-04 12:18:48 +00:00
parent abf2ab6a5a
commit 0f970fa1f1
16 changed files with 428 additions and 358 deletions

View File

@@ -22,10 +22,8 @@
<!-- TODO: translation --> <!-- TODO: translation -->
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content class="ion-content-parallax"> <ion-content parallax>
<div>
<div class="about-changelog"> <div class="about-changelog">
<markdown src="assets/about/CHANGELOG.md"></markdown> <markdown src="assets/about/CHANGELOG.md"></markdown>
</div> </div>
</div>
</ion-content> </ion-content>

View File

@@ -22,8 +22,7 @@
<!-- TODO: translation --> <!-- TODO: translation -->
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content class="ion-content-parallax"> <ion-content parallax>
<div>
<div class="licenses-content"> <div class="licenses-content">
<ion-card <ion-card
*ngFor="let license of licenses" *ngFor="let license of licenses"
@@ -49,5 +48,4 @@
</ion-card-content> </ion-card-content>
</ion-card> </ion-card>
</div> </div>
</div>
</ion-content> </ion-content>

View File

@@ -24,11 +24,9 @@
</ng-template> </ng-template>
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content *ngIf="content" class="ion-content-parallax"> <ion-content parallax *ngIf="content">
<div>
<ion-text>{{ appName }} v{{ version }}</ion-text> <ion-text>{{ appName }} v{{ version }}</ion-text>
<div class="page-content"> <div class="page-content">
<about-page-content *ngFor="let element of content.content" [content]="element"></about-page-content> <about-page-content *ngFor="let element of content.content" [content]="element"></about-page-content>
</div> </div>
</div>
</ion-content> </ion-content>

View File

@@ -1,5 +1,5 @@
<!-- <!--
~ Copyright (C) 2022 StApps ~ Copyright (C) 2023 StApps
~ This program is free software: you can redistribute it and/or modify it ~ This program is free software: you can redistribute it and/or modify it
~ under the terms of the GNU General Public License as published by the Free ~ under the terms of the GNU General Public License as published by the Free
~ Software Foundation, version 3. ~ Software Foundation, version 3.
@@ -26,14 +26,12 @@
<ion-label>{{ label | translate }}</ion-label> <ion-label>{{ label | translate }}</ion-label>
<stapps-edit-modal #editModal (save)="selection.save()"> <stapps-edit-modal #editModal (save)="selection.save()">
<ng-template> <ng-template>
<ion-content class="ion-padding modal-content"> <ion-content parallax [parallaxSize]="160" class="ion-padding modal-content">
<div>
<stapps-edit-event-selection <stapps-edit-event-selection
#selection #selection
[items]="associatedDateSeries" [items]="associatedDateSeries"
(modified)="editModal.pendingChanges = true" (modified)="editModal.pendingChanges = true"
></stapps-edit-event-selection> ></stapps-edit-event-selection>
</div>
</ion-content> </ion-content>
<ion-footer mode="ios"> <ion-footer mode="ios">
<ion-toolbar color="light"> <ion-toolbar color="light">

View File

@@ -12,8 +12,6 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
@import 'src/theme/common/ion-content-parallax';
:host { :host {
display: block; display: block;
padding: var(--spacing-sm); padding: var(--spacing-sm);
@@ -35,10 +33,7 @@
} }
.modal-content { .modal-content {
--background: var(--ion-color-primary);
--color: var(--ion-color-primary-contrast); --color: var(--ion-color-primary-contrast);
@include ion-content-parallax($content-size: 160px);
} }
ion-footer > ion-toolbar { ion-footer > ion-toolbar {

View File

@@ -1,5 +1,5 @@
<!-- <!--
~ Copyright (C) 2022 StApps ~ Copyright (C) 2023 StApps
~ This program is free software: you can redistribute it and/or modify it ~ This program is free software: you can redistribute it and/or modify it
~ under the terms of the GNU General Public License as published by the Free ~ under the terms of the GNU General Public License as published by the Free
~ Software Foundation, version 3. ~ Software Foundation, version 3.
@@ -30,8 +30,8 @@
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ng-content select="[header]"></ng-content> <ng-content select="[header]"></ng-content>
<ion-content class="ion-no-padding ion-content-parallax"> <ion-content parallax class="ion-no-padding">
<div [ngSwitch]="true"> <ng-container [ngSwitch]="true">
<ng-container *ngSwitchCase="!item && (isDisconnected | async)"> <ng-container *ngSwitchCase="!item && (isDisconnected | async)">
<div class="centeredMessageContainer"> <div class="centeredMessageContainer">
<ion-icon name="signal_disconnected"></ion-icon> <ion-icon name="signal_disconnected"></ion-icon>
@@ -59,5 +59,5 @@
[contentTemplateRef]="contentTemplateRef" [contentTemplateRef]="contentTemplateRef"
></stapps-data-detail-content> ></stapps-data-detail-content>
</ng-container> </ng-container>
</div> </ng-container>
</ion-content> </ion-content>

View File

@@ -12,11 +12,6 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
:host {
z-index: 100;
}
.crumb-label { .crumb-label {
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;

View File

@@ -21,8 +21,7 @@
<ion-title>{{ 'feedback.page.TITLE' | translate }}</ion-title> <ion-title>{{ 'feedback.page.TITLE' | translate }}</ion-title>
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content class="ion-content-parallax"> <ion-content parallax>
<div>
<div class="feedback-content"> <div class="feedback-content">
<ion-card> <ion-card>
<form #feedbackForm="ngForm" (ngSubmit)="onSubmit()"> <form #feedbackForm="ngForm" (ngSubmit)="onSubmit()">
@@ -123,5 +122,4 @@
</form> </form>
</ion-card> </ion-card>
</div> </div>
</div>
</ion-content> </ion-content>

View File

@@ -22,8 +22,7 @@
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content class="ion-content-parallax" (elementSizeChange)="calcPageSize($event)"> <ion-content parallax (elementSizeChange)="calcPageSize($event)">
<div>
<ion-refresher slot="fixed" (ionRefresh)="refresh($event.target)"> <ion-refresher slot="fixed" (ionRefresh)="refresh($event.target)">
<ion-refresher-content <ion-refresher-content
pullingIcon="chevron-down-outline" pullingIcon="chevron-down-outline"
@@ -58,5 +57,4 @@
<ion-infinite-scroll id="infinite-scroll" threshold="20%" (ionInfinite)="loadMore($event.target)"> <ion-infinite-scroll id="infinite-scroll" threshold="20%" (ionInfinite)="loadMore($event.target)">
<ion-infinite-scroll-content loading-spinner="crescent"> </ion-infinite-scroll-content> <ion-infinite-scroll-content loading-spinner="crescent"> </ion-infinite-scroll-content>
</ion-infinite-scroll> </ion-infinite-scroll>
</div>
</ion-content> </ion-content>

View File

@@ -22,16 +22,13 @@
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content> <ion-content color="light" parallax [parallaxSize]="130">
<div>
<section class="user-card-wrapper"> <section class="user-card-wrapper">
<ion-card class="user-card"> <ion-card class="user-card">
<ion-card-header> <ion-card-header>
<ion-img src="assets/imgs/header.svg"></ion-img> <ion-img src="assets/imgs/header.svg"></ion-img>
<span *ngIf="user$ | async as userInfo"> <span *ngIf="user$ | async as userInfo">
{{ {{ userInfo.role ? (userInfo?.role | titlecase) : ('profile.role_guest' | translate | titlecase) }}
userInfo.role ? (userInfo?.role | titlecase) : ('profile.role_guest' | translate | titlecase)
}}
</span> </span>
</ion-card-header> </ion-card-header>
<ion-card-content> <ion-card-content>
@@ -118,5 +115,4 @@
</ion-card-content> </ion-card-content>
</ion-card> </ion-card>
</section> </section>
</div>
</ion-content> </ion-content>

View File

@@ -12,15 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
@import 'src/theme/common/ion-content-parallax';
:host { :host {
ion-content {
--background: var(--ion-color-light);
@include ion-content-parallax($content-size: 130px);
}
section { section {
margin-bottom: calc(2 * var(--spacing-lg) - var(--spacing-md)); margin-bottom: calc(2 * var(--spacing-lg) - var(--spacing-md));
padding: var(--spacing-md); padding: var(--spacing-md);

View File

@@ -22,8 +22,7 @@
</ion-toolbar> </ion-toolbar>
</ion-header> </ion-header>
<ion-content class="ion-no-padding ion-content-parallax"> <ion-content parallax class="ion-no-padding">
<div>
<div class="settings-content"> <div class="settings-content">
<ng-container *ngFor="let categoryKey of categoriesOrder"> <ng-container *ngFor="let categoryKey of categoriesOrder">
<ion-list *ngIf="objectKeys(settingsCache).includes(categoryKey)"> <ion-list *ngIf="objectKeys(settingsCache).includes(categoryKey)">
@@ -55,5 +54,4 @@
<ion-icon slot="start" name="device_reset"></ion-icon> <ion-icon slot="start" name="device_reset"></ion-icon>
</ion-button> </ion-button>
</div> </div>
</div>
</ion-content> </ion-content>

View File

@@ -0,0 +1,116 @@
/*
* Copyright (C) 2023 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Directive, ElementRef, HostBinding, Input, OnDestroy, OnInit} from '@angular/core';
type IonicColor =
| 'danger'
| 'dark'
| 'light'
| 'medium'
| 'primary'
| 'secondary'
| 'success'
| 'tertiary'
| 'warning'
| string;
/**
* Adds a parallax effect to `<ion-content/>` elements
*
* Why is this necessary and why do we need to inject
* elements into a foreign element's shadow DOM just for this?
*
* We previously had used a global style in conjunction with
* adding a child `<div/>`, however, unfortunately Safari 16.4
* broke 3D transforms where the parent is inside the shadow
* DOM and child elements are outside.
*
* We also have to use `<ion-content/>` as ionic relies on the
* `<ion-content/>` selector to make iOS animations work.
*
* Which means this is pretty much the only way to solve this
* problem.
*
* This directive, when applied using `<ion-content parallax/>`,
* will transform its shadow DOM from
*
* ```html
* <div id="background-content" part="background"></div>
* <main class="inner-scroll scroll-y" part="scroll">
* <slot></slot>
* </main>
* <slot name="fixed"><slot />
* ```
*
* To
*
* ```html
* <div id="background-content" part="background"></div>
* <main class="inner-scroll scroll-y" part="scroll parallax-scroll">
* <div part="parallax-parent">
* <div part="parallax"></div>
* <slot></slot>
* </div>
* </main>
* <slot name="fixed"><slot />
* ```
*
* Which we can then be used through `::part()` to style it from
* a global style sheet.
*/
@Directive({
selector: 'ion-content[parallax]',
})
export class IonContentParallaxDirective implements OnInit, OnDestroy {
@HostBinding('style.--parallax-content-size.px') @Input() parallaxSize = 230;
@Input() set parallaxColor(value: IonicColor) {
this.parallaxBackground = `var(--ion-color-${value})`;
}
@HostBinding('style.--parallax-background') parallaxBackground?: string;
private mutationObserver: MutationObserver;
constructor(private element: ElementRef) {}
ngOnInit() {
this.mutationObserver = new MutationObserver(() => {
const inner = this.element.nativeElement.shadowRoot.querySelector('.inner-scroll') as
| HTMLDivElement
| undefined;
if (!inner) return;
// eslint-disable-next-line unicorn/no-array-for-each
inner.childNodes.forEach(node => node.remove());
inner.part.add('parallax-scroll');
const parallaxParentElement = document.createElement('div');
parallaxParentElement.part.add('parallax-parent');
const parallaxElement = document.createElement('div');
parallaxElement.part.add('parallax');
inner.append(parallaxParentElement);
parallaxParentElement.append(parallaxElement, document.createElement('slot'));
});
this.mutationObserver.observe(this.element.nativeElement.shadowRoot, {
childList: true,
});
}
ngOnDestroy() {
this.mutationObserver.disconnect();
}
}

View File

@@ -31,10 +31,12 @@ import {SimpleSwiperComponent} from './simple-swiper.component';
import {SearchbarAutofocusDirective} from './searchbar-autofocus.directive'; import {SearchbarAutofocusDirective} from './searchbar-autofocus.directive';
import {SectionComponent} from './section.component'; import {SectionComponent} from './section.component';
import {RouterModule} from '@angular/router'; import {RouterModule} from '@angular/router';
import {IonContentParallaxDirective} from './ion-content-parallax.directive';
@NgModule({ @NgModule({
imports: [BrowserModule, IonicModule, TranslateModule, ThingTranslateModule.forChild(), RouterModule], imports: [BrowserModule, IonicModule, TranslateModule, ThingTranslateModule.forChild(), RouterModule],
declarations: [ declarations: [
IonContentParallaxDirective,
ElementSizeChangeDirective, ElementSizeChangeDirective,
ArrayLastPipe, ArrayLastPipe,
DateIsThisPipe, DateIsThisPipe,
@@ -50,6 +52,7 @@ import {RouterModule} from '@angular/router';
SearchbarAutofocusDirective, SearchbarAutofocusDirective,
], ],
exports: [ exports: [
IonContentParallaxDirective,
ElementSizeChangeDirective, ElementSizeChangeDirective,
ArrayLastPipe, ArrayLastPipe,
DateIsThisPipe, DateIsThisPipe,

View File

@@ -124,10 +124,6 @@ ion-header {
} }
} }
.ion-content-parallax {
@include ion-content-parallax();
}
ion-alert { ion-alert {
button.alert-button.preferred { button.alert-button.preferred {
background-color: var(--ion-color-primary); background-color: var(--ion-color-primary);

View File

@@ -12,43 +12,34 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
$overscroll-padding: 720px;
$parallax-strength: 2;
$default-parallax-content-size: 230px;
@mixin ion-content-parallax( ion-content::part(parallax-scroll) {
$parallax-background: var(--ion-color-primary),
$background: var(--ion-background-color),
$parallax-strength: 2,
$overscroll-padding: 720px,
$content-size: 230px
) {
&::part(background) {
background: $background;
}
&::part(scroll) {
perspective: 2px; perspective: 2px;
perspective-origin: center top; perspective-origin: center top;
} }
> div {
ion-content::part(parallax-parent) {
transform-style: preserve-3d; transform-style: preserve-3d;
position: relative; position: relative;
}
&::before { ion-content::part(parallax) {
content: ' ';
position: absolute; position: absolute;
top: 0; top: 0;
right: 0; right: 0;
left: 0; left: 0;
$height: calc($content-size + $overscroll-padding);
$translateY: calc($overscroll-padding * $parallax-strength); $translateY: calc($overscroll-padding * $parallax-strength);
$translateZ: calc(-1px * $parallax-strength); $translateZ: calc(-1px * $parallax-strength);
$transform-origin: calc($parallax-strength * $parallax-strength * $overscroll-padding); $transform-origin: calc($parallax-strength * $parallax-strength * $overscroll-padding);
height: $height; height: calc(var(--parallax-content-size, $default-parallax-content-size) + $overscroll-padding);
width: 150%; width: 150%;
transform-origin: 50% $transform-origin; transform-origin: 50% $transform-origin;
transform: translate3d(0px, $translateY, $translateZ) scale($parallax-strength); transform: translate3d(0px, $translateY, $translateZ) scale($parallax-strength);
background: $parallax-background; background: var(--parallax-background, var(--ion-color-primary));
}
}
} }