1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

improving lightbox performance

This commit is contained in:
Braun Patrik 2017-07-15 23:54:17 +02:00
parent f7136c7271
commit f82c7d4169
4 changed files with 31 additions and 22 deletions

View File

@ -6,6 +6,7 @@
<div class="lightbox" #lightbox> <div class="lightbox" #lightbox>
<gallery-lightbox-photo [gridPhoto]="activePhoto ? activePhoto.gridPhoto : null" <gallery-lightbox-photo [gridPhoto]="activePhoto ? activePhoto.gridPhoto : null"
[loadImage]="!animating"
#photo> #photo>
</gallery-lightbox-photo> </gallery-lightbox-photo>
</div> </div>

View File

@ -15,7 +15,7 @@ import {Dimension} from "../../model/IRenderable";
import {FullScreenService} from "../fullscreen.service"; import {FullScreenService} from "../fullscreen.service";
import {OverlayService} from "../overlay.service"; import {OverlayService} from "../overlay.service";
import {Subscription} from "rxjs"; import {Subscription} from "rxjs";
import {animate, AnimationBuilder, style} from "@angular/animations"; import {animate, AnimationBuilder, AnimationPlayer, style} from "@angular/animations";
import {GalleryLightboxPhotoComponent} from "./photo/photo.lightbox.gallery.component"; import {GalleryLightboxPhotoComponent} from "./photo/photo.lightbox.gallery.component";
import {Observable} from "rxjs/Observable"; import {Observable} from "rxjs/Observable";
@ -46,6 +46,7 @@ export class GalleryLightboxComponent implements OnDestroy {
public infoPanelVisible = false; public infoPanelVisible = false;
public infoPanelWidth = 0; public infoPanelWidth = 0;
public animating = false
constructor(public fullScreenService: FullScreenService, constructor(public fullScreenService: FullScreenService,
@ -132,7 +133,6 @@ export class GalleryLightboxComponent implements OnDestroy {
public show(photo: PhotoDTO) { public show(photo: PhotoDTO) {
this.controllersVisible = true; this.controllersVisible = true;
this.showControls(); this.showControls();
console.log(this.photoElement);
this.visible = true; this.visible = true;
let selectedPhoto = this.findPhotoComponent(photo); let selectedPhoto = this.findPhotoComponent(photo);
if (selectedPhoto === null) { if (selectedPhoto === null) {
@ -141,7 +141,10 @@ export class GalleryLightboxComponent implements OnDestroy {
const lightboxDimension = selectedPhoto.getDimension(); const lightboxDimension = selectedPhoto.getDimension();
lightboxDimension.top -= this.getBodyScrollTop(); lightboxDimension.top -= this.getBodyScrollTop();
this.animatePhoto(selectedPhoto.getDimension(), this.calcLightBoxPhotoDimension(selectedPhoto.gridPhoto.photo)); this.animating = true;
this.animatePhoto(selectedPhoto.getDimension(), this.calcLightBoxPhotoDimension(selectedPhoto.gridPhoto.photo)).onDone(() => {
this.animating = false;
});
this.animateLightbox( this.animateLightbox(
lightboxDimension, lightboxDimension,
<Dimension>{ <Dimension>{
@ -165,6 +168,7 @@ export class GalleryLightboxComponent implements OnDestroy {
this.fullScreenService.exitFullScreen(); this.fullScreenService.exitFullScreen();
this.pause(); this.pause();
this.animating = true;
const lightboxDimension = this.activePhoto.getDimension(); const lightboxDimension = this.activePhoto.getDimension();
lightboxDimension.top -= this.getBodyScrollTop(); lightboxDimension.top -= this.getBodyScrollTop();
this.blackCanvasOpacity = 0; this.blackCanvasOpacity = 0;
@ -175,26 +179,28 @@ export class GalleryLightboxComponent implements OnDestroy {
left: 0, left: 0,
width: this.getScreenWidth(), width: this.getScreenWidth(),
height: this.getScreenHeight() height: this.getScreenHeight()
}, lightboxDimension); }, lightboxDimension).onDone(() => {
setTimeout(() => {
this.visible = false; this.visible = false;
this.activePhoto = null; this.activePhoto = null;
this.overlayService.hideOverlay(); this.overlayService.hideOverlay();
}, 500); });
this.hideInfoPanel(false); this.hideInfoPanel(false);
} }
animatePhoto(from: Dimension, to: Dimension = from) {
this._builder.build([ animatePhoto(from: Dimension, to: Dimension = from): AnimationPlayer {
const elem = this._builder.build([
style(<any>Dimension.toString(from)), style(<any>Dimension.toString(from)),
animate(300, animate(300,
style(<any>Dimension.toString(to))) style(<any>Dimension.toString(to)))
]) ])
.create(this.photoElement.elementRef.nativeElement) .create(this.photoElement.elementRef.nativeElement);
.play(); elem.play();
return elem;
} }
animateLightbox(from: Dimension = <Dimension>{ animateLightbox(from: Dimension = <Dimension>{
@ -202,14 +208,15 @@ export class GalleryLightboxComponent implements OnDestroy {
left: 0, left: 0,
width: this.getScreenWidth(), width: this.getScreenWidth(),
height: this.getScreenHeight() height: this.getScreenHeight()
}, to: Dimension = from) { }, to: Dimension = from): AnimationPlayer {
this._builder.build([ const elem = this._builder.build([
style(<any>Dimension.toString(from)), style(<any>Dimension.toString(from)),
animate(300, animate(300,
style(<any>Dimension.toString(to))) style(<any>Dimension.toString(to)))
]) ])
.create(this.lightboxElement.nativeElement) .create(this.lightboxElement.nativeElement);
.play(); elem.play();
return elem;
} }

View File

@ -4,12 +4,12 @@
[style.height.%]="imageSize.height" [style.height.%]="imageSize.height"
[src]="thumbnailPath()"/> [src]="thumbnailPath()"/>
<img *ngIf="gridPhoto !== null" <img *ngIf="gridPhoto !== null && loadImage"
[style.width.%]="imageSize.width" [style.width.%]="imageSize.width"
[style.height.%]="imageSize.height" [style.height.%]="imageSize.height"
[src]="gridPhoto.getPhotoPath()" [src]="gridPhoto.getPhotoPath()"
(load)="onImageLoad()" (load)="onImageLoad()"
(error)="onImageError()"/> (error)="onImageError()"/>
</div> </div>

View File

@ -1,4 +1,4 @@
import {Component, ElementRef, Input, OnChanges} from "@angular/core"; import {Component, Input, OnChanges} from "@angular/core";
import {GridPhoto} from "../../grid/GridPhoto"; import {GridPhoto} from "../../grid/GridPhoto";
@Component({ @Component({
@ -9,12 +9,13 @@ import {GridPhoto} from "../../grid/GridPhoto";
export class GalleryLightboxPhotoComponent implements OnChanges { export class GalleryLightboxPhotoComponent implements OnChanges {
@Input() gridPhoto: GridPhoto; @Input() gridPhoto: GridPhoto;
@Input() loadImage: boolean = false;
public imageSize = {width: "auto", height: "100"}; public imageSize = {width: "auto", height: "100"};
imageLoaded: boolean = false; imageLoaded: boolean = false;
constructor(public elementRef: ElementRef) { constructor() {
} }
ngOnChanges() { ngOnChanges() {