Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generify radar dimension #196

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
58 changes: 31 additions & 27 deletions addon/-private/data-view/radar/dynamic-radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DEBUG } from '@glimmer/env';
import Radar from './radar';
import SkipList from '../skip-list';
import roundTo from '../utils/round-to';
import getScaledClientRect from '../../utils/element/get-scaled-client-rect';

export default class DynamicRadar extends Radar {
constructor(parentToken, options) {
Expand All @@ -15,7 +14,7 @@ export default class DynamicRadar extends Radar {
this._totalBefore = 0;
this._totalAfter = 0;

this._minHeight = Infinity;
this._minSize = Infinity;

this._nextIncrementalRender = null;

Expand Down Expand Up @@ -60,24 +59,24 @@ export default class DynamicRadar extends Radar {
_updateConstants() {
super._updateConstants();

if (this._calculatedEstimateHeight < this._minHeight) {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems odd for _minHeight to still be here in a generalized version

Copy link
Author

@kybishop kybishop Mar 19, 2018

Choose a reason for hiding this comment

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

Still a WIP, will get to this soon. Fixed

this._minHeight = this._calculatedEstimateHeight;
if (this._calculatedEstimateSize < this._minSize) {
this._minSize = this._calculatedEstimateSize;
}

// Create the SkipList only after the estimateHeight has been calculated the first time
// Create the SkipList only after the estimateSize has been calculated the first time
if (this.skipList === null) {
this.skipList = new SkipList(this.totalItems, this._calculatedEstimateHeight);
this.skipList = new SkipList(this.totalItems, this._calculatedEstimateSize);
} else {
this.skipList.defaultValue = this._calculatedEstimateHeight;
this.skipList.defaultValue = this._calculatedEstimateSize;
}
}

_updateIndexes() {
const {
bufferSize,
skipList,
visibleTop,
visibleBottom,
visibleStart,
visibleEnd,
totalItems,

_didReset
Expand All @@ -101,8 +100,8 @@ export default class DynamicRadar extends Radar {

const { values } = skipList;

let { totalBefore, index: firstVisibleIndex } = this.skipList.find(visibleTop);
let { totalAfter, index: lastVisibleIndex } = this.skipList.find(visibleBottom);
let { totalBefore, index: firstVisibleIndex } = this.skipList.find(visibleStart);
let { totalAfter, index: lastVisibleIndex } = this.skipList.find(visibleEnd);

const maxIndex = totalItems - 1;

Expand Down Expand Up @@ -136,13 +135,16 @@ export default class DynamicRadar extends Radar {
let beforeVisibleDiff = 0;

if (firstItemIndex < _prevFirstItemIndex) {
// Measurement only items that could affect scrollTop. This will necesarilly be the
// Measure only items that could affect scrollTop/scrollLeft. This will necessarily be the
// minimum of the either the total number of items that are rendered up to the first
// visible item, OR the number of items that changed before the first visible item
// (the delta). We want to measure the delta of exactly this number of items, because
// items that are after the first visible item should not affect the scroll position,
// and neither should items already rendered before the first visible item.
const measureLimit = Math.min(Math.abs(firstItemIndex - _prevFirstItemIndex), _prevFirstVisibleIndex - firstItemIndex);
const measureLimit = Math.min(
Math.abs(firstItemIndex - _prevFirstItemIndex),
_prevFirstVisibleIndex - firstItemIndex
);

beforeVisibleDiff = Math.round(this._measure(measureLimit));
}
Expand Down Expand Up @@ -187,23 +189,25 @@ export default class DynamicRadar extends Radar {
const itemIndex = currentItem.index;

const {
top: currentItemTop,
height: currentItemHeight
} = getScaledClientRect(currentItem, _transformScale);
startPosition: currentItemStartPosition,
size: currentItemSize
} = currentItem.getScaledPositionInformation(_transformScale);

let margin;

if (previousItem !== undefined) {
margin = currentItemTop - getScaledClientRect(previousItem, _transformScale).bottom;
margin = currentItemStartPosition
- previousItem.getScaledPositionInformation(_transformScale).endPosition;
} else {
margin = currentItemTop - getScaledClientRect(_occludedContentBefore, _transformScale).bottom;
margin = currentItemStartPosition
- _occludedContentBefore.getScaledPositionInformation(_transformScale).endPosition;
}

const newHeight = roundTo(currentItemHeight + margin);
const itemDelta = skipList.set(itemIndex, newHeight);
const newSize = roundTo(currentItemSize + margin);
const itemDelta = skipList.set(itemIndex, newSize);

if (newHeight < this._minHeight) {
this._minHeight = newHeight;
if (newSize < this._minSize) {
this._minSize = newSize;
}

if (itemDelta !== 0) {
Expand All @@ -215,7 +219,7 @@ export default class DynamicRadar extends Radar {
}

_didEarthquake(scrollDiff) {
return scrollDiff > (this._minHeight / 2);
return scrollDiff > (this._minSize / 2);
}

get total() {
Expand All @@ -240,21 +244,21 @@ export default class DynamicRadar extends Radar {

get firstVisibleIndex() {
const {
visibleTop
visibleStart
} = this;

const { index } = this.skipList.find(visibleTop);
const { index } = this.skipList.find(visibleStart);

return index;
}

get lastVisibleIndex() {
const {
visibleBottom,
visibleEnd,
totalItems
} = this;

const { index } = this.skipList.find(visibleBottom);
const { index } = this.skipList.find(visibleEnd);

return Math.min(index, totalItems - 1);
}
Expand Down
Loading