Skip to content
Snippets Groups Projects
Commit e7f69509 authored by Chris Lawton's avatar Chris Lawton Committed by Todd Dembrey
Browse files

transition between detail view panels on mobile

parent 11dc2da6
No related branches found
No related tags found
No related merge requests found
import React from 'react';
import React, { Component } from 'react'
import PropTypes from 'prop-types';
import DisplayPanel from '@components/DisplayPanel';
import SlideInRight from '@components/Transitions/SlideInRight'
import SlideOutLeft from '@components/Transitions/SlideOutLeft'
import './style.scss';
const DetailView = ({ listing, display }) => (
<div className="detail-view">
{listing}
<DisplayPanel />
</div>
);
class DetailView extends Component {
constructor() {
super();
this.state = {
width: window.innerWidth,
hasActiveApplication: false
}
}
componentWillMount() {
window.addEventListener('resize', this.handleWindowSizeChange.bind(this));
}
componentWillUnmount() {
window.removeEventListener('resize', this.handleWindowSizeChange.bind(this));
}
handleWindowSizeChange = () => {
this.setState({
width: window.innerWidth
})
}
render() {
const { listing } = this.props;
const { width, hasActiveApplication } = this.state;
const isMobile = width < 1024;
if (isMobile) {
return (
<div className="detail-view">
<SlideInRight in={!hasActiveApplication}>
<DisplayPanel />
</SlideInRight>
<SlideOutLeft in={hasActiveApplication}>
{listing}
</SlideOutLeft>
</div>
)
} else {
return (
<div className="detail-view">
{listing}
<DisplayPanel />
</div>
)
}
}
};
DetailView.propTypes = {
listing: PropTypes.node.isRequired,
};
export default DetailView;
import React from 'react'
import Transition from 'react-transition-group/Transition';
const SlideInRight = ({ children, in: inProp }) => {
const duration = 250;
const defaultStyle = {
transition: `transform ${duration}ms ease-in-out`,
transform: 'translate3d(0, 0, 0)',
position: 'absolute',
zIndex: 2,
width: '100%'
}
const transitionStyles = {
entering: { transform: 'translate3d(0, 0, 0)' },
entered: { transform: 'translate3d(100%, 0, 0)' },
exiting: { transform: 'translate3d(100%, 0, 0)' },
exited: { transform: 'translate3d(0, 0, 0)' }
};
return (
<Transition in={inProp} timeout={duration}>
{(state) => (
<div style={{ ...defaultStyle, ...transitionStyles[state] }}>
{children}
</div>
)}
</Transition>
)
}
export default SlideInRight
import React from 'react'
import Transition from 'react-transition-group/Transition';
const SlideOutLeft = ({ children, in: inProp }) => {
const duration = 250;
const defaultStyle = {
transition: `transform ${duration}ms ease-in-out`,
transform: 'translate3d(0, 0, 0)',
position: 'absolute',
width: '100%'
}
const transitionStyles = {
entering: { transform: 'translate3d(0, 0, 0)' },
entered: { transform: 'translate3d(-100%, 0, 0)' },
exiting: { transform: 'translate3d(-100%, 0, 0)' },
exited: { transform: 'translate3d(0, 0, 0)' }
};
return (
<Transition in={inProp} timeout={duration}>
{(state) => (
<div style={{ ...defaultStyle, ...transitionStyles[state] }}>
{children}
</div>
)}
</Transition>
)
}
export default SlideOutLeft
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment