From 0a33ce6ddd73f724c7124afb9cc15f4d08534313 Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 26 Sep 2019 18:56:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20App=E7=AB=AF=E5=A2=9E=E5=8A=A0=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20uni.onTabBarMidButtonTap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/apis.js | 5 +++-- src/core/runtime/todo.js | 7 ++++--- src/core/service/api/ui/tab-bar.js | 19 ++++++++++++++++++- .../app-plus/service/framework/tab-bar.js | 4 ++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/apis.js b/lib/apis.js index dc6fb851f8..042a2ec8b2 100644 --- a/lib/apis.js +++ b/lib/apis.js @@ -115,7 +115,7 @@ const device = [ ] const keyboard = [ - 'hideKeyboard', + 'hideKeyboard', 'onKeyboardHeightChange' ] @@ -138,6 +138,7 @@ const ui = [ 'removeTabBarBadge', 'showTabBarRedDot', 'hideTabBarRedDot', + 'onTabBarMidButtonTap', 'setBackgroundColor', 'setBackgroundTextStyle', 'createAnimation', @@ -209,4 +210,4 @@ const apis = [ ...third ] -module.exports = apis +module.exports = apis diff --git a/src/core/runtime/todo.js b/src/core/runtime/todo.js index 1e8d2349b9..90cbcb3c40 100644 --- a/src/core/runtime/todo.js +++ b/src/core/runtime/todo.js @@ -1,10 +1,11 @@ import { isFn -} from 'uni-shared' - +} from 'uni-shared' + const todoApis = Object.create(null) const TODOS = [ + 'onTabBarMidButtonTap', 'subscribePush', 'unsubscribePush', 'onPush', @@ -29,4 +30,4 @@ TODOS.forEach(function (name) { todoApis[name] = createTodoApi(name) }) -export default todoApis +export default todoApis diff --git a/src/core/service/api/ui/tab-bar.js b/src/core/service/api/ui/tab-bar.js index b7728006fb..1d6a0d5c15 100644 --- a/src/core/service/api/ui/tab-bar.js +++ b/src/core/service/api/ui/tab-bar.js @@ -1,7 +1,12 @@ import { + onMethod, invokeMethod } from '../../platform' +import { + invoke +} from 'uni-core/service/bridge' + export function removeTabBarBadge ({ index }) { @@ -20,4 +25,16 @@ export function showTabBarRedDot ({ }) } -export const hideTabBarRedDot = removeTabBarBadge +export const hideTabBarRedDot = removeTabBarBadge + +const callbacks = [] + +onMethod('onTabBarMidButtonTap', res => { + callbacks.forEach(callbackId => { + invoke(callbackId, res) + }) +}) + +export function onTabBarMidButtonTap (callbackId) { + callbacks.push(callbackId) +} diff --git a/src/platforms/app-plus/service/framework/tab-bar.js b/src/platforms/app-plus/service/framework/tab-bar.js index 2ef4f35106..6cae39b11f 100644 --- a/src/platforms/app-plus/service/framework/tab-bar.js +++ b/src/platforms/app-plus/service/framework/tab-bar.js @@ -3,6 +3,7 @@ import { } from '../api/util' import { + publish, requireNativePlugin } from '../bridge' @@ -102,6 +103,9 @@ export default { tabBar && tabBar.onClick(({ index }) => { clickCallback(config.list[index], index, true) }) + tabBar && tabBar.onMidButtonClick(() => { + publish('onTabBarMidButtonTap', {}) + }) }, switchTab (page) { const itemLength = config.list.length -- GitLab