[fix] Text support for 'fontVariant' style

Fix #824
Close #825
This commit is contained in:
Nicolas Gallagher
2018-02-17 17:46:49 -08:00
parent 31db333ba3
commit 6d908189a7
5 changed files with 35 additions and 16 deletions
@@ -22,6 +22,23 @@ describe('StyleSheet/createReactDOMStyle', () => {
expect(firstStyle).toEqual(secondStyle); expect(firstStyle).toEqual(secondStyle);
}); });
test('shortform -> longform', () => {
const style = {
borderStyle: 'solid',
boxSizing: 'border-box',
borderBottomColor: 'white',
borderBottomWidth: 1,
borderWidth: 0,
marginTop: 50,
marginVertical: 25,
margin: 10,
overflow: 'hidden',
overscrollBehavior: 'contain'
};
expect(createReactDOMStyle(style)).toMatchSnapshot();
});
describe('borderWidth styles', () => { describe('borderWidth styles', () => {
test('defaults to 0 when "null"', () => { test('defaults to 0 when "null"', () => {
expect(createReactDOMStyle({ borderWidth: null })).toEqual({ expect(createReactDOMStyle({ borderWidth: null })).toEqual({
@@ -134,21 +151,10 @@ describe('StyleSheet/createReactDOMStyle', () => {
}); });
}); });
test('shortform -> longform', () => { test('fontVariant', () => {
const style = { expect(createReactDOMStyle({ fontVariant: ['common-ligatures', 'small-caps'] })).toEqual({
borderStyle: 'solid', fontVariant: 'common-ligatures small-caps'
boxSizing: 'border-box', });
borderBottomColor: 'white',
borderBottomWidth: 1,
borderWidth: 0,
marginTop: 50,
marginVertical: 25,
margin: 10,
overflow: 'hidden',
overscrollBehavior: 'contain'
};
expect(createReactDOMStyle(style)).toMatchSnapshot();
}); });
describe('shadow styles', () => { describe('shadow styles', () => {
@@ -247,6 +247,13 @@ const createReducer = (style, styleProps) => {
break; break;
} }
case 'fontVariant': {
if (Array.isArray(value) && value.length > 0) {
resolvedStyle.fontVariant = value.join(' ');
}
break;
}
case 'shadowColor': case 'shadowColor':
case 'shadowOffset': case 'shadowOffset':
case 'shadowOpacity': case 'shadowOpacity':
@@ -10,7 +10,7 @@
import ColorPropType from '../ColorPropType'; import ColorPropType from '../ColorPropType';
import ViewStylePropTypes from '../View/ViewStylePropTypes'; import ViewStylePropTypes from '../View/ViewStylePropTypes';
import { number, oneOf, oneOfType, shape, string } from 'prop-types'; import { array, number, oneOf, oneOfType, shape, string } from 'prop-types';
const numberOrString = oneOfType([number, string]); const numberOrString = oneOfType([number, string]);
@@ -35,6 +35,7 @@ const TextStylePropTypes = {
fontSize: numberOrString, fontSize: numberOrString,
fontStyle: string, fontStyle: string,
fontWeight: string, fontWeight: string,
fontVariant: array,
letterSpacing: numberOrString, letterSpacing: numberOrString,
lineHeight: numberOrString, lineHeight: numberOrString,
textAlign: TextAlignPropType, textAlign: TextAlignPropType,
+1
View File
@@ -109,6 +109,7 @@ const styles = StyleSheet.create({
// inherit parent font styles // inherit parent font styles
fontFamily: 'inherit', fontFamily: 'inherit',
fontSize: 'inherit', fontSize: 'inherit',
fontVariant: ['inherit'],
whiteSpace: 'inherit' whiteSpace: 'inherit'
}, },
notSelectable: { notSelectable: {
@@ -196,6 +196,10 @@ const stylePropTypes = [
name: 'fontStyle', name: 'fontStyle',
typeInfo: 'string' typeInfo: 'string'
}, },
{
name: 'fontVariant',
typeInfo: 'Array<string>'
},
{ {
name: 'fontWeight', name: 'fontWeight',
typeInfo: 'string' typeInfo: 'string'