File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
examples/hippy-vue-next-demo/src
packages/hippy-vue-next-style-parser/src/style-match Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 44 EventBus ,
55 setScreenSize ,
66 BackAndroid ,
7+ Native ,
78} from '@hippy/vue-next' ;
89
910import 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' && / r e m $ / . test ( value ) ) {
54+ // get the numeric value of rem
55+
56+ const { screen } = Native . Dimensions ;
57+ // 比如可以对 rem 单位进行处理
58+ if ( typeof value === 'string' && / r e m $ / . 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
5070const router = createRouter ( ) ;
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments