From bc25bf5ec9c40226c50e0e38e290b788a20fd4ce Mon Sep 17 00:00:00 2001 From: tianjiaxing Date: Wed, 18 Aug 2021 13:35:16 +0800 Subject: [PATCH] feat(app): mediaQueryObserver --- .../uni-app-plus/dist/uni-app-service.es.js | 29 +++++++++++-- .../uni-app-plus/dist/uni-app-view.umd.js | 2 +- packages/uni-app-plus/src/platform/index.ts | 18 +++----- .../src/service/api/ui/mediaQueryObserver.ts | 42 +++++++++++++++++++ .../src/view/framework/viewMethods.ts | 14 +++++++ .../src/service/api/ui/mediaQueryObserver.ts | 4 +- packages/uni-mp-vue/dist/vue.runtime.esm.js | 6 ++- 7 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 packages/uni-app-plus/src/service/api/ui/mediaQueryObserver.ts diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js index 24249fbdb..c095d552e 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -2229,12 +2229,12 @@ var serviceContext = (function (vue) { }, pageId, operateMapCallback); } - function getEventName(reqId) { + function getEventName$1(reqId) { const EVENT_NAME = 'IntersectionObserver'; return `${EVENT_NAME}.${reqId}`; } function addIntersectionObserver({ reqId, component, options, callback }, _pageId) { - const eventName = getEventName(reqId); + const eventName = getEventName$1(reqId); UniServiceJSBridge.invokeViewMethod('addIntersectionObserver', { reqId, component: component.$el.nodeId, @@ -2248,11 +2248,32 @@ var serviceContext = (function (vue) { reqId, component: component.$el.nodeId, }, _pageId); + UniServiceJSBridge.unsubscribe(getEventName$1(reqId)); + } + + function getEventName(reqId) { + const EVENT_NAME = 'MediaQueryObserver'; + return `${EVENT_NAME}.${reqId}`; + } + function addMediaQueryObserver({ reqId, component, options, callback }, _pageId) { + const eventName = getEventName(reqId); + UniServiceJSBridge.invokeViewMethod('addMediaQueryObserver', { + reqId, + component: component.$el.nodeId, + options, + eventName, + }, _pageId); + UniServiceJSBridge.subscribe(eventName, callback); + } + function removeMediaQueryObserver({ reqId, component }, _pageId) { + UniServiceJSBridge.invokeViewMethod('removeMediaQueryObserver', { + reqId, + component: component.$el.nodeId, + // reqEnd: true + }, _pageId); UniServiceJSBridge.unsubscribe(getEventName(reqId)); } - function addMediaQueryObserver(args, pageId) { } - function removeMediaQueryObserver(args, pageId) { } const TEMP_PATH$1 = ''; const API_UPX2PX = 'upx2px'; diff --git a/packages/uni-app-plus/dist/uni-app-view.umd.js b/packages/uni-app-plus/dist/uni-app-view.umd.js index a006a8712..b85e8b7db 100644 --- a/packages/uni-app-plus/dist/uni-app-view.umd.js +++ b/packages/uni-app-plus/dist/uni-app-view.umd.js @@ -1 +1 @@ -!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";var e={exports:{}},t={exports:{}},n={exports:{}},r=n.exports={version:"2.6.12"};"number"==typeof __e&&(__e=r);var i={exports:{}},a=i.exports=void 0!==a&&a.Math==Math?a:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=a);var o=n.exports,s=i.exports,l="__core-js_shared__",u=s[l]||(s[l]={});(t.exports=function(e,t){return u[e]||(u[e]=void 0!==t?t:{})})("versions",[]).push({version:o.version,mode:"window",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"});var c=0,d=Math.random(),h=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++c+d).toString(36))},p=t.exports("wks"),f=h,v=i.exports.Symbol,g="function"==typeof v;(e.exports=function(e){return p[e]||(p[e]=g&&v[e]||(g?v:f)("Symbol."+e))}).store=p;var m={},y=function(e){return"object"==typeof e?null!==e:"function"==typeof e},_=y,b=function(e){if(!_(e))throw TypeError(e+" is not an object!");return e},w=function(e){try{return!!e()}catch(t){return!0}},x=!w((function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})),S=y,T=i.exports.document,E=S(T)&&S(T.createElement),k=function(e){return E?T.createElement(e):{}},C=!x&&!w((function(){return 7!=Object.defineProperty(k("div"),"a",{get:function(){return 7}}).a})),M=y,O=b,I=C,L=function(e,t){if(!M(e))return e;var n,r;if(t&&"function"==typeof(n=e.toString)&&!M(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!M(r=n.call(e)))return r;if(!t&&"function"==typeof(n=e.toString)&&!M(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")},N=Object.defineProperty;m.f=x?Object.defineProperty:function(e,t,n){if(O(e),t=L(t,!0),O(n),I)try{return N(e,t,n)}catch(r){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(e[t]=n.value),e};var A=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},P=m,R=A,B=x?function(e,t,n){return P.f(e,t,R(1,n))}:function(e,t,n){return e[t]=n,e},$=e.exports("unscopables"),D=Array.prototype;null==D[$]&&B(D,$,{});var F={},W={}.toString,j=function(e){return W.call(e).slice(8,-1)},V=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},z=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==j(e)?e.split(""):Object(e)},H=V,q=function(e){return z(H(e))},U={exports:{}},Y={}.hasOwnProperty,X=function(e,t){return Y.call(e,t)},G=t.exports("native-function-to-string",Function.toString),J=i.exports,K=B,Z=X,Q=h("src"),ee=G,te="toString",ne=(""+ee).split(te);n.exports.inspectSource=function(e){return ee.call(e)},(U.exports=function(e,t,n,r){var i="function"==typeof n;i&&(Z(n,"name")||K(n,"name",t)),e[t]!==n&&(i&&(Z(n,Q)||K(n,Q,e[t]?""+e[t]:ne.join(String(t)))),e===J?e[t]=n:r?e[t]?e[t]=n:K(e,t,n):(delete e[t],K(e,t,n)))})(Function.prototype,te,(function(){return"function"==typeof this&&this[Q]||ee.call(this)}));var re=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e},ie=re,ae=i.exports,oe=n.exports,se=B,le=U.exports,ue=function(e,t,n){if(ie(e),void 0===t)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}},ce=function(e,t,n){var r,i,a,o,s=e&ce.F,l=e&ce.G,u=e&ce.S,c=e&ce.P,d=e&ce.B,h=l?ae:u?ae[t]||(ae[t]={}):(ae[t]||{}).prototype,p=l?oe:oe[t]||(oe[t]={}),f=p.prototype||(p.prototype={});for(r in l&&(n=t),n)a=((i=!s&&h&&void 0!==h[r])?h:n)[r],o=d&&i?ue(a,ae):c&&"function"==typeof a?ue(Function.call,a):a,h&&le(h,r,a,e&ce.U),p[r]!=a&&se(p,r,o),c&&f[r]!=a&&(f[r]=a)};ae.core=oe,ce.F=1,ce.G=2,ce.S=4,ce.P=8,ce.B=16,ce.W=32,ce.U=64,ce.R=128;var de,he=ce,pe=Math.ceil,fe=Math.floor,ve=function(e){return isNaN(e=+e)?0:(e>0?fe:pe)(e)},ge=ve,me=Math.min,ye=ve,_e=Math.max,be=Math.min,we=q,xe=function(e){return e>0?me(ge(e),9007199254740991):0},Se=function(e,t){return(e=ye(e))<0?_e(e+t,0):be(e,t)},Te=t.exports("keys"),Ee=h,ke=function(e){return Te[e]||(Te[e]=Ee(e))},Ce=X,Me=q,Oe=(de=!1,function(e,t,n){var r,i=we(e),a=xe(i.length),o=Se(n,a);if(de&&t!=t){for(;a>o;)if((r=i[o++])!=r)return!0}else for(;a>o;o++)if((de||o in i)&&i[o]===t)return de||o||0;return!de&&-1}),Ie=ke("IE_PROTO"),Le="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(","),Ne=function(e,t){var n,r=Me(e),i=0,a=[];for(n in r)n!=Ie&&Ce(r,n)&&a.push(n);for(;t.length>i;)Ce(r,n=t[i++])&&(~Oe(a,n)||a.push(n));return a},Ae=Le,Pe=Object.keys||function(e){return Ne(e,Ae)},Re=m,Be=b,$e=Pe,De=x?Object.defineProperties:function(e,t){Be(e);for(var n,r=$e(t),i=r.length,a=0;i>a;)Re.f(e,n=r[a++],t[n]);return e},Fe=i.exports.document,We=Fe&&Fe.documentElement,je=b,Ve=De,ze=Le,He=ke("IE_PROTO"),qe=function(){},Ue=function(){var e,t=k("iframe"),n=ze.length;for(t.style.display="none",We.appendChild(t),t.src="javascript:",(e=t.contentWindow.document).open(),e.write("