Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parallax): child horizontal prop defaults to parent's #1458

Merged
merged 4 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion demo/src/sandboxes/parallax/src/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
.number span {
display: inline-block;
position: relative;
transform: translate3d(-35%, 0, 0);
}

.slopeBegin {
Expand Down
12 changes: 9 additions & 3 deletions packages/parallax/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IParallaxLayer {

export interface IParallax {
config: ConfigProp
horizontal: boolean
busy: boolean
space: number
offset: number
Expand Down Expand Up @@ -101,8 +102,12 @@ export const ParallaxLayer = React.memo(
}
})

// Layer's horizontal defaults to parent's horizontal if not set.
const scrollHorizontal =
horizontal === undefined ? parent.horizontal : horizontal

const translate3d = ctrl.springs.translate.to(
horizontal
scrollHorizontal
? x => `translate3d(${x}px,0,0)`
: y => `translate3d(0,${y}px,0)`
)
Expand All @@ -115,8 +120,8 @@ export const ParallaxLayer = React.memo(
backgroundSize: 'auto',
backgroundRepeat: 'no-repeat',
willChange: 'transform',
[horizontal ? 'height' : 'width']: '100%',
[horizontal ? 'width' : 'height']: ctrl.springs.space,
[scrollHorizontal ? 'height' : 'width']: '100%',
[scrollHorizontal ? 'width' : 'height']: ctrl.springs.space,
WebkitTransform: translate3d,
msTransform: translate3d,
transform: translate3d,
Expand Down Expand Up @@ -155,6 +160,7 @@ export const Parallax = React.memo(
const state: IParallax = useMemoOne(
() => ({
config,
horizontal,
busy: false,
space: 0,
current: 0,
Expand Down