Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vue-next): fix beforeLoadStyle not work #4003

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/hippy-vue-next-demo/src/main-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ const app: HippyApp = createApp(App, {
* default is true, if set false, it will follow vue-loader compilerOptions whitespace setting
*/
trimWhitespace: true,
styleOptions: {
beforeLoadStyle: (decl) => {
let { value } = decl;
// 比如可以对 rem 单位进行处理
if (typeof value === 'string' && /rem$/.test(value)) {
// get the numeric value of rem

const { screen } = Native.Dimensions;
// 比如可以对 rem 单位进行处理
if (typeof value === 'string' && /rem$/.test(value)) {
const { width, height } = screen;
// 防止hippy 旋转后,宽度发生变化
const realWidth = width > height ? width : height;
value = Number(parseFloat(`${(realWidth * 100 * Number(value.replace('rem', ''))) / 844}`).toFixed(2));
}
}
return { ...decl, value };
},
},
});
// create router
const router = createRouter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function getCssMap(
* Here is a secret startup option: beforeStyleLoadHook.
* Usage for process the styles while styles loading.
*/
const cssRules = fromAstNodes(styleCssMap);
const cssRules = fromAstNodes(styleCssMap, beforeLoadStyle);
if (globalCssMap) {
globalCssMap.append(cssRules);
} else {
Expand Down
Loading