Skip to content

Commit

Permalink
Account for insets when comparing size of subject to size of scrollpo…
Browse files Browse the repository at this point in the history
…rt/view progress visibility range (#210)

* Account for insets when comparing size of subject to size of scrollport/view progress range

* Add comment documenting reason for adjusting scrollport size

Co-authored-by: Bramus <[email protected]>

---------

Co-authored-by: Bramus <[email protected]>
  • Loading branch information
johannesodland and bramus authored Jan 26, 2024
1 parent fe5902b commit 3813df9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/scroll-timeline-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,9 @@ export function calculateRange(phase, sourceMeasurements, subjectMeasurements, a

let startOffset = undefined;
let endOffset = undefined;
const targetIsTallerThanContainer = viewSize > sizes.containerSize ? true : false;
// Take inset into account when determining the scrollport size
const adjustedScrollportSize = sizes.containerSize - inset.start - inset.end;
const subjectIsLargerThanScrollport = viewSize > adjustedScrollportSize;

switch(phase) {
case 'cover':
Expand All @@ -700,11 +702,11 @@ export function calculateRange(phase, sourceMeasurements, subjectMeasurements, a

case 'entry-crossing':
startOffset = coverStartOffset;
endOffset = targetIsTallerThanContainer ? containEndOffset : containStartOffset;
endOffset = subjectIsLargerThanScrollport ? containEndOffset : containStartOffset;
break;

case 'exit-crossing':
startOffset = targetIsTallerThanContainer ? containStartOffset : containEndOffset;
startOffset = subjectIsLargerThanScrollport ? containStartOffset : containEndOffset;
endOffset = coverEndOffset;
break;
}
Expand Down

0 comments on commit 3813df9

Please sign in to comment.