提交 54686c68 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(mp-weixin): skyline gesture (question/162700)

上级 3a9801a7
......@@ -328,7 +328,7 @@ const promiseInterceptor = {
};
const SYNC_API_RE =
/^\$|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale|invokePushCallback|getWindowInfo|getDeviceInfo|getAppBaseInfo|getSystemSetting|getAppAuthorizeSetting/;
/^\$|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale|invokePushCallback|getWindowInfo|getDeviceInfo|getAppBaseInfo|getSystemSetting|getAppAuthorizeSetting|initUTS|requireUTS|registerUTS/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -923,6 +923,18 @@ var getAppAuthorizeSetting = {
// import navigateTo from 'uni-helpers/navigate-to'
const compressImage = {
args (fromArgs) {
// https://developers.weixin.qq.com/community/develop/doc/000c08940c865011298e0a43256800?highLine=compressHeight
if (fromArgs.compressedHeight && !fromArgs.compressHeight) {
fromArgs.compressHeight = fromArgs.compressedHeight;
}
if (fromArgs.compressedWidth && !fromArgs.compressWidth) {
fromArgs.compressWidth = fromArgs.compressedWidth;
}
}
};
const protocols = {
redirectTo,
// navigateTo, // 由于在微信开发者工具的页面参数,会显示__id__参数,因此暂时关闭mp-weixin对于navigateTo的AOP
......@@ -933,7 +945,8 @@ const protocols = {
getAppBaseInfo,
getDeviceInfo,
getWindowInfo,
getAppAuthorizeSetting
getAppAuthorizeSetting,
compressImage
};
const todos = [
'vibrate',
......@@ -1416,6 +1429,20 @@ function toSkip (obj) {
});
}
return obj
}
const WORKLET_RE = /_(.*)_worklet_factory_/;
function initWorkletMethods (mpMethods, vueMethods) {
if (vueMethods) {
Object.keys(vueMethods).forEach((name) => {
const matches = name.match(WORKLET_RE);
if (matches) {
const workletName = matches[1];
mpMethods[name] = vueMethods[name];
mpMethods[workletName] = vueMethods[workletName];
}
});
}
}
const MPPage = Page;
......@@ -2423,6 +2450,9 @@ function parseBasePage (vuePageOptions) {
{
initUnknownHooks(pageOptions.methods, vuePageOptions, ['onReady']);
}
{
initWorkletMethods(pageOptions.methods, vueOptions.methods);
}
return pageOptions
}
......
......@@ -438,4 +438,11 @@ describe('mp:compiler-mp-weixin', () => {
}
)
})
it('skyline gesture', () => {
assertCodegen(
'<vertical-drag-gesture-handler onGestureEvent="handlePan" native-view="scroll-view" shouldResponseOnMove="shouldResponse" shouldAcceptGesture="shouldAccept"/>',
'<vertical-drag-gesture-handler onGestureEvent="handlePan" native-view="scroll-view" shouldResponseOnMove="shouldResponse" shouldAcceptGesture="shouldAccept"></vertical-drag-gesture-handler>'
)
})
})
......@@ -83,7 +83,15 @@ const tags = {
'page-container',
'page-meta',
'navigation-bar',
'match-media'
'match-media',
// 手势组件
'tap-gesture-handler',
'double-tap-gesture-handler',
'pan-gesture-handler',
'scale-gesture-handler',
'force-press-gesture-handler',
'vertical-drag-gesture-handler',
'horizontal-drag-gesture-handler'
],
// 支付宝小程序平台独有组件
'mp-alipay': [
......@@ -184,4 +192,4 @@ module.exports = function getCompilerOptions (platform) {
baseCompiler,
require(id + '/lib/uni.compiler.js')
)
}
}
......@@ -213,6 +213,19 @@ function getCondition (pagesJson) {
return false
}
function weixinSkyline (config) {
return config.renderer === 'skyline' && config.lazyCodeLoading === 'requiredComponents'
}
function openES62ES5 (config) {
if (!config.setting) {
config.setting = {}
}
if (!config.setting.es6) {
config.setting.es6 = true
}
}
module.exports = function (pagesJson, manifestJson, project = {}) {
const app = {
pages: [],
......@@ -291,8 +304,8 @@ module.exports = function (pagesJson, manifestJson, project = {}) {
}
if (
process.env.UNI_PLATFORM === 'mp-weixin' ||
process.env.UNI_PLATFORM === 'mp-qq'
platform === 'mp-weixin' ||
platform === 'mp-qq'
) {
// 微信不需要生成,其他平台做拷贝
return {
......@@ -354,6 +367,9 @@ module.exports = function (pagesJson, manifestJson, project = {}) {
}
}
// 使用了微信小程序手势系统,自动开启 ES6=>ES5
platform === 'mp-weixin' && weixinSkyline(manifestJson[platform]) && openES62ES5(project)
if (process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
if (!project.setting) {
project.setting = {}
......
......@@ -71,10 +71,9 @@ export {
initUTSClassName,
initUTSPackageName,
requireUTSPlugin,
registerUTSPlugin,
registerUTSPlugin
} from './plugin/uts'
export * from './route/navigate-back'
export * from './route/navigate-to'
export * from './route/re-launch'
......
......@@ -10,6 +10,8 @@ import {
import parseComponent from 'uni-platform/runtime/wrapper/component-parser'
import { initWorkletMethods } from './util'
const hooks = [
'onShow',
'onHide',
......@@ -38,6 +40,9 @@ export default function parseBasePage (vuePageOptions) {
} else {
initUnknownHooks(pageOptions.methods, vuePageOptions, ['onReady'])
}
if (__PLATFORM__ === 'mp-weixin') {
initWorkletMethods(pageOptions.methods, vueOptions.methods)
}
return pageOptions
}
......@@ -134,3 +134,17 @@ export function toSkip (obj) {
}
return obj
}
const WORKLET_RE = /_(.*)_worklet_factory_/
export function initWorkletMethods (mpMethods, vueMethods) {
if (vueMethods) {
Object.keys(vueMethods).forEach((name) => {
const matches = name.match(WORKLET_RE)
if (matches) {
const workletName = matches[1]
mpMethods[name] = vueMethods[name]
mpMethods[workletName] = vueMethods[workletName]
}
})
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册