Uh oh!
There was an error while loading. Please reload this page.
[FlatList] Add setNativeProps - #13529
Conversation
ide
commented
Apr 20, 2017
@sahrens this looks good to me, can you take a look? |
chitezh
commented
Jun 20, 2017
sahrens
left a comment
There was a problem hiding this comment.
Sweet, thanks! Sorry I missed the earlier mention.
facebook-github-bot
commented
Jun 20, 2017
@sahrens has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary:
Curently FlatList does not implement setting native props directly like the old ListView did. This pr introduce the `setNativeProps` function which delegates to MetroListView or VirtualizedList. Thos don't have `setNativeProps` handling either, so, I delegated further to the respective ListView and Scroll components, which do have handling for it, thus, allowing to set the native props through FlatList.
Create a project with a FlatList and change a native property using `setNativeProps`:
```javascript
componentDidMount() {
setInterval(() => {
this.list.setNativeProps({ style: {backgroundColor:"white"} })
}, 1000)
}
render() {
return (
<View style={styles.container}>
<FlatList ref={component => this.list = component}
style={{backgroundColor:"black"}}
data={[{key: 'a'}, {key: 'b'}]}
renderItem={({item}) => <Text>{item.key}</Text>} />
</View>
)
}
```
Fixesreact#13501Closesreact#13529
Differential Revision: D5283593
Pulled By: sahrens
fbshipit-source-id: 8f96f88e286042d82452fef924689b5a8a783987Can we use setNativeProps with FlatList now? I'm currently unable on RN61.1 edit: I've got setNativeProps working with a subset of FlatList props @sahrens@ide I've modified an example from the PR that adds Can anyone help me understand what I'm doing wrong? exportdefaultclassTestingextendsReact.Component{componentDidMount(){lettick=0this.list.setNativeProps({onEndReached: info=>{// NEVER CALLED 😢console.log('L231 on Scroll info ===',info)},onScroll: info=>{// NEVER CALLED 😢console.log('L250 info ===',info)},// Background DOES flash red on load... 🤔 style: {backgroundColor: 'red'}})setInterval(()=>{this.list.setNativeProps({onEndReached: info=>{console.log('L231 on Scroll info ===',info)},// Background DOES toggle black and white... 🤔 style: {backgroundColor: tick++&2 ? 'white' : 'black'}})},1000)}render(){return(<Viewstyle={styles.container}><FlatListref={component=>(this.list=component)}style={{backgroundColor: 'black'}}data={[{key: 'a'},{key: 'b'}]}renderItem={({ item })=><Text>{item.key}</Text>}/></View>)}} |
a-eid
commented
Sep 14, 2020
@technoplato why would u wanna |
technoplato
commented
Sep 14, 2020
@a-eid it’s been a little since I was working on this, but I think I was trying to create a library that would turn your list into one with infinite scroll capabilities. I’m sure there are better ways and that I was missing the forest through the trees. |
aminta
commented
Oct 6, 2022
So, in 2022 is it now possibile? |
Motivation (required)
Curently FlatList does not implement setting native props directly like the old ListView did. This pr introduce the
setNativePropsfunction which delegates to MetroListView or VirtualizedList. Thos don't havesetNativePropshandling either, so, I delegated further to the respective ListView and Scroll components, which do have handling for it, thus, allowing to set the native props through FlatList.Test Plan (required)
Create a project with a FlatList and change a native property using
setNativeProps:Fixes#13501