Remove present view animations
This commit is contained in:
parent
c8d02392f2
commit
eb653b66c3
|
@ -32,21 +32,22 @@ const AlbumGallery = ({ album, loading = false, customAlbumLink }) => {
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// On update
|
// On update
|
||||||
useEffect(() => {
|
// TODO: Fix hash
|
||||||
if (presenting) {
|
// useEffect(() => {
|
||||||
window.history.replaceState(
|
// if (presenting) {
|
||||||
null,
|
// window.history.replaceState(
|
||||||
null,
|
// null,
|
||||||
document.location.pathname + '#' + `present=${activeImage}`
|
// null,
|
||||||
)
|
// document.location.pathname + '#' + `present=${activeImage}`
|
||||||
} else if (presentIndexFromHash(document.location.hash)) {
|
// )
|
||||||
window.history.replaceState(
|
// } else if (presentIndexFromHash(document.location.hash)) {
|
||||||
null,
|
// window.history.replaceState(
|
||||||
null,
|
// null,
|
||||||
document.location.pathname.split('#')[0]
|
// null,
|
||||||
)
|
// document.location.pathname.split('#')[0]
|
||||||
}
|
// )
|
||||||
})
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setActiveImage(-1)
|
setActiveImage(-1)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import { animated } from 'react-spring'
|
|
||||||
import { Transition } from 'react-spring/renderprops'
|
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import { Loader } from 'semantic-ui-react'
|
import { Loader } from 'semantic-ui-react'
|
||||||
import { Photo } from './Photo'
|
import { Photo } from './Photo'
|
||||||
|
@ -42,17 +40,14 @@ const PhotoGallery = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.key == 'ArrowRight') {
|
if (e.key == 'ArrowRight') {
|
||||||
setMoveDirection('right')
|
|
||||||
nextImage && nextImage()
|
nextImage && nextImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.key == 'ArrowLeft') {
|
if (e.key == 'ArrowLeft') {
|
||||||
setMoveDirection('left')
|
|
||||||
nextImage && previousImage()
|
nextImage && previousImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.key == 'Escape') {
|
if (e.key == 'Escape') {
|
||||||
setMoveDirection(null)
|
|
||||||
setPresenting(false)
|
setPresenting(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,8 +59,6 @@ const PhotoGallery = ({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const [moveDirection, setMoveDirection] = useState(null)
|
|
||||||
|
|
||||||
const activeImage = photos && activeIndex != -1 && photos[activeIndex]
|
const activeImage = photos && activeIndex != -1 && photos[activeIndex]
|
||||||
|
|
||||||
const getPhotoElements = updateSidebar => {
|
const getPhotoElements = updateSidebar => {
|
||||||
|
@ -103,60 +96,24 @@ const PhotoGallery = ({
|
||||||
return photoElements
|
return photoElements
|
||||||
}
|
}
|
||||||
|
|
||||||
let transformDirectionIndex = 0
|
|
||||||
if (moveDirection == 'right') transformDirectionIndex = 1
|
|
||||||
if (moveDirection == 'left') transformDirectionIndex = 2
|
|
||||||
|
|
||||||
const presentViewTransitionConfig = {
|
|
||||||
items: activeImage,
|
|
||||||
keys: x => x,
|
|
||||||
config: {
|
|
||||||
tension: 220,
|
|
||||||
},
|
|
||||||
from: {
|
|
||||||
opacity: 0,
|
|
||||||
transform: [
|
|
||||||
'translate(0%, 0)',
|
|
||||||
'translate(12%, 0)',
|
|
||||||
'translate(-12%, 0)',
|
|
||||||
][transformDirectionIndex],
|
|
||||||
},
|
|
||||||
enter: {
|
|
||||||
opacity: 1,
|
|
||||||
transform: 'translate(0%, 0)',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const AnimatedPresentPhoto = animated(PresentPhoto)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarConsumer>
|
<SidebarConsumer>
|
||||||
{({ updateSidebar }) => (
|
{({ updateSidebar }) => (
|
||||||
<div>
|
<div>
|
||||||
{!presenting ? (
|
<Gallery>
|
||||||
<Gallery>
|
<Loader active={loading}>Loading images</Loader>
|
||||||
<Loader active={loading}>Loading images</Loader>
|
{getPhotoElements(updateSidebar)}
|
||||||
{getPhotoElements(updateSidebar)}
|
<PhotoFiller />
|
||||||
<PhotoFiller />
|
</Gallery>
|
||||||
</Gallery>
|
{presenting && (
|
||||||
) : (
|
|
||||||
<PresentContainer>
|
<PresentContainer>
|
||||||
<Transition {...presentViewTransitionConfig}>
|
<PresentPhoto photo={activeImage} />
|
||||||
{photo => props => (
|
|
||||||
<PresentPhoto
|
|
||||||
thumbnail={photo && photo.thumbnail.url}
|
|
||||||
photo={photo}
|
|
||||||
style={props}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Transition>
|
|
||||||
</PresentContainer>
|
</PresentContainer>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</SidebarConsumer>
|
</SidebarConsumer>
|
||||||
)
|
)
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PhotoGallery.propTypes = {
|
PhotoGallery.propTypes = {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import React, { useEffect, useState } from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import styled, { createGlobalStyle } from 'styled-components'
|
import styled, { createGlobalStyle } from 'styled-components'
|
||||||
import { Query } from 'react-apollo'
|
|
||||||
import gql from 'graphql-tag'
|
|
||||||
import ProtectedImage from './ProtectedImage'
|
import ProtectedImage from './ProtectedImage'
|
||||||
|
|
||||||
export const PresentContainer = ({ children, ...otherProps }) => {
|
export const PresentContainer = ({ children, ...otherProps }) => {
|
||||||
|
@ -26,7 +24,7 @@ export const PresentContainer = ({ children, ...otherProps }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
PresentContainer.propTypes = {
|
PresentContainer.propTypes = {
|
||||||
children: PropTypes.element,
|
children: PropTypes.any,
|
||||||
}
|
}
|
||||||
|
|
||||||
const PreventScroll = createGlobalStyle`
|
const PreventScroll = createGlobalStyle`
|
||||||
|
@ -36,101 +34,33 @@ const PreventScroll = createGlobalStyle`
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const imageQuery = gql`
|
|
||||||
query presentImage($id: ID!) {
|
|
||||||
photo(id: $id) {
|
|
||||||
id
|
|
||||||
title
|
|
||||||
original {
|
|
||||||
width
|
|
||||||
height
|
|
||||||
url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
const StyledPhoto = styled(ProtectedImage)`
|
const StyledPhoto = styled(ProtectedImage)`
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
object-position: center;
|
object-position: center;
|
||||||
`
|
`
|
||||||
|
|
||||||
export const PresentPhoto = ({
|
export const PresentPhoto = ({ photo, imageLoaded, ...otherProps }) => {
|
||||||
photo,
|
|
||||||
thumbnail,
|
|
||||||
imageLoaded,
|
|
||||||
...otherProps
|
|
||||||
}) => {
|
|
||||||
let [originalPhoto, setOriginalPhoto] = useState(null)
|
|
||||||
useEffect(() => {
|
|
||||||
if (!(photo && photo.id)) return
|
|
||||||
|
|
||||||
function loadOriginalPhoto() {
|
|
||||||
let originalPhoto = null
|
|
||||||
|
|
||||||
if (photo && photo.original && photo.original.url) {
|
|
||||||
originalPhoto = (
|
|
||||||
<StyledPhoto
|
|
||||||
style={{ display: 'none' }}
|
|
||||||
src={photo.original.url}
|
|
||||||
onLoad={e => {
|
|
||||||
e.target.style.display = 'initial'
|
|
||||||
imageLoaded && imageLoaded()
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
originalPhoto = (
|
|
||||||
<Query query={imageQuery} variables={{ id: photo.id }}>
|
|
||||||
{({ loading, error, data }) => {
|
|
||||||
if (error) {
|
|
||||||
alert(error)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data && data.photo) {
|
|
||||||
const photo = data.photo
|
|
||||||
|
|
||||||
return (
|
|
||||||
<StyledPhoto
|
|
||||||
style={{ display: 'none' }}
|
|
||||||
src={photo.original.url}
|
|
||||||
onLoad={e => {
|
|
||||||
e.target.style.display = 'initial'
|
|
||||||
imageLoaded && imageLoaded()
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}}
|
|
||||||
</Query>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
setOriginalPhoto(originalPhoto)
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeoutHandle = setTimeout(loadOriginalPhoto, 500)
|
|
||||||
|
|
||||||
return function cleanup() {
|
|
||||||
clearTimeout(timeoutHandle)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div {...otherProps}>
|
<div {...otherProps}>
|
||||||
{originalPhoto}
|
<StyledPhoto src={photo.thumbnail.url} />
|
||||||
<StyledPhoto src={thumbnail} />
|
<StyledPhoto
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
src={photo.original.url}
|
||||||
|
onLoad={e => {
|
||||||
|
e.target.style.display = 'initial'
|
||||||
|
imageLoaded && imageLoaded()
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
PresentPhoto.propTypes = {
|
PresentPhoto.propTypes = {
|
||||||
photo: PropTypes.object,
|
photo: PropTypes.object,
|
||||||
thumbnail: PropTypes.string,
|
|
||||||
imageLoaded: PropTypes.func,
|
imageLoaded: PropTypes.func,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue