From f992e2ff4f3e52926707e7c877a5b30e59184252 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 25 May 2021 18:29:07 +0800 Subject: [PATCH] fix(h5): useMaxWidth --- packages/uni-h5/dist/uni-h5.cjs.js | 2 +- packages/uni-h5/dist/uni-h5.es.js | 22 ++++++++++++------- .../src/framework/components/layout/index.tsx | 22 +++++++++---------- packages/uni-h5/src/service/api/ui/window.ts | 18 ++++++++++----- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index 6a6ac7fbe..c84bc166c 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -10569,7 +10569,7 @@ var LayoutComponent = /* @__PURE__ */ defineSystemComponent({ layoutState, windowState } = __UNI_FEATURE_RESPONSIVE__ ? useState() : {}; - useMaxWidth(layoutState, rootRef); + layoutState && useMaxWidth(layoutState, rootRef); const topWindow = __UNI_FEATURE_TOPWINDOW__ && useTopWindow(layoutState); const leftWindow = __UNI_FEATURE_LEFTWINDOW__ && useLeftWindow(layoutState); const rightWindow = __UNI_FEATURE_RIGHTWINDOW__ && useRightWindow(layoutState); diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index fe3d780b3..32b036619 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -18042,7 +18042,7 @@ function createTabBarMidButtonTsx(color, iconPath, midButton, tabBar2, index2, o }, null, 12, ["src"])], 4), createTabBarItemBdTsx(color, iconPath, midButton, tabBar2)], 12, ["onClick"]); } const DEFAULT_CSS_VAR_VALUE = "0px"; -let globalLayoutState; +let globalLayoutState = void 0; function getLayoutState() { return globalLayoutState; } @@ -18058,7 +18058,7 @@ var LayoutComponent = /* @__PURE__ */ defineSystemComponent({ layoutState, windowState } = __UNI_FEATURE_RESPONSIVE__ ? useState() : {}; - useMaxWidth(layoutState, rootRef); + layoutState && useMaxWidth(layoutState, rootRef); const topWindow = __UNI_FEATURE_TOPWINDOW__ && useTopWindow(layoutState); const leftWindow = __UNI_FEATURE_LEFTWINDOW__ && useLeftWindow(layoutState); const rightWindow = __UNI_FEATURE_RIGHTWINDOW__ && useRightWindow(layoutState); @@ -18442,27 +18442,33 @@ const hideRightWindow = /* @__PURE__ */ defineAsyncApi("hideRightWindow", (_, {r }); const getTopWindowStyle = /* @__PURE__ */ defineSyncApi("getTopWindowStyle", () => { const state2 = getLayoutState(); - return Object.assign({}, state2.topWindowStyle); + return Object.assign({}, state2 && state2.topWindowStyle); }); const setTopWindowStyle = /* @__PURE__ */ defineSyncApi("setTopWindowStyle", (style) => { const state2 = getLayoutState(); - state2.topWindowStyle = style; + if (state2) { + state2.topWindowStyle = style; + } }); const getLeftWindowStyle = /* @__PURE__ */ defineSyncApi("getLeftWindowStyle", () => { const state2 = getLayoutState(); - return Object.assign({}, state2.leftWindowStyle); + return Object.assign({}, state2 && state2.leftWindowStyle); }); const setLeftWindowStyle = /* @__PURE__ */ defineSyncApi("setLeftWindowStyle", (style) => { const state2 = getLayoutState(); - state2.leftWindowStyle = style; + if (state2) { + state2.leftWindowStyle = style; + } }); const getRightWindowStyle = /* @__PURE__ */ defineSyncApi("getRightWindowStyle", () => { const state2 = getLayoutState(); - return Object.assign({}, state2.rightWindowStyle); + return Object.assign({}, state2 && state2.rightWindowStyle); }); const setRightWindowStyle = /* @__PURE__ */ defineSyncApi("setRightWindowStyle", (style) => { const state2 = getLayoutState(); - state2.rightWindowStyle = style; + if (state2) { + state2.rightWindowStyle = style; + } }); var api = /* @__PURE__ */ Object.freeze({ __proto__: null, diff --git a/packages/uni-h5/src/framework/components/layout/index.tsx b/packages/uni-h5/src/framework/components/layout/index.tsx index 2e3518868..fdff204ed 100644 --- a/packages/uni-h5/src/framework/components/layout/index.tsx +++ b/packages/uni-h5/src/framework/components/layout/index.tsx @@ -35,7 +35,7 @@ type KeepAliveRoute = ReturnType const DEFAULT_CSS_VAR_VALUE = '0px' -let globalLayoutState: LayoutState +let globalLayoutState: LayoutState | undefined = undefined export function getLayoutState() { return globalLayoutState } @@ -49,12 +49,12 @@ export default /*#__PURE__*/ defineSystemComponent({ useKeepAliveRoute()) as KeepAliveRoute const { layoutState, windowState } = __UNI_FEATURE_RESPONSIVE__ ? useState() - : ({} as ReturnType) - useMaxWidth(layoutState, rootRef) - const topWindow = __UNI_FEATURE_TOPWINDOW__ && useTopWindow(layoutState) - const leftWindow = __UNI_FEATURE_LEFTWINDOW__ && useLeftWindow(layoutState) + : ({} as { layoutState: undefined; windowState: undefined }) + layoutState && useMaxWidth(layoutState, rootRef) + const topWindow = __UNI_FEATURE_TOPWINDOW__ && useTopWindow(layoutState!) + const leftWindow = __UNI_FEATURE_LEFTWINDOW__ && useLeftWindow(layoutState!) const rightWindow = - __UNI_FEATURE_RIGHTWINDOW__ && useRightWindow(layoutState) + __UNI_FEATURE_RIGHTWINDOW__ && useRightWindow(layoutState!) const showTabBar = (__UNI_FEATURE_TABBAR__ && useShowTabBar(emit)) as ComputedRef const clazz = useAppClass(showTabBar) @@ -269,8 +269,8 @@ function useState() { function createLayoutTsx( keepAliveRoute: KeepAliveRoute, - layoutState: LayoutState, - windowState: WindowState, + layoutState?: LayoutState, + windowState?: WindowState, topWindow?: unknown, leftWindow?: unknown, rightWindow?: unknown @@ -283,13 +283,13 @@ function createLayoutTsx( return routerVNode } const topWindowTsx = __UNI_FEATURE_TOPWINDOW__ - ? createTopWindowTsx(topWindow, layoutState, windowState) + ? createTopWindowTsx(topWindow, layoutState!, windowState!) : null const leftWindowTsx = __UNI_FEATURE_LEFTWINDOW__ - ? createLeftWindowTsx(leftWindow, layoutState, windowState) + ? createLeftWindowTsx(leftWindow, layoutState!, windowState!) : null const rightWindowTsx = __UNI_FEATURE_RIGHTWINDOW__ - ? createRightWindowTsx(rightWindow, layoutState, windowState) + ? createRightWindowTsx(rightWindow, layoutState!, windowState!) : null return ( diff --git a/packages/uni-h5/src/service/api/ui/window.ts b/packages/uni-h5/src/service/api/ui/window.ts index 36518fdc3..52fc9ff4a 100644 --- a/packages/uni-h5/src/service/api/ui/window.ts +++ b/packages/uni-h5/src/service/api/ui/window.ts @@ -137,41 +137,47 @@ export const hideRightWindow = ( export const getTopWindowStyle = ( defineSyncApi('getTopWindowStyle', () => { const state = getLayoutState() - return Object.assign({}, state.topWindowStyle) + return Object.assign({}, state && state.topWindowStyle) }) ) export const setTopWindowStyle = ( defineSyncApi('setTopWindowStyle', (style) => { const state = getLayoutState() - state.topWindowStyle = style + if (state) { + state.topWindowStyle = style + } }) ) export const getLeftWindowStyle = ( defineSyncApi('getLeftWindowStyle', () => { const state = getLayoutState() - return Object.assign({}, state.leftWindowStyle) + return Object.assign({}, state && state.leftWindowStyle) }) ) export const setLeftWindowStyle = ( defineSyncApi('setLeftWindowStyle', (style) => { const state = getLayoutState() - state.leftWindowStyle = style + if (state) { + state.leftWindowStyle = style + } }) ) export const getRightWindowStyle = ( defineSyncApi('getRightWindowStyle', () => { const state = getLayoutState() - return Object.assign({}, state.rightWindowStyle) + return Object.assign({}, state && state.rightWindowStyle) }) ) export const setRightWindowStyle = ( defineSyncApi('setRightWindowStyle', (style) => { const state = getLayoutState() - state.rightWindowStyle = style + if (state) { + state.rightWindowStyle = style + } }) ) -- GitLab