react-fixed-bottom
Version:
React component to make fixed:bottom styles usable in Safari mobile
17 lines (14 loc) • 5.01 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var t,e=(t=require("react"))&&"object"==typeof t&&"default"in t?t.default:t,o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])})(t,e)};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var n=function(){return(n=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var r in e=arguments[o])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)},r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},i=/^\s+|\s+$/g,f=/^[-+]0x[0-9a-f]+$/i,u=/^0b[01]+$/i,a=/^0o[0-7]+$/i,c=parseInt,l="object"==typeof r&&r&&r.Object===Object&&r,s="object"==typeof self&&self&&self.Object===Object&&self,p=l||s||Function("return this")(),d=Object.prototype.toString,m=Math.max,v=Math.min,y=function(){return p.Date.now()};function h(t,e,o){var n,r,i,f,u,a,c=0,l=!1,s=!1,p=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function d(e){var o=n,i=r;return n=r=void 0,c=e,f=t.apply(i,o)}function h(t){return c=t,u=setTimeout(O,e),l?d(t):f}function g(t){var o=t-a;return void 0===a||o>=e||o<0||s&&t-c>=i}function O(){var t=y();if(g(t))return j(t);u=setTimeout(O,function(t){var o=e-(t-a);return s?v(o,i-(t-c)):o}(t))}function j(t){return u=void 0,p&&n?d(t):(n=r=void 0,f)}function S(){var t=y(),o=g(t);if(n=arguments,r=this,a=t,o){if(void 0===u)return h(a);if(s)return u=setTimeout(O,e),d(a)}return void 0===u&&(u=setTimeout(O,e)),f}return e=w(e)||0,b(o)&&(l=!!o.leading,i=(s="maxWait"in o)?m(w(o.maxWait)||0,e):i,p="trailing"in o?!!o.trailing:p),S.cancel=function(){void 0!==u&&clearTimeout(u),c=0,n=a=r=u=void 0},S.flush=function(){return void 0===u?f:j(y())},S}function b(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function w(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==d.call(t)}(t))return NaN;if(b(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=b(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(i,"");var o=u.test(t);return o||a.test(t)?c(t.slice(2),o?2:8):f.test(t)?NaN:+t}var g=function(t,e,o){var n=!0,r=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return b(o)&&(n="leading"in o?!!o.leading:n,r="trailing"in o?!!o.trailing:r),h(t,e,{leading:n,maxWait:e,trailing:r})};var O=function(t){function r(o){var n=t.call(this,o)||this;return n.state={bottom:n.props.offset||0},n.isSafariMobile=function(){if("undefined"==typeof window||void 0===window.navigator)return!1;var t=window.navigator.userAgent;return/iP(ad|od|hone)/i.test(t)&&/WebKit/i.test(t)&&!/(CriOS|FxiOS|OPiOS|mercury)/i.test(t)}(),n.anchorRef=e.createRef(),n.computeOffsetBottom=function(){if(n.anchorRef.current){var t=n.anchorRef.current.getBoundingClientRect().bottom,e=n.props.offset,o=void 0===e?0:e;Math.floor(Number(t))>window.innerHeight?n.setState({bottom:o+44}):n.setState({bottom:o})}},n.handleScroll=g(n.computeOffsetBottom,200),n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(r,t),r.prototype.componentDidMount=function(){this.isSafariMobile&&(window.addEventListener("scroll",this.handleScroll),this.deferredComputeOffsetBottom=setTimeout(this.computeOffsetBottom))},r.prototype.componentWillUnmount=function(){this.isSafariMobile&&(this.handleScroll.cancel(),window.removeEventListener("scroll",this.handleScroll),window.clearTimeout(this.deferredComputeOffsetBottom))},r.prototype.render=function(){var t=this.state.bottom,o=this.props,r=o.children,i=o.offset,f=e.cloneElement(r,{style:n({},r.props.style,{bottom:t,position:"fixed"})});return e.createElement(e.Fragment,null,f,this.isSafariMobile&&e.createElement("div",{ref:this.anchorRef,style:{position:"fixed",bottom:i}}))},r}(e.PureComponent);exports.FixedBottom=O;
//# sourceMappingURL=index.js.map