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
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ var RecyclerViewBackedScrollView = React.createClass({
);
});

const refreshControl = this.props.refreshControl;
if (refreshControl) {
// 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.

<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.

{wrappedChildren}
</NativeAndroidRecyclerView>
);
}

return (
<NativeAndroidRecyclerView {...props}>
{wrappedChildren}
Expand Down