-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[FlatList] Add setNativeProps #13529
Conversation
@sahrens this looks good to me, can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, thanks! Sorry I missed the earlier mention.
@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> ) } ``` Fixes facebook#13501 Closes facebook#13529 Differential Revision: D5283593 Pulled By: sahrens fbshipit-source-id: 8f96f88e286042d82452fef924689b5a8a783987
Can 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? export default class Testing extends React.Component {
componentDidMount() {
let tick = 0
this.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 (
<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>
)
}
} |
@technoplato why would u wanna |
@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. |
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
setNativeProps
function which delegates to MetroListView or VirtualizedList. Thos don't havesetNativeProps
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.Test Plan (required)
Create a project with a FlatList and change a native property using
setNativeProps
:Fixes #13501