UNPKG

rax-scrollview

Version:
1 lines 14.4 kB
!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}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={"rax-scrollview-vertical":{display:"flex",flexDirection:"column"},"rax-scrollview-horizontal":{display:"flex",flexDirection:"row"},"rax-scrollview-content-container-horizontal":{flexDirection:"row"},"rax-scrollview-webcontainer":{display:"block"}}},function(e,t){e.exports=require("rax-view")},function(e,t,n){"use strict";var r=n(0),o=n(5),i=n.n(o),c=n(2),a=n.n(c),l=n(1),s=l.isWeb&&void 0!==window.requestAnimationFrame?window.requestAnimationFrame:function(e){return setTimeout(e,16)},u=l.isWeb&&void 0!==window.cancelAnimationFrame?window.cancelAnimationFrame:clearTimeout,f="start",d="end",h="run",p="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:h}),r({percent:e.percent,t:e.t,type:p}),void(e.percent>=1&&(e.isfinished=!0,e.stop()));n({percent:e.progress,originPercent:e.percent,t:e.t,type:h}),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 a(){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?a():i=setTimeout(a,t-e)),o}}var y=n(3),w=n(4);function O(){return O=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},O.apply(this,arguments)}var j=n.n(w).a;function x(){var e=[],t=arguments[0],n=Object.prototype.toString.call(t).slice(8,-1).toLowerCase();if("string"===n)(t=t.trim())&&e.push(t);else if("array"===n)t.forEach((function(t){(t=x(t).trim())&&e.push(t)}));else if("object"===n)for(var r in t)(r=r.trim())&&t.hasOwnProperty(r)&&t[r]&&e.push(r);return e.join(" ").trim()}function S(e){var t=j.__cache||(j.__cache={}),n=x(e),r=n.split(/\s+/),o=t[n];return o||(o={},1===r.length?o=j[r[0].trim()]:r.forEach((function(e){"object"==typeof j[e.trim()]&&(o=Object.assign(o,j[e.trim()]))})),t[n]=o),o}var _,E=750,T="rax-scrollview-style",R="rax-scrollview";function I(e,t,n,r,o){var i=e.current,c=i.scrollLeft,a=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=a+r.percent*(n-a)))}}).run():(t>=0&&(e.current.scrollLeft=t),n>=0&&(e.current.scrollTop=n))}function P(){return _||(_=document.documentElement.clientWidth/E)}function z(e){var t=P();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 N=Object(r.forwardRef)((function(e,t){var n,o=e.className,c=e.style,l=e.horizontal,s=e.contentContainerStyle,u=e.disableScroll,f=e.scrollEventThrottle,d=e.showsHorizontalScrollIndicator,h=e.showsVerticalScrollIndicator,p=e.onEndReached,v=e.onEndReachedThreshold,m=e.onScroll,b=e.children,y=Object(r.useRef)(0),w=Object(r.useRef)(0),j=Object(r.useRef)(0),x=Object(r.useRef)(null),_=Object(r.useRef)(null),E=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(p){var r=x.current;if(!r)return;j.current=l?r.offsetWidth:r.offsetHeight;var o=l?r.scrollWidth:r.scrollHeight,i=l?r.scrollLeft:r.scrollTop,c=z(v),a=o-i-j.current<c,s=i>y.current,u=o!=w.current;a&&s&&u&&(w.current=o,e.onEndReached(t)),y.current=i}};if(Object(r.useImperativeHandle)(t,(function(){return{_nativeNode:x.current,resetScroll:function(){w.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,a=void 0===c||c,l=t.duration,s=void 0===l?400:l;I(x,z(r),z(i),a,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,a=t.offsetX,l=t.offsetY;if(!n)throw new Error("Params missing id.");var s=document.getElementById(n);if(s&&_.current){var u=s.getBoundingClientRect(),f=_.current.getBoundingClientRect(),d=u.x-f.x+z(a),h=u.y-f.y+z(l);I(x,d,h,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 N=Object(r.createElement)(i.a,{ref:_,className:a()((n={},n[R+"-content-container-horizontal"]=l,n[R+"-webcontainer"]=!l,n)),style:Object.assign({},S(a()((n={},n[R+"-content-container-horizontal"]=l,n[R+"-webcontainer"]=!l,n))),s)},b),A=Object.assign({},c);null!==A.height&&void 0!==A.height||(A.flex=1);var C=a()(R,R+"-"+(l?"horizontal":"vertical"),o);if(!(l?d:h)&&"undefined"!=typeof document&&"function"==typeof document.getElementById&&!document.getElementById(T)){var L=document.createElement("style");L.id=T,document.head.appendChild(L),L.innerHTML="."+R+"::-webkit-scrollbar{display: none;}"}A.WebkitOverflowScrolling="touch",l?(A.overflowX="scroll",A.overflowY="hidden"):(A.overflowX="hidden",A.overflowY="scroll"),u&&(A.overflowX="hidden",A.overflowY="scroll");var W=Object.assign({},e);return delete W.onEndReachedThreshold,Object(r.createElement)(i.a,O({},W,{ref:x,className:C,style:Object.assign({},S(C),A),onScroll:f?g(E,f):E}),N)}));t.a=Object(y.a)(N)},function(e,t){},function(e,t,n){"use strict";var r=n(0),o=n(2),i=n.n(o),c=n(3),a=n(9),l=n(4);function s(){return s=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},s.apply(this,arguments)}var u=n.n(l).a;function f(){var e=[],t=arguments[0],n=Object.prototype.toString.call(t).slice(8,-1).toLowerCase();if("string"===n)(t=t.trim())&&e.push(t);else if("array"===n)t.forEach((function(t){(t=f(t).trim())&&e.push(t)}));else if("object"===n)for(var r in t)(r=r.trim())&&t.hasOwnProperty(r)&&t[r]&&e.push(r);return e.join(" ").trim()}function d(e){var t=u.__cache||(u.__cache={}),n=f(e),r=n.split(/\s+/),o=t[n];return o||(o={},1===r.length?o=u[r[0].trim()]:r.forEach((function(e){"object"==typeof u[e.trim()]&&(o=Object.assign(o,u[e.trim()]))})),t[n]=o),o}var h,p=750,v="rax-scrollview";function m(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=h||(h=Object(a.getInfoSync)().windowWidth/p);return parseFloat(t[1])*n}if("px"===t[2])return parseFloat(t[1])}return 0}var b=Object(r.forwardRef)((function(e,t){var n=e.className,o=e.style,c=e.horizontal,a=e.onEndReached,l=e.onScroll,u=e.children,f=e.disableScroll,h=void 0!==f&&f,p=e.onEndReachedThreshold,b=Object(r.useState)(0)[0],g=Object(r.useState)(0)[0],y=Object(r.useState)(!1),w=y[0],O=y[1],j=Object(r.useState)(400),x=j[0],S=j[1],_=Object(r.useState)(null)[0],E=Object(r.useRef)(null);Object(r.useImperativeHandle)(t,(function(){return{_nativeNode:E.current,resetScroll:function(){c?E.current.setAttribute("scroll-left","0"):E.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,a=t.animated,l=void 0===a||a,s=t.duration,u=void 0===s?400:s;c?E.current.setAttribute("scroll-left",String(m(r))):E.current.setAttribute("scroll-top",String(m(i))),O(l),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.");E.current.setAttribute("scroll-into-view",n),O(o),S(c)}}}));var T=Object.assign({},o);null===T.height&&(T.flex=1);var R=i()(v,v+"-"+(c?"horizontal":"vertical"),n),I=m(p);return Object(r.createElement)("scroll-view",s({},e,{ref:E,className:R,style:Object.assign({},d(R),T),"scroll-top":b,"scroll-left":g,onScroll:l?function(e){l&&(e.nativeEvent={get contentOffset(){return{x:e.detail.scrollLeft,y:e.detail.scrollTop}},get contentSize(){return{width:e.detail.scrollWidth,height:e.detail.scrollHeight}}},l(e))}:null,onScrollToLower:a,"lower-threshold":I,"scroll-with-animation":w,"scroll-animation-duration":x,"scroll-x":!h&&c,"scroll-y":!h&&!c,"scroll-into-view":_,"enable-flex":!0}),u)}));t.a=Object(c.a)(b)},function(e,t){e.exports=require("@uni/system-info")},function(e,t,n){"use strict";var r=n(0),o=n(5),i=n.n(o),c=n(11),a=n.n(c),l=n(12),s=n.n(l),u=n(2),f=n.n(u),d=n(3),h=n(4);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 v=n.n(h).a;function m(){var e=[],t=arguments[0],n=Object.prototype.toString.call(t).slice(8,-1).toLowerCase();if("string"===n)(t=t.trim())&&e.push(t);else if("array"===n)t.forEach((function(t){(t=m(t).trim())&&e.push(t)}));else if("object"===n)for(var r in t)(r=r.trim())&&t.hasOwnProperty(r)&&t[r]&&e.push(r);return e.join(" ").trim()}function b(e){var t=v.__cache||(v.__cache={}),n=m(e),r=n.split(/\s+/),o=t[n];return o||(o={},1===r.length?o=v[r[0].trim()]:r.forEach((function(e){"object"==typeof v[e.trim()]&&(o=Object.assign(o,v[e.trim()]))})),t[n]=o),o}var g="object"==typeof __weex_v2__,y="rax-scrollview",w=Object(r.forwardRef)((function(e,t){var n=e.className,o=e.style,c=e.horizontal,l=e.contentContainerStyle,u=e.showsHorizontalScrollIndicator,d=e.showsVerticalScrollIndicator,h=e.onEndReached,v=e.onEndReachedThreshold,m=e.onScroll,w=e.children,O=Object(r.useState)(0),j=O[0],x=O[1],S=Object(r.useRef)(null),_=Object(r.useRef)(null);if(Object(r.useImperativeHandle)(t,(function(){return{_nativeNode:S.current,resetScroll:function(){x(j+1)},scrollTo:function(e){if(g)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,a=void 0===c||c,l=__weex_require__("@weex-module/dom"),s=_.current;s&&l.scrollToElement(s,{offset:r||i||0,animated:a})}},scrollIntoView:function(e){var t=e||{},n=t.id,r=t.animated,o=void 0===r||r,i=t.duration,c=t.offsetX,a=t.offsetY;if(!n)throw new Error("Params missing id.");var l=s()(n);l&&(g?S.current.scrollTo(l,{animated:o,duration:i,x:c,y:a}):__weex_require__("@weex-module/dom").scrollToElement(l,{offset:c||a||0,animated:o}))}}})),v="string"==typeof v?parseInt(v,10):v,o){var E=["alignItems","justifyContent"].filter((function(e){return void 0!==o[e]}));0!==E.length&&console.warn("ScrollView child layout ("+JSON.stringify(E)+") must be applied through the contentContainerStyle prop.")}var T,R=null;if(g)T=w;else{var I;R=Object(r.createElement)(i.a,null);var P=null;P=Array.isArray(w)?w.map((function(e){return"object"==typeof e&&null!==e&&"type"in e&&e.type==a.a?(R=e,null):e})):w,T=Object(r.createElement)(i.a,{ref:_,className:f()((I={},I[y+"-content-container-horizontal"]=c,I)),style:Object.assign({},b(f()((I={},I[y+"-content-container-horizontal"]=c,I))),l)},P)}var z=Object.assign({},o);null===z.height&&(z.flex=1);var N=f()(y,y+"-"+(c?"horizontal":"vertical"),n),A=c?u:d,C=Object.assign({},e);return g&&delete C.onEndReachedThreshold,Object(r.createElement)("scroller",p({},C,{ref:S,className:N,style:Object.assign({},b(N),z),showScrollbar:A,onLoadmore:h,onScroll:m?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},m(e)}:null,loadmoreoffset:v,loadmoreretry:j,scrollDirection:c?"horizontal":"vertical"}),R,T)}));t.a=Object(d.a)(w)},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),a=n(7);for(var l in a)["default"].indexOf(l)<0&&function(e){n.d(t,e,(function(){return a[e]}))}(l);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}]);