Skip to content

Commit

Permalink
build uni runtime(app-plus add subNVue)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Apr 29, 2019
1 parent c9a2c89 commit 8cf72d2
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 10 deletions.
71 changes: 65 additions & 6 deletions packages/uni-app-plus/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
});

const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;
const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;

const CONTEXT_API_RE = /^create|Manager$/;

Expand Down Expand Up @@ -144,7 +144,9 @@ function upx2px (number, newDeviceWidth) {
return number < 0 ? -result : result
}

var protocols = {};
const protocols = {};
const todos = [];
const canIUses = [];

const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];

Expand Down Expand Up @@ -248,7 +250,52 @@ TODOS.forEach(function (name) {
todoApis[name] = createTodoApi(name);
});

function requireNativePlugin (pluginName) {
function wrapper$1 (webview) {
webview.$processed = true;
if (!webview.__uniapp_mask_id) {
return
}
const maskColor = webview.__uniapp_mask;
const maskWebview = plus.webview.getWebviewById(webview.__uniapp_mask_id);
const oldShow = webview.show;
const oldHide = webview.hide;
const oldClose = webview.close;

const showMask = function () {
maskWebview.setStyle({
mask: maskColor
});
};
const closeMask = function () {
maskWebview.setStyle({
mask: 'none'
});
};
webview.show = function (...args) {
showMask();
return oldShow.apply(webview, args)
};
webview.hide = function (...args) {
closeMask();
return oldHide.apply(webview, args)
};
webview.close = function (...args) {
closeMask();
return oldClose.apply(webview, args)
};
}

const subNVue = {
getSubNVueById (id) {
const webview = plus.webview.getWebviewById(id);
if (webview && !webview.$processed) {
wrapper$1(webview);
}
return webview
}
};

function requireNativePlugin (pluginName) {
/* eslint-disable no-undef */
if (typeof weex !== 'undefined') {
return weex.requireModule(pluginName)
Expand All @@ -258,7 +305,8 @@ function requireNativePlugin (pluginName) {
}

var api = /*#__PURE__*/Object.freeze({
requireNativePlugin: requireNativePlugin
requireNativePlugin: requireNativePlugin,
subNVue: subNVue
});

const MPPage = Page;
Expand Down Expand Up @@ -532,7 +580,7 @@ function getProperties (props, isBehavior = false, file = '') {
return properties
}

function wrapper$1 (event) {
function wrapper$2 (event) {
// TODO 又得兼容 mpvue 的 mp 对象
try {
event.mp = JSON.parse(JSON.stringify(event));
Expand Down Expand Up @@ -683,7 +731,7 @@ const ONCE = '~';
const CUSTOM = '^';

function handleEvent (event) {
event = wrapper$1(event);
event = wrapper$2(event);

// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const eventOpts = (event.currentTarget || event.target).dataset.eventOpts;
Expand Down Expand Up @@ -975,6 +1023,17 @@ function createComponent (vueOptions) {
return initComponent$1(componentOptions, vueOptions)
}

todos.forEach(todoApi => {
protocols[todoApi] = false;
});

canIUses.forEach(canIUseApi => {
const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name : canIUseApi;
if (!wx.canIUse(apiName)) {
protocols[canIUseApi] = false;
}
});

let uni = {};

if (typeof Proxy !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-app-plus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-app-plus",
"version": "0.0.230",
"version": "0.0.231",
"description": "uni-app app-plus",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/helpers/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
isFn
} from 'uni-shared'

const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/
const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/

const CONTEXT_API_RE = /^create|Manager$/

Expand Down
6 changes: 4 additions & 2 deletions src/platforms/app-plus/service/api/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export function requireNativePlugin (pluginName) {
export function requireNativePlugin (pluginName) {
/* eslint-disable no-undef */
if (typeof weex !== 'undefined') {
return weex.requireModule(pluginName)
}
/* eslint-disable no-undef */
return __requireNativePlugin__(pluginName)
}
}

export * from './sub-nvue'
44 changes: 44 additions & 0 deletions src/platforms/app-plus/service/api/sub-nvue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function wrapper (webview) {
webview.$processed = true
if (!webview.__uniapp_mask_id) {
return
}
const maskColor = webview.__uniapp_mask
const maskWebview = plus.webview.getWebviewById(webview.__uniapp_mask_id)
const oldShow = webview.show
const oldHide = webview.hide
const oldClose = webview.close

const showMask = function () {
maskWebview.setStyle({
mask: maskColor
})
}
const closeMask = function () {
maskWebview.setStyle({
mask: 'none'
})
}
webview.show = function (...args) {
showMask()
return oldShow.apply(webview, args)
}
webview.hide = function (...args) {
closeMask()
return oldHide.apply(webview, args)
}
webview.close = function (...args) {
closeMask()
return oldClose.apply(webview, args)
}
}

export const subNVue = {
getSubNVueById (id) {
const webview = plus.webview.getWebviewById(id)
if (webview && !webview.$processed) {
wrapper(webview)
}
return webview
}
}

0 comments on commit 8cf72d2

Please sign in to comment.