Skip to content

Commit

Permalink
fix(sticky): rerender sticky when threshold change (jdf2e#2564)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-huxiyang authored Sep 6, 2024
1 parent d9f6072 commit 0c7dd1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/packages/sticky/sticky.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const Sticky: FunctionComponent<Partial<StickyProps>> = (props) => {
zIndex,
}
return style
}, [fixed, rootRect.height, rootRect.width, transform, position])
}, [fixed, rootRect.height, rootRect.width, transform, position, threshold])

const handleScroll: any = async (scrollTop: number) => {
const curRootRect = await getRectByTaro(rootRef.current)
Expand Down
5 changes: 3 additions & 2 deletions src/packages/sticky/sticky.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ export const Sticky: FunctionComponent<Partial<StickyProps>> = (props) => {
const stickyRef = useRef<HTMLDivElement>(null)
const rootRef = useRef<HTMLDivElement>(null)
const [isFixed, setIsFixed] = useState(false)

const [stickyStyle, setStickyStyle] = useState<CSSProperties>({
[position]: `${threshold}px`,
zIndex,
})

useEffect(() => {
setStickyStyle({ ...stickyStyle, [position]: `${threshold}px` })
}, [threshold, position])
const [rootStyle, setRootStyle] = useState({})

const getElement = useCallback(() => {
Expand Down

0 comments on commit 0c7dd1e

Please sign in to comment.