From 6e0fa96243902c4354764c2edc79edf1190280fc Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 4 Jun 2018 09:57:49 -0300 Subject: ListScrollForm.scrollToEnd function --- ui/form/ListScrollForm.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'ui/form') diff --git a/ui/form/ListScrollForm.js b/ui/form/ListScrollForm.js index 581c82f..fe7ef0e 100644 --- a/ui/form/ListScrollForm.js +++ b/ui/form/ListScrollForm.js @@ -96,19 +96,7 @@ module.exports = class ListScrollForm extends Form { // we should move the view so that the item is the farthest right (of all // the visible items). if (this.getItemPos(sel) > this.formEdge + this.scrollSize) { - // We can decide how many items to scroll past by moving forward until - // our item's far edge is visible. - - let i - let edge = this.formEdge - - for (i = 0; i < this.inputs.length; i++) { - if (this.getItemPos(sel) <= edge) break - edge += this.inputs[i][this.sizeProp] - } - - // Now that we have the right index to scroll to, apply it! - this.scrollItems = i + this.scrollElementIntoEndOfView(sel) } // Adjusting the number of scroll items is much simpler to deal with if @@ -143,11 +131,30 @@ module.exports = class ListScrollForm extends Form { this.scrollItems += this.h if (this.curIndex >= this.inputs.length) { this.curIndex = this.inputs.length - 1 - this.scrollItems = Math.max(0, this.inputs.length - this.h) + this.scrollToEnd() } this.updateSelectedElement() } + scrollElementIntoEndOfView(element) { + // We can decide how many items to scroll past by moving forward until + // the item's far edge is visible. + let i + let edge = this.formEdge + for (i = 0; i < this.inputs.length; i++) { + if (this.getItemPos(element) <= edge) break + edge += this.inputs[i][this.sizeProp] + } + + // Now that we have the right index to scroll to, apply it! + this.scrollItems = i + } + + scrollToEnd() { + this.scrollElementIntoEndOfView(this.inputs[this.inputs.length - 1]) + this.fixLayout() + } + getItemPos(item) { // Gets the position of the item in an unscrolled view. -- cgit 1.3.0-6-gf8a5