Skip to content

Commit

Permalink
feat(uni-app-x mp): safeAreaInset css变量兼容小程序端
Browse files Browse the repository at this point in the history
  • Loading branch information
Wangyaqi committed Jan 21, 2025
1 parent 76c7ac4 commit 6fcc8b6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/uni-mp-vite/src/plugin/configResolved.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {

const debugNVueCss = debug('uni:nvue-css')
const cssVars = `page{--status-bar-height:25px;--top-window-height:0px;--window-top:0px;--window-bottom:0px;--window-left:0px;--window-right:0px;--window-magin:0px}`
const uvueCssVars = `page{--status-bar-height:25px;--top-window-height:0px;--window-top:0px;--window-bottom:0px;--window-left:0px;--window-right:0px;--window-magin:0px;--uni-safe-area-inset-top:0px;--uni-safe-area-inset-left:0px;--uni-safe-area-inset-right:0px;--uni-safe-area-inset-bottom:0px;}`

const genShadowCss = (cdn: number) => {
const url = createShadowImageUrl(cdn, 'grey')
Expand Down Expand Up @@ -96,25 +97,26 @@ export function createConfigResolved({
}
},
chunkCssCode(filename, cssCode) {
const isX = process.env.UNI_APP_X === 'true'
cssCode = transformScopedCss(cssCode)
if (filename === 'app' + cssExtname) {
const componentCustomHiddenCss =
(component &&
component.vShow &&
genComponentCustomHiddenCss(component.vShow)) ||
''
const realCssVars = isX ? uvueCssVars : cssVars
if (config.isProduction) {
return (
cssCode +
genShadowCss(cdn || 0) +
cssVars +
realCssVars +
componentCustomHiddenCss
)
} else {
return cssCode + cssVars + componentCustomHiddenCss
return cssCode + realCssVars + componentCustomHiddenCss
}
}
const isX = process.env.UNI_APP_X === 'true'

if (isX) {
if (component?.[':host']) {
Expand Down

0 comments on commit 6fcc8b6

Please sign in to comment.