Files
react-native/Libraries/StyleSheet/processFontVariant.js
T
Gabriel Donadel Dall'Agnol 09d420707f feat: Add space-separated string support for fontVariant (#34641)
Summary:
This updates `fontVariant` to support space-separated string values, i.e., `'small-caps common-ligatures'`, thus aligning it with the [CSS Fonts Module Level 4](https://drafts.csswg.org/css-fonts/#font-variant-prop) specification as requested on https://github.com/facebook/react-native/issues/34425. This also adds unit tests to the `processFontVariant` function ensuring the style processing works as expected.

## Changelog

[General] [Added] - Add space-separated string support for fontVariant

Pull Request resolved: https://github.com/facebook/react-native/pull/34641

Test Plan:
This can be tested either through `processFontVariant-tests` or by using the following code:

```js
 <Text
   style={{
     fontVariant: 'small-caps common-ligatures',
  }} />
```

Reviewed By: javache

Differential Revision: D39423317

Pulled By: cipolleschi

fbshipit-source-id: ad971addb423ed338e178528a11fe9d456c03e6e
2022-09-14 05:08:10 -07:00

31 lines
676 B
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
import type {____FontVariantArray_Internal} from './StyleSheetTypes';
function processFontVariant(
fontVariant: ____FontVariantArray_Internal | string,
): ?____FontVariantArray_Internal {
if (Array.isArray(fontVariant)) {
return fontVariant;
}
// $FlowFixMe[incompatible-type]
const match: ?____FontVariantArray_Internal = fontVariant
.split(' ')
.filter(Boolean);
return match;
}
module.exports = processFontVariant;