File tree 3 files changed +111
-4
lines changed
3 files changed +111
-4
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ const invariant = require('invariant');
25
25
const processDecelerationRate = require ( './processDecelerationRate' ) ;
26
26
const requireNativeComponent = require ( '../../ReactNative/requireNativeComponent' ) ;
27
27
const resolveAssetSource = require ( '../../Image/resolveAssetSource' ) ;
28
+ const splitLayoutProps = require ( '../../StyleSheet/splitLayoutProps' ) ;
28
29
29
30
import type {
30
31
PressEvent ,
@@ -1125,15 +1126,15 @@ class ScrollView extends React.Component<Props, State> {
1125
1126
// On Android wrap the ScrollView with a AndroidSwipeRefreshLayout.
1126
1127
// Since the ScrollView is wrapped add the style props to the
1127
1128
// AndroidSwipeRefreshLayout and use flex: 1 for the ScrollView.
1128
- // Note: we should only apply props.style on the wrapper
1129
+ // Note: we should split props.style on the inner and outer props
1129
1130
// however, the ScrollView still needs the baseStyle to be scrollable
1130
-
1131
+ const { outer , inner } = splitLayoutProps ( flattenStyle ( props . style ) ) ;
1131
1132
return React . cloneElement (
1132
1133
refreshControl ,
1133
- { style : props . style } ,
1134
+ { style : [ baseStyle , outer ] } ,
1134
1135
< ScrollViewClass
1135
1136
{ ...props }
1136
- style = { baseStyle }
1137
+ style = { [ baseStyle , inner ] }
1137
1138
// $FlowFixMe
1138
1139
ref = { this . _setScrollViewRef } >
1139
1140
{ contentContainer }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its 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
+ * @emails oncall+react_native
9
+ */
10
+
11
+ 'use strict' ;
12
+
13
+ const splitLayoutProps = require ( '../splitLayoutProps' ) ;
14
+
15
+ test ( 'splits style objects' , ( ) => {
16
+ const style = { width : 10 , margin : 20 , padding : 30 } ;
17
+ const { outer, inner} = splitLayoutProps ( style ) ;
18
+ expect ( outer ) . toMatchInlineSnapshot ( `
19
+ Object {
20
+ "margin": 20,
21
+ "width": 10,
22
+ }
23
+ ` ) ;
24
+ expect ( inner ) . toMatchInlineSnapshot ( `
25
+ Object {
26
+ "padding": 30,
27
+ }
28
+ ` ) ;
29
+ } ) ;
30
+
31
+ test ( 'does not copy values to both returned objects' , ( ) => {
32
+ const style = { marginVertical : 5 , paddingHorizontal : 10 } ;
33
+ const { outer, inner} = splitLayoutProps ( style ) ;
34
+ expect ( outer ) . toMatchInlineSnapshot ( `
35
+ Object {
36
+ "marginVertical": 5,
37
+ }
38
+ ` ) ;
39
+ expect ( inner ) . toMatchInlineSnapshot ( `
40
+ Object {
41
+ "paddingHorizontal": 10,
42
+ }
43
+ ` ) ;
44
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its 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
+ * @flow strict-local
9
+ */
10
+
11
+ 'use strict' ;
12
+
13
+ import type { DangerouslyImpreciseStyle } from './StyleSheet' ;
14
+
15
+ const OUTER_PROPS = Object . assign ( Object . create ( null ) , {
16
+ margin : true ,
17
+ marginHorizontal : true ,
18
+ marginVertical : true ,
19
+ marginBottom : true ,
20
+ marginTop : true ,
21
+ marginLeft : true ,
22
+ marginRight : true ,
23
+ flex : true ,
24
+ flexGrow : true ,
25
+ flexShrink : true ,
26
+ flexBasis : true ,
27
+ alignSelf : true ,
28
+ height : true ,
29
+ minHeight : true ,
30
+ maxHeight : true ,
31
+ width : true ,
32
+ minWidth : true ,
33
+ maxWidth : true ,
34
+ position : true ,
35
+ left : true ,
36
+ right : true ,
37
+ bottom : true ,
38
+ top : true ,
39
+ } ) ;
40
+
41
+ function splitLayoutProps (
42
+ props : ?DangerouslyImpreciseStyle ,
43
+ ) : {
44
+ outer: DangerouslyImpreciseStyle ,
45
+ inner : DangerouslyImpreciseStyle ,
46
+ } {
47
+ const inner = { } ;
48
+ const outer = { } ;
49
+ if ( props ) {
50
+ Object . keys ( props ) . forEach ( k => {
51
+ const value : $ElementType < DangerouslyImpreciseStyle , typeof k > = props [ k ] ;
52
+ if ( OUTER_PROPS [ k ] ) {
53
+ outer [ k ] = value ;
54
+ } else {
55
+ inner [ k ] = value ;
56
+ }
57
+ } ) ;
58
+ }
59
+ return { outer, inner} ;
60
+ }
61
+
62
+ module . exports = splitLayoutProps ;
You can’t perform that action at this time.
0 commit comments