Skip to content

Commit

Permalink
fix(rn): 忽略 scalePx2d 导致的 Invalid prop fontSize of type string 的警告
Browse files Browse the repository at this point in the history
  • Loading branch information
Pines-Cheng committed Jun 2, 2019
1 parent b4903e8 commit bebacd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/taro-cli/src/rn/styleProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import chalk from 'chalk'
import * as pxtransform from 'postcss-pxtransform'
import transformCSS from 'taro-css-to-react-native'

import {StyleSheetValidation} from './StyleSheet/index'
import { StyleSheetValidation } from './StyleSheet/index'
import * as Util from '../util'
import * as npmProcess from '../util/npm'
import {FILE_PROCESSOR_MAP, processTypeEnum} from '../util/constants'
import { FILE_PROCESSOR_MAP, processTypeEnum } from '../util/constants'

import * as stylelintConfig from '../config/rn-stylelint.json'

Expand All @@ -30,15 +30,14 @@ export default StyleSheet.create(${css})
`)
}


/**
* @description 读取 css/scss/less 文件,预处理后,返回 css string
* @param {string} filePath
* @param {object} pluginsConfig
* @param {string} appPath
* @returns {*}
*/
function loadStyle({filePath, pluginsConfig}, appPath) {
function loadStyle ({filePath, pluginsConfig}, appPath) {
const fileExt = path.extname(filePath)
const pluginName = FILE_PROCESSOR_MAP[fileExt]
if (pluginName) {
Expand Down Expand Up @@ -73,7 +72,7 @@ function loadStyle({filePath, pluginsConfig}, appPath) {
* @param {object} projectConfig
* @returns {Function | any}
*/
function postCSS({css, filePath, projectConfig}) {
function postCSS ({css, filePath, projectConfig}) {
const pxTransformConfig = {
designWidth: projectConfig.designWidth || 750
}
Expand Down Expand Up @@ -102,7 +101,7 @@ function postCSS({css, filePath, projectConfig}) {
})
}

function getStyleObject({css, filePath}) {
function getStyleObject ({css, filePath}) {
let styleObject = {}
try {
styleObject = transformCSS(css)
Expand All @@ -113,18 +112,21 @@ function getStyleObject({css, filePath}) {
return styleObject
}

function validateStyle({styleObject, filePath}) {
function validateStyle ({styleObject, filePath}) {
for (const name in styleObject) {
try {
StyleSheetValidation.validateStyle(name, styleObject)
} catch (err) {
Util.printLog(processTypeEnum.WARNING, '样式不支持', filePath)
console.log(chalk.red(err.message))
// 先忽略掉 fontSize 的报错
if (err.message.indexOf(`"fontSize": "scalePx2dp`) === -1) {
console.log(chalk.red(err.message))
}
}
}
}

function writeStyleFile({css, tempFilePath}) {
function writeStyleFile ({css, tempFilePath}) {
const fileContent = getWrapedCSS(css.replace(/"(scalePx2dp\(.*?\))"/g, '$1'))
fs.ensureDirSync(path.dirname(tempFilePath))
fs.writeFileSync(tempFilePath, fileContent)
Expand Down
1 change: 1 addition & 0 deletions packages/taro-rn/src/api/interface/showModal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react'
import { Text } from 'react-native'
import RootSiblings from 'react-native-root-siblings'
import Dialog from '../Dialog'
Expand Down

0 comments on commit bebacd9

Please sign in to comment.