mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-28 20:34:52 +08:00
24
src/apis/StyleSheet/__tests__/processTextShadow-test.js
Normal file
24
src/apis/StyleSheet/__tests__/processTextShadow-test.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
import assert from 'assert'
|
||||
import processTextShadow from '../processTextShadow'
|
||||
|
||||
suite('apis/StyleSheet/processTextShadow', () => {
|
||||
test('textShadowOffset', () => {
|
||||
const style = {
|
||||
textShadowColor: 'red',
|
||||
textShadowOffset: { width: 2, height: 2 },
|
||||
textShadowRadius: 5
|
||||
}
|
||||
|
||||
assert.deepEqual(
|
||||
processTextShadow(style),
|
||||
{
|
||||
textShadow: '2px 2px 5px red',
|
||||
textShadowColor: null,
|
||||
textShadowOffset: null,
|
||||
textShadowRadius: null
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -26,7 +26,10 @@ suite('apis/StyleSheet/processTransform', () => {
|
||||
|
||||
assert.deepEqual(
|
||||
processTransform(style),
|
||||
{ transform: 'matrix3d(1,2,3,4,5,6)' }
|
||||
{
|
||||
transform: 'matrix3d(1,2,3,4,5,6)',
|
||||
transformMatrix: null
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
17
src/apis/StyleSheet/__tests__/processVendorPrefixes-test.js
Normal file
17
src/apis/StyleSheet/__tests__/processVendorPrefixes-test.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/* eslint-env mocha */
|
||||
|
||||
import assert from 'assert'
|
||||
import processVendorPrefixes from '../processVendorPrefixes'
|
||||
|
||||
suite('apis/StyleSheet/processVendorPrefixes', () => {
|
||||
test('handles array values', () => {
|
||||
const style = {
|
||||
display: [ '-webkit-flex', 'flex' ]
|
||||
}
|
||||
|
||||
assert.deepEqual(
|
||||
processVendorPrefixes(style),
|
||||
{ display: 'flex' }
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -1,22 +1,18 @@
|
||||
import expandStyle from './expandStyle'
|
||||
import flattenStyle from '../../modules/flattenStyle'
|
||||
import prefixAll from 'inline-style-prefixer/static'
|
||||
import processTextShadow from './processTextShadow'
|
||||
import processTransform from './processTransform'
|
||||
import processVendorPrefixes from './processVendorPrefixes'
|
||||
|
||||
const addVendorPrefixes = (style) => {
|
||||
let prefixedStyles = prefixAll(style)
|
||||
// React@15 removed undocumented support for fallback values in
|
||||
// inline-styles. Revert array values to the standard CSS value
|
||||
for (const prop in prefixedStyles) {
|
||||
const value = prefixedStyles[prop]
|
||||
if (Array.isArray(value)) {
|
||||
prefixedStyles[prop] = value[value.length - 1]
|
||||
}
|
||||
}
|
||||
return prefixedStyles
|
||||
}
|
||||
const plugins = [
|
||||
processTextShadow,
|
||||
processTransform,
|
||||
processVendorPrefixes
|
||||
]
|
||||
|
||||
const _createReactDOMStyleObject = (reactNativeStyle) => processTransform(expandStyle(flattenStyle(reactNativeStyle)))
|
||||
const createReactDOMStyleObject = (reactNativeStyle) => addVendorPrefixes(_createReactDOMStyleObject(reactNativeStyle))
|
||||
const applyPlugins = (style) => plugins.reduce((style, plugin) => plugin(style), style)
|
||||
|
||||
const createReactDOMStyleObject = (reactNativeStyle) => applyPlugins(expandStyle(flattenStyle(reactNativeStyle)))
|
||||
|
||||
module.exports = createReactDOMStyleObject
|
||||
|
||||
19
src/apis/StyleSheet/processTextShadow.js
Normal file
19
src/apis/StyleSheet/processTextShadow.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import normalizeValue from './normalizeValue'
|
||||
|
||||
const processTextShadow = (style) => {
|
||||
if (style && style.textShadowOffset) {
|
||||
const { height, width } = style.textShadowOffset
|
||||
const offsetX = normalizeValue(null, height || 0)
|
||||
const offsetY = normalizeValue(null, width || 0)
|
||||
const blurRadius = normalizeValue(null, style.textShadowRadius || 0)
|
||||
const color = style.textShadowColor || 'currentcolor'
|
||||
|
||||
style.textShadow = `${offsetX} ${offsetY} ${blurRadius} ${color}`
|
||||
style.textShadowColor = null
|
||||
style.textShadowOffset = null
|
||||
style.textShadowRadius = null
|
||||
}
|
||||
return style
|
||||
}
|
||||
|
||||
module.exports = processTextShadow
|
||||
@@ -20,7 +20,7 @@ const processTransform = (style) => {
|
||||
style.transform = style.transform.map(mapTransform).join(' ')
|
||||
} else if (style.transformMatrix) {
|
||||
style.transform = convertTransformMatrix(style.transformMatrix)
|
||||
delete style.transformMatrix
|
||||
style.transformMatrix = null
|
||||
}
|
||||
}
|
||||
return style
|
||||
|
||||
16
src/apis/StyleSheet/processVendorPrefixes.js
Normal file
16
src/apis/StyleSheet/processVendorPrefixes.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import prefixAll from 'inline-style-prefixer/static'
|
||||
|
||||
const processVendorPrefixes = (style) => {
|
||||
let prefixedStyles = prefixAll(style)
|
||||
// React@15 removed undocumented support for fallback values in
|
||||
// inline-styles. Revert array values to the standard CSS value
|
||||
for (const prop in prefixedStyles) {
|
||||
const value = prefixedStyles[prop]
|
||||
if (Array.isArray(value)) {
|
||||
prefixedStyles[prop] = value[value.length - 1]
|
||||
}
|
||||
}
|
||||
return prefixedStyles
|
||||
}
|
||||
|
||||
module.exports = processVendorPrefixes
|
||||
@@ -2,7 +2,7 @@ import { PropTypes } from 'react'
|
||||
import ColorPropType from '../../propTypes/ColorPropType'
|
||||
import ViewStylePropTypes from '../View/ViewStylePropTypes'
|
||||
|
||||
const { number, oneOf, oneOfType, string } = PropTypes
|
||||
const { number, oneOf, oneOfType, shape, string } = PropTypes
|
||||
const numberOrString = oneOfType([ number, string ])
|
||||
|
||||
module.exports = {
|
||||
@@ -19,8 +19,9 @@ module.exports = {
|
||||
textDecorationLine: string,
|
||||
/* @platform web */
|
||||
textOverflow: string,
|
||||
/* @platform web */
|
||||
textShadow: string,
|
||||
textShadowColor: ColorPropType,
|
||||
textShadowOffset: shape({ width: number, height: number }),
|
||||
textShadowRadius: number,
|
||||
/* @platform web */
|
||||
textTransform: oneOf([ 'capitalize', 'lowercase', 'none', 'uppercase' ]),
|
||||
/* @platform web */
|
||||
|
||||
@@ -31,6 +31,7 @@ module.exports = {
|
||||
outline: string,
|
||||
overflowX: autoOrHiddenOrVisible,
|
||||
overflowY: autoOrHiddenOrVisible,
|
||||
transition: string,
|
||||
userSelect: string,
|
||||
visibility: hiddenOrVisible,
|
||||
zIndex: number
|
||||
|
||||
Reference in New Issue
Block a user