Uh oh!
There was an error while loading. Please reload this page.
[ListView] Allow different types of ScrollView to be composed - #785
Conversation
21189f6 to
eeaa260Compareide
commented
Apr 12, 2015
ide
commented
Apr 12, 2015
It could be better to name the prop |
fee4b89 to
e767a5cCompareThere was a problem hiding this comment.
I want to merge the ListView's props (e.g. scrollEventThrottle) with the underlying ScrollView's props if renderScrollView returned something like <ScrollView pageSize={10} />, but the implementation in this diff is not flexible enough. I'll update it to your renderScrollView(props) idea after I try composing some ScrollViews together.
f364404 to
8279015Compare2ac5ede to
eae66d4Compareide
commented
May 6, 2015
catping |
frantic
commented
May 6, 2015
I tried this some time ago, but it turned out to be a disaster - RefreshableScrollView scrollview didn't play nicely with ListView because ListView depends on @ide have you tried <ListViewrenderScrollView={()=><RefreshableScrollView/>}/>with sections that have sticky headers? |
ide
commented
May 6, 2015
@frantic: my RefreshableScrollView (not yet open-sourced) doesn't modify the header indices or children so composing it with a ListView works. You may actually want to look at using it when it is open-source since it handles more edge cases and features than I believe the FB implementation does. Along with #766 this composition API lets me create reversed, refreshable, infinite-scroll list views for example. |
frantic
commented
May 6, 2015
@ide mind sharing it? I guess we could merge it into the main repo if you want. |
ide
commented
May 6, 2015
Yep, my plan is to share it in the near future once it is easy to use out of the box, since I am still working on the default spinner component. I will probably publish it to npm since it is pure JS code; it will be as simple as |
There was a problem hiding this comment.
No reason to mark this as required since it has a default implementation.
There was a problem hiding this comment.
Also, I agree that "ScrollView" is a little confusing here - renderScrollComponent might be better. Can you update?
There was a problem hiding this comment.
Will update with a renamed version.
Regarding isRequired, I understand it to mean that the type of this.props.renderScrollView is Function instead of ?Function in Flow-speak. So because we're saying the prop is non-null (which is true because of the default value from getDefaultProps), Flow won't complain about this.props.renderScrollView() needing a null check.
There was a problem hiding this comment.
Oh, interesting, does flow even apply to non-es6 class-style propTypes?
On Thu, Jun 11, 2015 at 4:29 PM James Ide notifications@github.com wrote:
In Libraries/CustomComponents/ListView/ListView.js
#785 (comment):@@ -164,6 +164,13 @@ var ListView = React.createClass({
/
renderSectionHeader: PropTypes.func,
/*
\* (props) => renderable*\* A function that returns the scroll view in which the list rows are\* rendered. Defaults to returning a ScrollView with the given props.*/- renderScrollView: React.PropTypes.func.isRequired,
Will update with a renamed version.
Regarding isRequired, I understand it to mean that the type of
this.props.renderScrollView is Function instead of ?Function in
Flow-speak. So because we're saying the prop is non-null (which is true
because of the default value from getDefaultProps), Flow won't complain
about this.props.renderScrollView() needing a null check.—
Reply to this email directly or view it on GitHub
https://github.com/facebook/react-native/pull/785/files#r32279234.
There was a problem hiding this comment.
Yeah, here's a small example:
/** * @flow */'use strict';varReact=require('react-native');var{ PropTypes, Text }=React;varApp=React.createClass({propTypes: {getContent: PropTypes.func,},render(){varcontent=this.props.getContent();return<Text>{content}</Text>;},});Flow prints:
/Users/ide/test/index.js:15:19,41: call of method getContent
Function cannot be called on possibly undefined value
/Users/ide/test/index.js:11:17,30: undefined
Adding isRequired makes the error go away.
There was a problem hiding this comment.
Oh cool, maybe new flow goodness. But defining a default for the prop and
leaving it not isRequired doesn't make the error go away? cc @glevi
On Thu, Jun 11, 2015 at 8:48 PM James Ide notifications@github.com wrote:
In Libraries/CustomComponents/ListView/ListView.js
#785 (comment):@@ -164,6 +164,13 @@ var ListView = React.createClass({
/
renderSectionHeader: PropTypes.func,
/*
\* (props) => renderable*\* A function that returns the scroll view in which the list rows are\* rendered. Defaults to returning a ScrollView with the given props.*/- renderScrollView: React.PropTypes.func.isRequired,
Yeah, here's a small example:
/** * @flow */'use strict';
var React = require('react-native');var { PropTypes, Text } = React;
var App = React.createClass({
propTypes: {
getContent: PropTypes.func,
},render() {
var content = this.props.getContent();
return {content};
},
});Flow prints:
/Users/ide/test/index.js:15:19,41: call of method getContent
Function cannot be called on possibly undefined value
/Users/ide/test/index.js:11:17,30: undefinedAdding isRequired makes the error go away.
—
Reply to this email directly or view it on GitHub
https://github.com/facebook/react-native/pull/785/files#r32288705.
There was a problem hiding this comment.
Adding getDefaultProps doesn't make the error go away (Flow 0.11.0):
getDefaultProps(){return{getContent(){return'x';}};},bogdantmm92
commented
Jun 22, 2015
Will this ever merge into the main repo? |
sahrens
commented
Jun 23, 2015
Sorry, bit of a holdup but will get it out soon. -Spencer
|
This enables code like:
```js
<ListView renderScrollView={(props) => <CustomScrollView {...props} />} />
```
where CustomScrollView might be inverted or support pull-to-refresh, etc.brentvatne
commented
Jul 7, 2015
cc @sahrens - this would be nice to get into 0.8.0-rc :) |
ide
commented
Jul 7, 2015
fwiw I'm doing some scroll view work right now and this pattern is working reasonably well in practice e.g. i can make a refreshable, infinitely scrolling list view. |
sahrens
commented
Jul 8, 2015
Sorry, some tests were failing so this got derailed. I'll try to land soon since Animated is mostly done.
|
Summary:
This enables code like:
```js
<ListView renderScrollView={() => <CustomScrollView />} />
```
where CustomScrollView might be inverted or support pull-to-refresh, etc.
Closesreact#785
Github Author: James Ide <ide@jameside.com>paramaggarwal
commented
Aug 14, 2015
Thanks for this @ide! Please do consider removing the |
ide
commented
Aug 14, 2015
@paramaggarwal Can you send a PR if flow understands getDefaultProps now? |
paramaggarwal
commented
Aug 14, 2015
@ide Oops! I thought you would know - I'm not very familiar with Flow. Sorry, ignore! |
alvaromb
commented
Nov 9, 2015
I'm getting the following warning when wrapping I'm just wrapping the list view to use a custom mixin. importReact,{ListView}from'react-native'importKeyboardAwareMixinfrom'./KeyboardAwareMixin'constKeyboardAwareListView=React.createClass({propTypes: {
...ListView.propTypes,},mixins: [KeyboardAwareMixin],render: function(){return(<ListViewref='keyboardView'keyboardDismissMode='interactive'contentInset={{bottom: this.state.keyboardSpace}}showsVerticalScrollIndicator={true}{...this.props}/>)},})exportdefaultKeyboardAwareListViewShould I take a different approach or |
ide
commented
Nov 9, 2015
@alvaromb we could probably make the prop non-required. It was marked as required to tell the Flow type checker that the prop was always defined, but feel free to send a PR to mark it non-required, as long as the type checker passes. |
* Update RCTCxxBridge.mm * Update RCTCxxBridge.mm * nil check websocket URL * use RCTAssertParam Co-authored-by: Chris Hogan <chrishogan@Chriss-MacBook-Pro-2.local>
* Add nullability checks (react#704) * Update RCTCxxBridge.mm * add nullability checks * Check a nil URL to fix crashes connecting to socket (react#785) * Update RCTCxxBridge.mm * Update RCTCxxBridge.mm * nil check websocket URL * use RCTAssertParam Co-authored-by: Chris Hogan <chrishogan@Chriss-MacBook-Pro-2.local> * pod install Co-authored-by: Chris Hogan <chrishogan@Chriss-MacBook-Pro-2.local>
This enables code like:
where CustomScrollView might be inverted or support pull-to-refresh, etc.