Skip to content

Commit 35c8d23

Browse files
committed
fix(vue-next): fix beforeLoadStyle not work
1 parent fa6dead commit 35c8d23

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

driver/js/examples/hippy-vue-next-demo/src/main-native.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
EventBus,
55
setScreenSize,
66
BackAndroid,
7+
Native,
78
} from '@hippy/vue-next';
89

910
import App from './app.vue';
@@ -45,6 +46,25 @@ const app: HippyApp = createApp(App, {
4546
* default is true, if set false, it will follow vue-loader compilerOptions whitespace setting
4647
*/
4748
trimWhitespace: true,
49+
styleOptions: {
50+
beforeLoadStyle: (decl) => {
51+
let { value } = decl;
52+
// 比如可以对 rem 单位进行处理
53+
if (typeof value === 'string' && /rem$/.test(value)) {
54+
// get the numeric value of rem
55+
56+
const { screen } = Native.Dimensions;
57+
// 比如可以对 rem 单位进行处理
58+
if (typeof value === 'string' && /rem$/.test(value)) {
59+
const { width, height } = screen;
60+
// 防止hippy 旋转后,宽度发生变化
61+
const realWidth = width > height ? width : height;
62+
value = Number(parseFloat(`${(realWidth * 100 * Number(value.replace('rem', ''))) / 844}`).toFixed(2));
63+
}
64+
}
65+
return { ...decl, value };
66+
},
67+
},
4868
});
4969
// create router
5070
const router = createRouter();

driver/js/packages/hippy-vue-next-style-parser/src/style-match/css-map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export function getCssMap(
220220
* Here is a secret startup option: beforeStyleLoadHook.
221221
* Usage for process the styles while styles loading.
222222
*/
223-
const cssRules = fromAstNodes(styleCssMap);
223+
const cssRules = fromAstNodes(styleCssMap, beforeLoadStyle);
224224
if (globalCssMap) {
225225
globalCssMap.append(cssRules);
226226
} else {

0 commit comments

Comments
 (0)