diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index a069a24c733..0015a9daabf 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -1138,7 +1138,7 @@ class ScrollView extends React.Component { ...this.props, alwaysBounceHorizontal, alwaysBounceVertical, - style: [baseStyle, this.props.style], + style: StyleSheet.compose(baseStyle, this.props.style), // Override the onContentSizeChange from props, since this event can // bubble up from TextInputs onContentSizeChange: null, @@ -1224,10 +1224,10 @@ class ScrollView extends React.Component { const {outer, inner} = splitLayoutProps(flattenStyle(props.style)); return React.cloneElement( refreshControl, - {style: [baseStyle, outer]}, + {style: StyleSheet.compose(baseStyle, outer)}, {contentContainer} , diff --git a/Libraries/Components/ScrollView/__tests__/__snapshots__/ScrollView-test.js.snap b/Libraries/Components/ScrollView/__tests__/__snapshots__/ScrollView-test.js.snap index 1afba0ee035..de40fd6e028 100644 --- a/Libraries/Components/ScrollView/__tests__/__snapshots__/ScrollView-test.js.snap +++ b/Libraries/Components/ScrollView/__tests__/__snapshots__/ScrollView-test.js.snap @@ -40,15 +40,12 @@ exports[` should render as expected: should deep render when not m snapToEnd={true} snapToStart={true} style={ - Array [ - Object { - "flexDirection": "column", - "flexGrow": 1, - "flexShrink": 1, - "overflow": "scroll", - }, - undefined, - ] + Object { + "flexDirection": "column", + "flexGrow": 1, + "flexShrink": 1, + "overflow": "scroll", + } } > { const style = {width: 10, margin: 20, padding: 30, transform: {scaleY: -1}}; @@ -45,3 +45,9 @@ test('does not copy values to both returned objects', () => { } `); }); + +test('returns null values if argument is null', () => { + const {outer, inner} = splitLayoutProps(null); + expect(outer).toBe(null); + expect(inner).toBe(null); +}); diff --git a/Libraries/StyleSheet/splitLayoutProps.js b/Libraries/StyleSheet/splitLayoutProps.js index 2c6fd33f87e..03bb726001e 100644 --- a/Libraries/StyleSheet/splitLayoutProps.js +++ b/Libraries/StyleSheet/splitLayoutProps.js @@ -4,61 +4,65 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format * @flow strict-local + * @format */ 'use strict'; -import type {DangerouslyImpreciseStyle} from './StyleSheet'; +import type {____ViewStyle_Internal} from './StyleSheetTypes'; -const OUTER_PROPS = Object.assign(Object.create(null), { - margin: true, - marginHorizontal: true, - marginVertical: true, - marginBottom: true, - marginTop: true, - marginLeft: true, - marginRight: true, - flex: true, - flexGrow: true, - flexShrink: true, - flexBasis: true, - alignSelf: true, - height: true, - minHeight: true, - maxHeight: true, - width: true, - minWidth: true, - maxWidth: true, - position: true, - left: true, - right: true, - bottom: true, - top: true, - transform: true, -}); - -function splitLayoutProps( - props: ?DangerouslyImpreciseStyle, +export default function splitLayoutProps( + props: ?____ViewStyle_Internal, ): { - outer: DangerouslyImpreciseStyle, - inner: DangerouslyImpreciseStyle, - ... + outer: ?____ViewStyle_Internal, + inner: ?____ViewStyle_Internal, } { - const inner = {}; - const outer = {}; - if (props) { - Object.keys(props).forEach((k: string) => { - const value = props[k]; - if (OUTER_PROPS[k]) { - outer[k] = value; - } else { - inner[k] = value; + let outer: ?____ViewStyle_Internal = null; + let inner: ?____ViewStyle_Internal = null; + + if (props != null) { + // $FlowIgnore[incompatible-exact] Will contain a subset of keys from `props`. + // $FlowIgnore[incompatible-type] Values are preserved within a key. + outer = {}; + // $FlowIgnore[incompatible-exact] Will contain a subset of keys from `props`. + // $FlowIgnore[incompatible-type] Values are preserved within a key. + inner = {}; + + for (const prop of Object.keys(props)) { + switch (prop) { + case 'margin': + case 'marginHorizontal': + case 'marginVertical': + case 'marginBottom': + case 'marginTop': + case 'marginLeft': + case 'marginRight': + case 'flex': + case 'flexGrow': + case 'flexShrink': + case 'flexBasis': + case 'alignSelf': + case 'height': + case 'minHeight': + case 'maxHeight': + case 'width': + case 'minWidth': + case 'maxWidth': + case 'position': + case 'left': + case 'right': + case 'bottom': + case 'top': + case 'transform': + outer[prop] = props[prop]; + break; + default: + inner[prop] = props[prop]; + break; } - }); + } } + return {outer, inner}; } - -module.exports = splitLayoutProps;