Skip to content

Commit 00c7cf3

Browse files
Nizariuskelset
authored andcommittedJun 7, 2019
Fix: RefreshControl in FlatList makes borderWidth not working (#24411)
Summary: Fixes #22752 On line 1021 you are passing base style to props: `style: [baseStyle, this.props.style],` Explicitly passing base style to ScrollView just overrides this line and doesn't let developers to customise style of any inheritors of ScrollView (not only FlatList) with custom RefreshControl. So this line (1113) seems to be removed. ## Changelog [GENERAL] [Fixed] - fix of Android's bug that doesn't let override ScrollView's Style with custom RefreshControl. Pull Request resolved: #24411 Differential Revision: D15713061 Pulled By: cpojer fbshipit-source-id: 461259800f867af15e53e0743a5057ea4528ae69
1 parent a916dd6 commit 00c7cf3

File tree

3 files changed

+111
-4
lines changed

3 files changed

+111
-4
lines changed
 

‎Libraries/Components/ScrollView/ScrollView.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const invariant = require('invariant');
2525
const processDecelerationRate = require('./processDecelerationRate');
2626
const requireNativeComponent = require('../../ReactNative/requireNativeComponent');
2727
const resolveAssetSource = require('../../Image/resolveAssetSource');
28+
const splitLayoutProps = require('../../StyleSheet/splitLayoutProps');
2829

2930
import type {
3031
PressEvent,
@@ -1125,15 +1126,15 @@ class ScrollView extends React.Component<Props, State> {
11251126
// On Android wrap the ScrollView with a AndroidSwipeRefreshLayout.
11261127
// Since the ScrollView is wrapped add the style props to the
11271128
// 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
11291130
// however, the ScrollView still needs the baseStyle to be scrollable
1130-
1131+
const {outer, inner} = splitLayoutProps(flattenStyle(props.style));
11311132
return React.cloneElement(
11321133
refreshControl,
1133-
{style: props.style},
1134+
{style: [baseStyle, outer]},
11341135
<ScrollViewClass
11351136
{...props}
1136-
style={baseStyle}
1137+
style={[baseStyle, inner]}
11371138
// $FlowFixMe
11381139
ref={this._setScrollViewRef}>
11391140
{contentContainer}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
});
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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;

0 commit comments

Comments
 (0)
Please sign in to comment.