diff --git a/packages/taro-jd/src/apis.ts b/packages/taro-jd/src/apis.ts index ef08b53caf26..ee88bdab9b7b 100644 --- a/packages/taro-jd/src/apis.ts +++ b/packages/taro-jd/src/apis.ts @@ -4,4 +4,10 @@ declare const jd: any export function initNativeApi (taro) { processApis(taro, jd) + + taro.getTabBar = function (pageCtx) { + if (typeof pageCtx?.getTabBar === 'function') { + return pageCtx.getTabBar()?.$taroInstances + } + } } diff --git a/packages/taro-mini-runner/src/__tests__/__snapshots__/jd.spec.ts.snap b/packages/taro-mini-runner/src/__tests__/__snapshots__/jd.spec.ts.snap index 68831450edef..9306bb7e1209 100644 --- a/packages/taro-mini-runner/src/__tests__/__snapshots__/jd.spec.ts.snap +++ b/packages/taro-mini-runner/src/__tests__/__snapshots__/jd.spec.ts.snap @@ -58,6 +58,12 @@ require("./taro"); function useScope() {} function initNativeApi(taro) { processApis(taro, jd); + taro.getTabBar = function(pageCtx) { + var _a; + if (typeof (pageCtx === null || pageCtx === void 0 ? void 0 : pageCtx.getTabBar) === "function") { + return (_a = pageCtx.getTabBar()) === null || _a === void 0 ? void 0 : _a.$taroInstances; + } + }; } var components = { Swiper: { diff --git a/packages/taro-webpack5-runner/src/__tests__/__snapshots__/mini-platform.spec.ts.snap b/packages/taro-webpack5-runner/src/__tests__/__snapshots__/mini-platform.spec.ts.snap index e83ec49f0522..8b4bd3ef5c41 100644 --- a/packages/taro-webpack5-runner/src/__tests__/__snapshots__/mini-platform.spec.ts.snap +++ b/packages/taro-webpack5-runner/src/__tests__/__snapshots__/mini-platform.spec.ts.snap @@ -2839,6 +2839,12 @@ require("./runtime"); var taro_shared = "taro-shared-mock"; function initNativeApi(taro) { processApis(taro, jd); + taro.getTabBar = function(pageCtx) { + var _a; + if (typeof (pageCtx === null || pageCtx === void 0 ? void 0 : pageCtx.getTabBar) === "function") { + return (_a = pageCtx.getTabBar()) === null || _a === void 0 ? void 0 : _a.$taroInstances; + } + }; } var components = { Swiper: { diff --git a/packages/taro/types/api/taro.extend.d.ts b/packages/taro/types/api/taro.extend.d.ts index 899a4bd52f92..dcdc9dcda561 100644 --- a/packages/taro/types/api/taro.extend.d.ts +++ b/packages/taro/types/api/taro.extend.d.ts @@ -130,7 +130,7 @@ declare module '../index' { setGlobalDataPlugin: setGlobalDataPlugin.Plugin /** 获取自定义 TabBar 对应的 React 或 Vue 组件实例 - * @supported weapp + * @supported weapp, jd * @param page 小程序页面对象,可以通过 Taro.getCurrentInstance().page 获取 */ getTabBar(page: getCurrentInstance.Current['page']): T | undefined