rax-scrollview
Version:
ScrollView component for Rax.
1 lines • 12.4 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.raxScrollview=t():e.raxScrollview=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=13)}([function(e,t){e.exports=require("rax")},function(e,t){e.exports=require("universal-env")},function(e,t){e.exports=require("classnames")},function(e,t,n){"use strict";n.d(t,"a",(function(){return i}));var r=500,o=50;function i(e){return e.defaultProps={scrollEventThrottle:o,onEndReachedThreshold:r,showsHorizontalScrollIndicator:!0,showsVerticalScrollIndicator:!0,className:"rax-scrollview"},e.displayName="ScrollView",e}},function(e,t){e.exports=require("rax-view")},function(e,t,n){},function(e,t,n){"use strict";var r=n(0),o=n(4),i=n.n(o),c=n(2),l=n.n(c),a=n(1),s=a.isWeb&&void 0!==window.requestAnimationFrame?window.requestAnimationFrame:function(e){return setTimeout(e,16)},u=a.isWeb&&void 0!==window.cancelAnimationFrame?window.cancelAnimationFrame:clearTimeout,f="start",d="end",p="run",h="stop",v={easeOutSine:function(e){return Math.sin(e*Math.PI/2)}},m=function(){},b=function(){function e(e){this.config={easing:"linear",duration:1/0,onStart:m,onRun:m,onStop:m,onEnd:m},this.isfinished=!1,this.config=Object.assign(Object.assign({},this.config),e)}var t=e.prototype;return t.run=function(){var e=this.config,t=e.duration,n=e.onStart,r=e.onRun;t<=1&&(this.isfinished=!0,r({percent:1}),this.stop()),this.isfinished||(this._hasFinishedPercent=this._stop&&this._stop.percent||0,this._stop=null,this.start=Date.now(),this.percent=0,n({percent:0,type:f}),this.easingFn=v[this.config.easing],this._run())},t._run=function(){var e=this,t=this.config,n=t.onRun,r=t.onStop;this._raf&&u(this._raf),this._raf=s((function(){if(e.now=Date.now(),e.t=e.now-e.start,e.duration=e.now-e.start>=e.config.duration?e.config.duration:e.now-e.start,e.progress=e.easingFn(e.duration/e.config.duration),e.percent=e.duration/e.config.duration+e._hasFinishedPercent,e.percent>=1||e._stop)return e.percent=e._stop&&e._stop.percent?e._stop.percent:1,e.duration=e._stop&&e._stop.duration?e._stop.duration:e.duration,n({percent:e.progress,originPercent:e.percent,t:e.t,type:p}),r({percent:e.percent,t:e.t,type:h}),void(e.percent>=1&&(e.isfinished=!0,e.stop()));n({percent:e.progress,originPercent:e.percent,t:e.t,type:p}),e._run()}))},t.stop=function(){var e=this.config.onEnd;this._stop={percent:this.percent,now:this.now},e({percent:1,t:this.t,type:d}),u(this._raf)},e}();function g(e,t){var n,r,o,i,c=0;function l(){i=0,c=+new Date,o=e.apply(n,r),n=null,r=null}return function(){n=this,r=arguments;var e=(new Date).getTime()-c;return i||(e>=t?l():i=setTimeout(l,t-e)),o}}var y=n(3);n(5);function w(){return w=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},w.apply(this,arguments)}var O,j=750,S="rax-scrollview-style",x="rax-scrollview";function _(e,t,n,r,o){var i=e.current,c=i.scrollLeft,l=i.scrollTop;r?new b({duration:o,easing:"easeOutSine",onRun:function(r){e&&e.current&&(t>=0&&(e.current.scrollLeft=c+r.percent*(t-c)),n>=0&&(e.current.scrollTop=l+r.percent*(n-l)))}}).run():(t>=0&&(e.current.scrollLeft=t),n>=0&&(e.current.scrollTop=n))}function E(){return O||(O=document.documentElement.clientWidth/j)}function T(e){var t=E();if("number"==typeof e)return e*t;var n=/^(\d+)(r{0,1}px){0,1}$/.exec(e);if(n){if(!n[2])return parseInt(n[1])*t;if("rpx"===n[2])return parseInt(n[1])*t;if("px"===n[2])return parseInt(n[1])}return 0}var R=Object(r.forwardRef)((function(e,t){var n,o=e.className,c=e.style,a=e.horizontal,s=e.contentContainerStyle,u=e.disableScroll,f=e.scrollEventThrottle,d=e.showsHorizontalScrollIndicator,p=e.showsVerticalScrollIndicator,h=e.onEndReached,v=e.onEndReachedThreshold,m=e.onScroll,b=e.children,y=Object(r.useRef)(0),O=Object(r.useRef)(0),j=Object(r.useRef)(0),E=Object(r.useRef)(null),R=Object(r.useRef)(null),I=function(t){if(e.onScroll){var n=t.target||t.srcElement||{};t.nativeEvent={get contentOffset(){return{x:n.scrollLeft,y:n.scrollTop}},get contentSize(){return{width:n.scrollWidth,height:n.scrollHeight}}},m(t)}if(h){var r=E.current;if(!r)return;j.current=a?r.offsetWidth:r.offsetHeight;var o=a?r.scrollWidth:r.scrollHeight,i=a?r.scrollLeft:r.scrollTop,c=T(v),l=o-i-j.current<c,s=i>y.current,u=o!=O.current;l&&s&&u&&(O.current=o,e.onEndReached(t)),y.current=i}};if(Object(r.useImperativeHandle)(t,(function(){return{_nativeNode:E.current,resetScroll:function(){O.current=0,y.current=0},scrollTo:function(e){var t=e||{},n=t.x,r=void 0===n?0:n,o=t.y,i=void 0===o?0:o,c=t.animated,l=void 0===c||c,a=t.duration,s=void 0===a?400:a;_(E,T(r),T(i),l,s)},scrollIntoView:function(e){var t=e||{},n=t.id,r=t.animated,o=void 0===r||r,i=t.duration,c=void 0===i?400:i,l=t.offsetX,a=t.offsetY;if(!n)throw new Error("Params missing id.");var s=document.getElementById(n);if(s&&R.current){var u=s.getBoundingClientRect(),f=R.current.getBoundingClientRect(),d=u.x-f.x+T(l),p=u.y-f.y+T(a);_(E,d,p,o,c)}}}})),c){var P=["alignItems","justifyContent"].filter((function(e){return void 0!==c[e]}));0!==P.length&&console.warn("ScrollView child layout ("+JSON.stringify(P)+") must be applied through the contentContainerStyle prop.")}var z=Object(r.createElement)(i.a,{ref:R,className:l()((n={},n[x+"-content-container-horizontal"]=a,n[x+"-webcontainer"]=!a,n)),style:s},b),N=Object.assign({},c);null!==N.height&&void 0!==N.height||(N.flex=1);var A=l()(x,x+"-"+(a?"horizontal":"vertical"),o);if(!(a?d:p)&&"undefined"!=typeof document&&"function"==typeof document.getElementById&&!document.getElementById(S)){var W=document.createElement("style");W.id=S,document.head.appendChild(W),W.innerHTML="."+x+"::-webkit-scrollbar{display: none;}"}N.WebkitOverflowScrolling="touch",a?(N.overflowX="scroll",N.overflowY="hidden"):(N.overflowX="hidden",N.overflowY="scroll"),u&&(N.overflowX="hidden",N.overflowY="scroll");var q=Object.assign({},e);return delete q.onEndReachedThreshold,Object(r.createElement)(i.a,w({},q,{ref:E,className:A,style:N,onScroll:f?g(I,f):I}),z)}));t.a=Object(y.a)(R)},function(e,t){},function(e,t,n){"use strict";var r=n(0),o=n(2),i=n.n(o),c=n(3),l=n(9);n(5);function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a.apply(this,arguments)}var s,u=750,f="rax-scrollview";function d(e){if("number"==typeof e)return e;var t=/^([\d\.]+)(r?px)?$/.exec(e);if(t){if(!t[2])return parseFloat(t[1]);if("rpx"===t[2]){var n=s||(s=Object(l.getInfoSync)().windowWidth/u);return parseFloat(t[1])*n}if("px"===t[2])return parseFloat(t[1])}return 0}var p=Object(r.forwardRef)((function(e,t){var n=e.className,o=e.style,c=e.horizontal,l=e.onEndReached,s=e.onScroll,u=e.children,p=e.disableScroll,h=void 0!==p&&p,v=e.onEndReachedThreshold,m=Object(r.useState)(0)[0],b=Object(r.useState)(0)[0],g=Object(r.useState)(!1),y=g[0],w=g[1],O=Object(r.useState)(400),j=O[0],S=O[1],x=Object(r.useState)(null)[0],_=Object(r.useRef)(null);Object(r.useImperativeHandle)(t,(function(){return{_nativeNode:_.current,resetScroll:function(){c?_.current.setAttribute("scroll-left","0"):_.current.setAttribute("scroll-top","0")},scrollTo:function(e){var t=e||{},n=t.x,r=void 0===n?0:n,o=t.y,i=void 0===o?0:o,l=t.animated,a=void 0===l||l,s=t.duration,u=void 0===s?400:s;c?_.current.setAttribute("scroll-left",String(d(r))):_.current.setAttribute("scroll-top",String(d(i))),w(a),S(u)},scrollIntoView:function(e){var t=e||{},n=t.id,r=t.animated,o=void 0===r||r,i=t.duration,c=void 0===i?400:i;if(!n)throw new Error("Params missing id.");_.current.setAttribute("scroll-into-view",n),w(o),S(c)}}}));var E=Object.assign({},o);null===E.height&&(E.flex=1);var T=i()(f,f+"-"+(c?"horizontal":"vertical"),n),R=d(v);return Object(r.createElement)("scroll-view",a({},e,{ref:_,className:T,style:E,"scroll-top":m,"scroll-left":b,onScroll:s?function(e){s&&(e.nativeEvent={get contentOffset(){return{x:e.detail.scrollLeft,y:e.detail.scrollTop}},get contentSize(){return{width:e.detail.scrollWidth,height:e.detail.scrollHeight}}},s(e))}:null,onScrollToLower:l,"lower-threshold":R,"scroll-with-animation":y,"scroll-animation-duration":j,"scroll-x":!h&&c,"scroll-y":!h&&!c,"scroll-into-view":x,"enable-flex":!0}),u)}));t.a=Object(c.a)(p)},function(e,t){e.exports=require("@uni/system-info")},function(e,t,n){"use strict";var r=n(0),o=n(4),i=n.n(o),c=n(11),l=n.n(c),a=n(12),s=n.n(a),u=n(2),f=n.n(u),d=n(3);n(5);function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},p.apply(this,arguments)}var h="object"==typeof __weex_v2__,v="rax-scrollview",m=Object(r.forwardRef)((function(e,t){var n=e.className,o=e.style,c=e.horizontal,a=e.contentContainerStyle,u=e.showsHorizontalScrollIndicator,d=e.showsVerticalScrollIndicator,m=e.onEndReached,b=e.onEndReachedThreshold,g=e.onScroll,y=e.children,w=Object(r.useState)(0),O=w[0],j=w[1],S=Object(r.useRef)(null),x=Object(r.useRef)(null);if(Object(r.useImperativeHandle)(t,(function(){return{_nativeNode:S.current,resetScroll:function(){j(O+1)},scrollTo:function(e){if(h)S.current.scrollTo(void 0,e);else{var t=e||{},n=t.x,r=void 0===n?0:n,o=t.y,i=void 0===o?0:o,c=t.animated,l=void 0===c||c,a=__weex_require__("@weex-module/dom"),s=x.current;s&&a.scrollToElement(s,{offset:r||i||0,animated:l})}},scrollIntoView:function(e){var t=e||{},n=t.id,r=t.animated,o=void 0===r||r,i=t.duration,c=t.offsetX,l=t.offsetY;if(!n)throw new Error("Params missing id.");var a=s()(n);a&&(h?S.current.scrollTo(a,{animated:o,duration:i,x:c,y:l}):__weex_require__("@weex-module/dom").scrollToElement(a,{offset:c||l||0,animated:o}))}}})),b="string"==typeof b?parseInt(b,10):b,o){var _=["alignItems","justifyContent"].filter((function(e){return void 0!==o[e]}));0!==_.length&&console.warn("ScrollView child layout ("+JSON.stringify(_)+") must be applied through the contentContainerStyle prop.")}var E,T=null;if(h)E=y;else{var R;T=Object(r.createElement)(i.a,null);var I=null;I=Array.isArray(y)?y.map((function(e){return"object"==typeof e&&null!==e&&"type"in e&&e.type==l.a?(T=e,null):e})):y,E=Object(r.createElement)(i.a,{ref:x,className:f()((R={},R[v+"-content-container-horizontal"]=c,R)),style:a},I)}var P=Object.assign({},o);null===P.height&&(P.flex=1);var z=f()(v,v+"-"+(c?"horizontal":"vertical"),n),N=c?u:d,A=Object.assign({},e);return h&&delete A.onEndReachedThreshold,Object(r.createElement)("scroller",p({},A,{ref:S,className:z,style:P,showScrollbar:N,onLoadmore:m,onScroll:g?function(e){e.nativeEvent={contentOffset:{x:-e.contentOffset.x,y:-e.contentOffset.y},contentSize:e.contentSize?{width:e.contentSize.width,height:e.contentSize.height}:null},g(e)}:null,loadmoreoffset:b,loadmoreretry:O,scrollDirection:c?"horizontal":"vertical"}),T,E)}));t.a=Object(d.a)(m)},function(e,t){e.exports=require("rax-refreshcontrol")},function(e,t){e.exports=require("rax-get-element-by-id")},function(e,t,n){e.exports=n(14)},function(e,t,n){"use strict";n.r(t);var r=n(1),o=n(6),i=n(8),c=n(10),l=n(7);for(var a in l)["default"].indexOf(a)<0&&function(e){n.d(t,e,(function(){return l[e]}))}(a);var s=null;s=r.isWeb?o.a:r.isMiniApp||r.isWeChatMiniProgram||r.isByteDanceMicroApp||r.isBaiduSmartProgram||r.isKuaiShouMiniProgram?i.a:r.isWeex?c.a:o.a,t.default=s}])}));