Skip to content

Commit cc1bcbc

Browse files
committed
Process font variation settings in native view configs
1 parent 714911b commit cc1bcbc

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
jest.mock('../UIManager', () => ({
13+
__esModule: true,
14+
default: {
15+
getConstants: () => ({ViewManagerNames: []}),
16+
getDefaultEventTypes: () => ({}),
17+
getViewManagerConfig: name =>
18+
name === 'TestView'
19+
? {
20+
NativeProps: {fontVariationSettings: 'String'},
21+
bubblingEventTypes: {},
22+
directEventTypes: {},
23+
}
24+
: null,
25+
},
26+
}));
27+
28+
const getNativeComponentAttributes =
29+
require('../getNativeComponentAttributes').default;
30+
const {
31+
fontVariationSettingsAttribute,
32+
} = require('../../Components/View/ReactNativeStyleAttributes');
33+
34+
describe('getNativeComponentAttributes', () => {
35+
it('processes object font variation settings from native view configs', () => {
36+
const viewConfig = getNativeComponentAttributes('TestView');
37+
38+
expect(viewConfig.validAttributes.fontVariationSettings).toEqual(
39+
fontVariationSettingsAttribute,
40+
);
41+
expect(
42+
viewConfig.validAttributes.fontVariationSettings.process({
43+
wght: 552.5,
44+
opsz: 17.25,
45+
}),
46+
).toBe("'opsz' 17.25, 'wght' 552.5");
47+
});
48+
});

packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const processBackgroundSize =
2626
const processColor = require('../StyleSheet/processColor').default;
2727
const processColorArray = require('../StyleSheet/processColorArray').default;
2828
const processFilter = require('../StyleSheet/processFilter').default;
29+
const processFontVariationSettings =
30+
require('../StyleSheet/processFontVariationSettings').default;
2931
const insetsDiffer = require('../Utilities/differ/insetsDiffer').default;
3032
const matricesDiffer = require('../Utilities/differ/matricesDiffer').default;
3133
const pointsDiffer = require('../Utilities/differ/pointsDiffer').default;
@@ -74,7 +76,7 @@ function getNativeComponentAttributes(uiViewClassName: string): any {
7476
for (const key in nativeProps) {
7577
const typeName = nativeProps[key];
7678
const diff = getDifferForType(typeName);
77-
const process = getProcessorForType(typeName);
79+
const process = getProcessorForAttribute(key, typeName);
7880

7981
// If diff or process == null, omit the corresponding property from the Attribute
8082
// Why:
@@ -183,7 +185,14 @@ function getDifferForType(
183185
return null;
184186
}
185187

186-
function getProcessorForType(typeName: string): ?(nextProp: any) => any {
188+
function getProcessorForAttribute(
189+
attributeName: string,
190+
typeName: string,
191+
): ?(nextProp: any) => any {
192+
if (attributeName === 'fontVariationSettings') {
193+
return processFontVariationSettings;
194+
}
195+
187196
switch (typeName) {
188197
// iOS Types
189198
case 'CGColor':

0 commit comments

Comments
 (0)