Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support RefreshControl in RecyclerViewBackedScrollView in Android #8639

Closed
wants to merge 3 commits into from

Conversation

tegon
Copy link
Contributor

@tegon tegon commented Jul 7, 2016

In Android, RecyclerViewBackedScrollView wasn't using refreshControl prop.
If a ListView were created with RecyclerViewBackedScrollView as its renderScrollComponent, then the refreshControl wouldn't work.
example:

        <ListView
          dataSource={this.props.dataSource}
          renderRow={this._renderRow.bind(this)}
          refreshControl={
            <RefreshControl 
              refreshing={this.props.isRefreshing} 
              onRefresh={this._onRefresh.bind(this)} 
            />
          }
          renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}/>;

This works in iOS, since the RecyclerViewBackedScrollView just returns an ScrollView.

This pull request uses the refreshControl to decide whether it should wrap the NativeAndroidRecyclerView with an
AndroidSwipeRefreshLayout or not.

This fixes the issue #7134.

@ghost
Copy link

ghost commented Jul 7, 2016

By analyzing the blame information on this pull request, we identified @kmagiera and @jutaz to be potential reviewers.

@ghost ghost added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jul 7, 2016
@satya164
Copy link
Contributor

satya164 commented Jul 8, 2016

cc @janicduplessis

return React.cloneElement(
refreshControl,
{style: props.style},
<NativeAndroidRecyclerView {...props}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a style with flex: 1 to NativeAndroidRecyclerView to make sure it fills the AndroidSwipeRefreshLayout.

Copy link
Contributor Author

@tegon tegon Jul 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This style is already in props.

console.log('props.style', props.style[0])
=> props.style Object {flex: 1}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly concerned about passing props.style to both AndroidSwipeRefreshLayout and NativeAndroidRecyclerView. Styles like margin could cause issues because they will get applied twice. Adding style after ...props will prevent that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it. Just added the style in the last commit.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 12, 2016
// Wrap the NativeAndroidRecyclerView with a AndroidSwipeRefreshLayout.
return React.cloneElement(
refreshControl,
{style: props.style},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove props.style above in theprops definition and instead pass in this.props.style (and add flex: 1 if it's necessary).

And set style in the props definition above to just {flex: 1}.

Also rename props to recyclerProps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i'm a litte bit confused... it should became something like this?

    const refreshControl = this.props.refreshControl;
     if (refreshControl) {
       // Wrap the NativeAndroidRecyclerView with a AndroidSwipeRefreshLayout.
       return React.cloneElement(
         refreshControl,
         {style: {flex: 1}},
         <NativeAndroidRecyclerView {...props}>
           {wrappedChildren}
         </NativeAndroidRecyclerView>
       );
     }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the clearer way to do this is not include style in the props declaration (line 95). This way we can be explicit about what style we want for each case.

Should look like

   const recyclerProps = { ... };

   ...

    const refreshControl = this.props.refreshControl;
     if (refreshControl) {
       // Wrap the NativeAndroidRecyclerView with a AndroidSwipeRefreshLayout.
       return React.cloneElement(
         refreshControl,
         {style: [styles.base, this.props.style]},
         <NativeAndroidRecyclerView {...recyclerProps} style={styles.base}>
           {wrappedChildren}
         </NativeAndroidRecyclerView>
       );
     }

styles.base being {flex: 1}

We'll also have to change the case where there is no refreshControl to style={[styles.base, this.props.style]} and {...recyclerProps}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, one way to think of it is: how would this code be most clearly written from scratch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've understood now, it is more clear indeed. Just pushed the changes.

@ide
Copy link
Contributor

ide commented Jul 14, 2016

Thanks, this looks good!

@facebook-github-bot shipit

@ghost ghost added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Jul 14, 2016
@ghost
Copy link

ghost commented Jul 14, 2016

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 14, 2016
@ghost ghost closed this in 0c0ac6e Jul 14, 2016
@waqas19921
Copy link

is that issue fixed?
refreshcontrol is still not working if ListViewwere created with RecyclerViewBackedScrollViewas its renderScrollComponent
i am using react-native 0.30

@janicduplessis
Copy link
Contributor

This is in 0.31.0-rc

samerce pushed a commit to iodine/react-native that referenced this pull request Aug 23, 2016
Summary:
In Android, `RecyclerViewBackedScrollView` wasn't using `refreshControl` prop.
If a ListView were created with `RecyclerViewBackedScrollView` as its `renderScrollComponent`, then the `refreshControl` wouldn't work.
example:
```js
        <ListView
          dataSource={this.props.dataSource}
          renderRow={this._renderRow.bind(this)}
          refreshControl={
            <RefreshControl
              refreshing={this.props.isRefreshing}
              onRefresh={this._onRefresh.bind(this)}
            />
          }
          renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}/>;
```
This works in iOS, since the `RecyclerViewBackedScrollView` just returns an `ScrollView`.

This pull request uses the `refreshControl` to decide whether it should wrap the `NativeAndroidRecyclerView` with an
`AndroidSwipeRefreshLayout` or not.

This fixes the issue facebook#7134.
Closes facebook#8639

Differential Revision: D3564158

fbshipit-source-id: c10a880ea61cd80b8af789b00be90d46d63eaf9a
mpretty-cyro pushed a commit to HomePass/react-native that referenced this pull request Aug 25, 2016
Summary:
In Android, `RecyclerViewBackedScrollView` wasn't using `refreshControl` prop.
If a ListView were created with `RecyclerViewBackedScrollView` as its `renderScrollComponent`, then the `refreshControl` wouldn't work.
example:
```js
        <ListView
          dataSource={this.props.dataSource}
          renderRow={this._renderRow.bind(this)}
          refreshControl={
            <RefreshControl
              refreshing={this.props.isRefreshing}
              onRefresh={this._onRefresh.bind(this)}
            />
          }
          renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}/>;
```
This works in iOS, since the `RecyclerViewBackedScrollView` just returns an `ScrollView`.

This pull request uses the `refreshControl` to decide whether it should wrap the `NativeAndroidRecyclerView` with an
`AndroidSwipeRefreshLayout` or not.

This fixes the issue facebook#7134.
Closes facebook#8639

Differential Revision: D3564158

fbshipit-source-id: c10a880ea61cd80b8af789b00be90d46d63eaf9a
tungdo194 pushed a commit to tungdo194/rn-test that referenced this pull request Apr 28, 2024
Summary:
In Android, `RecyclerViewBackedScrollView` wasn't using `refreshControl` prop.
If a ListView were created with `RecyclerViewBackedScrollView` as its `renderScrollComponent`, then the `refreshControl` wouldn't work.
example:
```js
        <ListView
          dataSource={this.props.dataSource}
          renderRow={this._renderRow.bind(this)}
          refreshControl={
            <RefreshControl
              refreshing={this.props.isRefreshing}
              onRefresh={this._onRefresh.bind(this)}
            />
          }
          renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}/>;
```
This works in iOS, since the `RecyclerViewBackedScrollView` just returns an `ScrollView`.

This pull request uses the `refreshControl` to decide whether it should wrap the `NativeAndroidRecyclerView` with an
`AndroidSwipeRefreshLayout` or not.

This fixes the issue #7134.
Closes facebook/react-native#8639

Differential Revision: D3564158

fbshipit-source-id: c10a880ea61cd80b8af789b00be90d46d63eaf9a
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants