popmotion icon indicating copy to clipboard operation
popmotion copied to clipboard

How do you deal with "media queries"

Open mschipperheyn opened this issue 8 years ago • 5 comments

I've just started using react-pose and I'm curious what the best way is to deal with different screen sizes and variations in animations that might depend on screen size.

E.g. a drawer covers perhaps 80% on a mobile screen and a fixed max width on a desktop style screen.

mschipperheyn avatar Jun 14 '18 14:06 mschipperheyn

For now you could pass viewport dimensions through as props, but in the near future we’ll provide an object with these On Thu, 14 Jun 2018 at 15:51, Marc Schipperheyn [email protected] wrote:

I've just started using react-pose and I'm curious what the best way is to deal with different screen sizes and variations in animations that might depend on screen size.

E.g. a drawer covers perhaps 80% on a mobile screen and a fixed max width on a desktop style screen.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Popmotion/popmotion/issues/379, or mute the thread https://github.com/notifications/unsubscribe-auth/AHfLKgR2LPGeQwCFbIs-fQEz6P6D3sAyks5t8nhlgaJpZM4UoHCz .

mattgperry avatar Jun 14 '18 15:06 mattgperry

Ok, thx

mschipperheyn avatar Jun 15 '18 02:06 mschipperheyn

Have you looked into using the matchMedia function? https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia

mattgperry avatar Aug 31 '18 14:08 mattgperry

Any news on this? I'd like to use a pose transition only on tablets and smaller. Is that possible at this point?

Here's an example of my needs (using react + styled components):

// Cancel link, that shows up when search is in focus
const searchCancelPoseProps = {
	visible: {
		width: 'auto',
		opacity: 1,
		transition: { duration: 400, ease: [0.73, 0.09, 0.21, 0.96] },
	},
	hidden: {
		width: '0',
		opacity: 0,
		transition: { duration: 400, ease: [0.73, 0.09, 0.21, 0.96] },
	},
}

export const SearchCancelLink = styled(posed.div(searchCancelPoseProps))`
	width: 0;
	height: 100%;
	overflow: hidden;

	// Cancel effects of pose transition, when on md.min
	${uMedia.md.min(css`
		width: 0 !important;
		opacity: 0 !important;
	`)};
`

For now I am using a CSS media query to override the styles coming form pose with !important, but I'd prefer something more elegant, if possible 😅

vajkri avatar Oct 28 '18 21:10 vajkri

u can pass a function to posed factory so i think u could just return empty config without any poses defined, u would have to pass if poses should be created as a prop to ur component & unfortunately u wouldnt be able to switch between animating or not

im talking about smth like

const searchCancelPoseProps = {
	visible: {
		width: 'auto',
		opacity: 1,
		transition: { duration: 400, ease: [0.73, 0.09, 0.21, 0.96] },
	},
	hidden: {
		width: '0',
		opacity: 0,
		transition: { duration: 400, ease: [0.73, 0.09, 0.21, 0.96] },
	},
}

export const SearchCancelLink = styled(
	posed.div(
		props => props.animate ? searchCancelPoseProps : {}
	)
)`
	width: 0;
	height: 100%;
	overflow: hidden;
`

Andarist avatar Oct 28 '18 21:10 Andarist