Skip to content
Open
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
18 changes: 11 additions & 7 deletions packages/arcodesign/components/sticky/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,25 @@ const Sticky = forwardRef((props: StickyProps, ref: Ref<StickyRef>) => {
const containerTop = rectTop + borderTop;
const containerBottom = rectBottom - borderBottom;

const disFromTop = Math.round(placeholderClientRect.top - containerTop);
const disFromBottom = Math.round(
placeholderClientRect.top + calculatedHeight - containerBottom,
);
// 使用容差阈值避免iOS阻尼动画时的抖动问题
// @en Tolerance threshold to avoid jitter problem in iOS damping animation
const TOLERANCE = 0.5;

Copilot AI Aug 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 0.5 should be extracted to a named constant at the module level or made configurable through props. This would improve maintainability and allow fine-tuning if needed.

Copilot uses AI. Check for mistakes.
const disFromTop = placeholderClientRect.top - containerTop;
const disFromBottom = placeholderClientRect.top + calculatedHeight - containerBottom;

const topFollowDifference =
followBottom - followOffset - calculatedHeight - topOffset - containerTop;
const bottomFollowDifference =
containerHeight - followTop - followOffset - calculatedHeight - bottomOffset;

setWasSticky(Boolean(isStickyRef.current));

const isTopSticky = needTop
? disFromTop <= topOffset && followBottom > containerTop + followOffset
? disFromTop <= topOffset + TOLERANCE &&
followBottom > containerTop + followOffset - TOLERANCE
Comment on lines +232 to +233

Copilot AI Aug 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tolerance is being added to topOffset but subtracted from followOffset. This asymmetric application of tolerance could be confusing. Consider documenting why different directions are used or ensuring consistent application.

Suggested change
? disFromTop <= topOffset + TOLERANCE &&
followBottom > containerTop + followOffset - TOLERANCE
followBottom > containerTop + followOffset + TOLERANCE

Copilot uses AI. Check for mistakes.
: false;
const isBottomSticky = needBottom
? disFromBottom >= -bottomOffset && followTop < containerBottom - followOffset
? disFromBottom >= -bottomOffset - TOLERANCE &&
followTop < containerBottom - followOffset + TOLERANCE
: false;
const newStickyState = isTopSticky || isBottomSticky;

Expand Down