Skip to content

Commit a7fabe4

Browse files
aryonecolas
authored andcommitted
[fix] ScrollView forwards style when 'refreshControl' prop is present
Fix #2024
1 parent a968c0c commit a7fabe4

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`components/ScrollView prop "refreshControl" with 1`] = `
4+
<div
5+
id="refresh-control"
6+
>
7+
<div
8+
class="css-view-1dbjc4n r-WebkitOverflowScrolling-150rngu r-flexDirection-eqz5dr r-flexGrow-16y2uox r-flexShrink-1wbh5a2 r-overflowX-11yh6sk r-overflowY-1rnoaur r-transform-1sncvnh"
9+
style="background-color: rgb(255, 0, 0);"
10+
>
11+
<div
12+
class="css-view-1dbjc4n"
13+
/>
14+
</div>
15+
</div>
16+
`;
17+
18+
exports[`components/ScrollView prop "refreshControl" without 1`] = `
19+
<div
20+
class="css-view-1dbjc4n r-WebkitOverflowScrolling-150rngu r-flexDirection-eqz5dr r-flexGrow-16y2uox r-flexShrink-1wbh5a2 r-overflowX-11yh6sk r-overflowY-1rnoaur r-transform-1sncvnh"
21+
style="background-color: rgb(255, 0, 0);"
22+
>
23+
<div
24+
class="css-view-1dbjc4n"
25+
/>
26+
</div>
27+
`;

packages/react-native-web/src/exports/ScrollView/__tests__/index-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,21 @@ describe('components/ScrollView', () => {
8686
expect(typeof node.scrollResponderScrollNativeHandleToKeyboard === 'function').toBe(true);
8787
});
8888
});
89+
90+
describe('prop "refreshControl"', () => {
91+
test('without', () => {
92+
const { container } = render(<ScrollView style={{ backgroundColor: 'red' }} />);
93+
expect(container.firstChild).toMatchSnapshot();
94+
});
95+
96+
test('with', () => {
97+
const { container } = render(
98+
<ScrollView
99+
refreshControl={<div id="refresh-control" />}
100+
style={{ backgroundColor: 'red' }}
101+
/>
102+
);
103+
expect(container.firstChild).toMatchSnapshot();
104+
});
105+
});
89106
});

packages/react-native-web/src/exports/ScrollView/index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,17 @@ const ScrollView = ((createReactClass({
223223

224224
invariant(ScrollViewClass !== undefined, 'ScrollViewClass must not be undefined');
225225

226-
if (refreshControl) {
227-
return React.cloneElement(
228-
refreshControl,
229-
{ style: props.style },
230-
<ScrollViewClass {...props} ref={this._setScrollNodeRef} style={baseStyle}>
231-
{contentContainer}
232-
</ScrollViewClass>
233-
);
234-
}
235-
236-
return (
226+
const scrollView = (
237227
<ScrollViewClass {...props} ref={this._setScrollNodeRef}>
238228
{contentContainer}
239229
</ScrollViewClass>
240230
);
231+
232+
if (refreshControl) {
233+
return React.cloneElement(refreshControl, { style: props.style }, scrollView);
234+
}
235+
236+
return scrollView;
241237
},
242238

243239
_handleContentOnLayout(e: Object) {

0 commit comments

Comments
 (0)