From 85aaa39206aedd90b6c2a282132b0b73fa553022 Mon Sep 17 00:00:00 2001 From: Liron Yahdav Date: Sat, 30 Dec 2017 14:18:55 -0800 Subject: [PATCH] [fix] i18n of styles when using 'setNativeProps' Close #732 --- .../react-native-web/src/components/View/index.js | 2 +- .../src/modules/NativeMethodsMixin/index.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/react-native-web/src/components/View/index.js b/packages/react-native-web/src/components/View/index.js index decc0ebe..657b0d0b 100644 --- a/packages/react-native-web/src/components/View/index.js +++ b/packages/react-native-web/src/components/View/index.js @@ -65,7 +65,7 @@ class View extends Component { if (hitSlop) { const hitSlopStyle = calculateHitSlopStyle(hitSlop); const hitSlopChild = createElement('span', { style: [styles.hitSlop, hitSlopStyle] }); - otherProps.children = React.Children.toArray([ hitSlopChild, otherProps.children ]); + otherProps.children = React.Children.toArray([hitSlopChild, otherProps.children]); } return createElement('div', otherProps); diff --git a/packages/react-native-web/src/modules/NativeMethodsMixin/index.js b/packages/react-native-web/src/modules/NativeMethodsMixin/index.js index 243b21d9..6b500e56 100644 --- a/packages/react-native-web/src/modules/NativeMethodsMixin/index.js +++ b/packages/react-native-web/src/modules/NativeMethodsMixin/index.js @@ -102,6 +102,10 @@ const NativeMethodsMixin = { * the initial styles from the DOM node and merge them with incoming props. */ setNativeProps(nativeProps: Object) { + if (!nativeProps) { + return; + } + // Copy of existing DOM state const node = findNodeHandle(this); const nodeStyle = node.style; @@ -117,10 +121,14 @@ const NativeMethodsMixin = { style[toCamelCase(property)] = nodeStyle.getPropertyValue(property); } } - const domStyleProps = { classList, style }; + const domStyleProps = { classList, style }; + const props = { + ...nativeProps, + style: i18nStyle(nativeProps.style) + }; // Next DOM state - const domProps = createDOMProps(null, i18nStyle(nativeProps), style => + const domProps = createDOMProps(null, props, style => StyleRegistry.resolveStateful(style, domStyleProps, { i18n: false }) ); UIManager.updateView(node, domProps, this);