From 9038362997d33411af980bbd9ced21b7da79cec5 Mon Sep 17 00:00:00 2001 From: "Jared A. Scheel" Date: Wed, 29 Apr 2020 11:30:48 -0500 Subject: [PATCH] Add container scrollTop setter to container context (#69) --- src/components/Container.js | 9 +++++++++ src/components/ContainerContext.js | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/Container.js b/src/components/Container.js index 3ea5b3b..52dba2c 100644 --- a/src/components/Container.js +++ b/src/components/Container.js @@ -129,6 +129,14 @@ export const Container = ({ scrollPositionMotionValue.set(scrollTop) }, [scrollPositionMotionValue]) + const setScrollTop = useCallback( + y => { + if (!contentRef.current) return + contentRef.current.scrollTop = y + }, + [contentRef] + ) + const bodyMarginTop = useTransform(scrollPositionMotionValue, scrollRange, [ padded ? -(spacing.padding.large + spacing.padding.small) @@ -176,6 +184,7 @@ export const Container = ({ scrollPositionMotionValue, headerStubHeight, scrollRange, + setScrollTop, }} > diff --git a/src/components/ContainerContext.js b/src/components/ContainerContext.js index 78017d3..2dc30ab 100644 --- a/src/components/ContainerContext.js +++ b/src/components/ContainerContext.js @@ -1,9 +1,11 @@ import React from 'react' const ContainerContext = React.createContext({ + overlap: false, scrollPositionMotionValue: null, - headerStubHeightMotionValue: null, - setBodyOffsetRatio: () => {}, + headerStubHeight: null, + scrollRange: [0, 100], + setScrollTop: () => {}, }) export default ContainerContext