Skip to content

Commit

Permalink
fix edge case where item appended when not needed and rate > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
tjenkinson committed Mar 4, 2023
1 parent 44466fe commit cdfa4bf
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/marquee.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,25 +310,32 @@ export class Marquee {
? offsetIfWasTouching
: Math.max(
// edge case that would happen if new item requested and synchronously provided,
// but before during that another item size increases, meaning this needs to be placed
// further off screen
// but before during that another item size increases, or if new item was provided
// when it wasn't strictly needed, which can happen if you have negative rate,
// switch to positive which requests an item, and then switch back to negative again
// and provide an item
offsetIfWasTouching,
this._windowOffset + containerSize
),
},
];
} else {
const neighbour = first(this._items);
const offsetIfWasTouching = neighbour
? neighbour.offset - this._pendingItem.getSize()
: this._windowOffset + containerSize - this._pendingItem.getSize();
this._items = [
{
item: this._pendingItem,
offset: newItemWouldBeTouching
? neighbour
? neighbour.offset - this._pendingItem.getSize()
: this._windowOffset +
containerSize -
this._pendingItem.getSize()
: this._windowOffset - this._pendingItem.getSize(),
? offsetIfWasTouching
: Math.min(
// edge case that would happen if new item was provided when it wasn't strictly needed,
// which can happen if you have positive rate, switch to negative which requests an item,
// and then switch back to positive again and provide an item
offsetIfWasTouching,
this._windowOffset - this._pendingItem.getSize()
),
},
...this._items,
];
Expand Down

0 comments on commit cdfa4bf

Please sign in to comment.