diff --git a/package-lock.json b/package-lock.json index 9c1cd4d..86c3b97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "image-viewer", - "version": "0.1.2", + "version": "0.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/components/BookComponent.tsx b/src/components/BookComponent.tsx index 1e84b3c..b5609ad 100644 --- a/src/components/BookComponent.tsx +++ b/src/components/BookComponent.tsx @@ -81,7 +81,7 @@ class BookComponent extends React.Component{ } componentDidMount(){ - fetch('https://picsum.photos/v2/list') + fetch('https://picsum.photos/v2/list?limit=30') .then(response=>{ return response.json() }).then(data=>{ diff --git a/src/components/TwoPagesView.tsx b/src/components/TwoPagesView.tsx index 4c856cd..650003f 100644 --- a/src/components/TwoPagesView.tsx +++ b/src/components/TwoPagesView.tsx @@ -1,11 +1,39 @@ import React, {useState, useEffect} from 'react' import {Transition, animated} from 'react-spring/renderprops' -import {ComponentContainer, PageComponent, PageContainer} from './OnePageView' -import { IBookContext } from './BookComponent' +import {ComponentContainer, PageComponent} from './OnePageView' +import { IBookPage } from './BookComponent' +import styled from 'styled-components' + +const PageContainer = styled.div` + height: 600px; + position: relative; + width: 100%; + cursor: pointer; + margin-bottom: 8px; + overflow-x: hidden; + & > div { + will-change: transform, opacity; + position: absolute; + width: 100%; + height: 100%; + } +` + export default function TwoPagesView(props: any) { let {src, currIndex, flagToReverse} = props - const [pagesToshow, setPagesToShow] = useState([]) + const [pagesToshow, setPagesToShow] = useState([ + { + src: '', + alt: '', + thumbnail: '', + }, + { + src: '', + alt: '', + thumbnail: '', + } + ]) useEffect(()=>{ const shouldShowPage = (pageIndex: number)=>{ @@ -28,27 +56,39 @@ export default function TwoPagesView(props: any) { } }, [currIndex, src]) + const firstPageObj = { + keys: (item: any)=> item.src, + initial: {}, + from: {opacity: 1, transform: flagToReverse? "translate3d(-50%, 0, 0)": "translate3d(100%, 0, 0)"}, + enter: { opacity: 1, transform: "translate3d(0%, 0, 0)" }, + leave: { opacity: 0, transform: flagToReverse? "translate3d(100%, 0, 0)": "translate3d(-50%, 0, 0)"}, + } + + const secondPageObj = { + keys: (item: any)=> item.src, + from: {opacity: 1, transform: flagToReverse? "translate3d(0%, 0, 0)": "translate3d(150%, 0, 0)"}, + enter: { opacity: 1, transform: "translate3d(50%, 0, 0)" }, + leave: { opacity: 0, transform: flagToReverse? "translate3d(150%, 0, 0)": "translate3d(0%, 0, 0)"}, + initial: {}, + } + return ( item.src} - initial={{}} - from={{opacity: 1, transform: flagToReverse? "translate3d(-50%, 0, 0)": "translate3d(100%, 0, 0)"}} - enter={{ opacity: 1, transform: "translate3d(0%, 0, 0)" }} - leave={{ opacity: 0, transform: flagToReverse? "translate3d(100%, 0, 0)": "translate3d(-50%, 0, 0)"}} + items={pagesToshow[0]} + {...firstPageObj} > { - currIndex=> style=>{ + image=> style=>{ return( - {React.createElement(()=>{ - return + {React.createElement(()=>{ + return })} ) @@ -59,21 +99,17 @@ export default function TwoPagesView(props: any) { item.src} - from={{opacity: 1, transform: flagToReverse? "translate3d(0%, 0, 0)": "translate3d(150%, 0, 0)"}} - enter={{ opacity: 1, transform: "translate3d(50%, 0, 0)" }} - leave={{ opacity: 0, transform: flagToReverse? "translate3d(150%, 0, 0)": "translate3d(0%, 0, 0)"}} - initial={{}} + items={pagesToshow[1]} + {...secondPageObj} > { - currIndex=> style=>{ + image=> style=>{ return( {React.createElement(()=>{ - return + return })} )