scroll_list.js 766 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. *
  8. */
  9. 'use strict';
  10. Object.defineProperty(exports, '__esModule', {
  11. value: true
  12. });
  13. exports.default = scroll;
  14. function scroll(size, _ref) {
  15. let offset = _ref.offset,
  16. max = _ref.max;
  17. let start = 0;
  18. let index = Math.min(offset, size);
  19. const halfScreen = max / 2;
  20. if (index <= halfScreen) {
  21. start = 0;
  22. } else {
  23. if (size >= max) {
  24. start = Math.min(index - halfScreen - 1, size - max);
  25. }
  26. index = Math.min(index - start, size);
  27. }
  28. return {
  29. end: Math.min(size, start + max),
  30. index: index,
  31. start: start
  32. };
  33. }