utils.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const getCurrentPage = function () {
  2. const pages = getCurrentPages();
  3. return pages[pages.length - 1];
  4. };
  5. const onPageScroll = function (event) {
  6. const { pageScroller = [] } = getCurrentPage();
  7. pageScroller.forEach((scroller) => {
  8. if (typeof scroller === 'function') {
  9. // @ts-ignore
  10. scroller(event);
  11. }
  12. });
  13. };
  14. export const pageScrollMixin = (scroller) => Behavior({
  15. attached() {
  16. const page = getCurrentPage();
  17. if (Array.isArray(page.pageScroller)) {
  18. page.pageScroller.push(scroller.bind(this));
  19. }
  20. else {
  21. page.pageScroller =
  22. typeof page.onPageScroll === 'function'
  23. ? [page.onPageScroll.bind(page), scroller.bind(this)]
  24. : [scroller.bind(this)];
  25. }
  26. page.onPageScroll = onPageScroll;
  27. },
  28. detached() {
  29. var _a;
  30. const page = getCurrentPage();
  31. page.pageScroller = ((_a = page.pageScroller) === null || _a === void 0 ? void 0 : _a.filter((item) => item !== scroller)) || [];
  32. },
  33. });
  34. export const getRect = function (context, selector) {
  35. return new Promise((resolve) => {
  36. wx.createSelectorQuery()
  37. .in(context)
  38. .select(selector)
  39. .boundingClientRect()
  40. .exec((rect = []) => resolve(rect[0]));
  41. });
  42. };
  43. //# sourceMappingURL=utils.js.map