Add swipe gestures to the lightbox

This commit is contained in:
Paul Frazee 2022-12-16 11:57:45 -06:00
parent 3a44a1cfdc
commit 3aded6887d
8 changed files with 387 additions and 40 deletions

View file

@ -51,18 +51,56 @@ export class ServerInputModal {
}
}
export class ProfileImageLightbox {
interface LightboxModel {
canSwipeLeft: boolean
canSwipeRight: boolean
onSwipeLeft: () => void
onSwipeRight: () => void
}
export class ProfileImageLightbox implements LightboxModel {
name = 'profile-image'
canSwipeLeft = false
canSwipeRight = false
constructor(public profileView: ProfileViewModel) {
makeAutoObservable(this)
}
onSwipeLeft() {}
onSwipeRight() {}
}
export class ImageLightbox {
export class ImageLightbox implements LightboxModel {
name = 'image'
canSwipeLeft = true
canSwipeRight = true
constructor(public uri: string) {
makeAutoObservable(this)
}
onSwipeLeft() {}
onSwipeRight() {}
}
export class ImagesLightbox implements LightboxModel {
name = 'images'
get canSwipeLeft() {
return this.index > 0
}
get canSwipeRight() {
return this.index < this.uris.length - 1
}
constructor(public uris: string[], public index: number) {
makeAutoObservable(this)
}
onSwipeLeft() {
if (this.canSwipeLeft) {
this.index = this.index - 1
}
}
onSwipeRight() {
if (this.canSwipeRight) {
this.index = this.index + 1
}
}
}
export interface ComposerOptsPostRef {
@ -91,7 +129,11 @@ export class ShellUiModel {
| ServerInputModal
| undefined
isLightboxActive = false
activeLightbox: ProfileImageLightbox | ImageLightbox | undefined
activeLightbox:
| ProfileImageLightbox
| ImageLightbox
| ImagesLightbox
| undefined
isComposerActive = false
composerOpts: ComposerOpts | undefined
@ -123,7 +165,9 @@ export class ShellUiModel {
this.activeModal = undefined
}
openLightbox(lightbox: ProfileImageLightbox | ImageLightbox) {
openLightbox(
lightbox: ProfileImageLightbox | ImageLightbox | ImagesLightbox,
) {
this.isLightboxActive = true
this.activeLightbox = lightbox
}