From 75508c12fff55d14938ed261523a2bc2bd6fc309 Mon Sep 17 00:00:00 2001 From: Rene Weber Date: Tue, 20 Jun 2017 09:24:54 -0700 Subject: [PATCH] Add setNativeProps 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 ( this.list = component} style={{backgroundColor:"black"}} data={[{key: 'a'}, {key: 'b'}]} renderItem={({item}) => {item.key}} /> ) } ``` Fixes #13501 Closes https://github.com/facebook/react-native/pull/13529 Differential Revision: D5283593 Pulled By: sahrens fbshipit-source-id: 8f96f88e286042d82452fef924689b5a8a783987 --- Libraries/Lists/FlatList.js | 6 ++++++ Libraries/Lists/MetroListView.js | 5 +++++ Libraries/Lists/VirtualizedList.js | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 0bbbf0b3c65ae8..534673974386cb 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -388,6 +388,12 @@ class FlatList } } + setNativeProps(props: Object) { + if (this._listRef) { + this._listRef.setNativeProps(props); + } + } + componentWillMount() { this._checkProps(this.props); } diff --git a/Libraries/Lists/MetroListView.js b/Libraries/Lists/MetroListView.js index bbe758282e7efa..4a1cb09dca3512 100644 --- a/Libraries/Lists/MetroListView.js +++ b/Libraries/Lists/MetroListView.js @@ -95,6 +95,11 @@ class MetroListView extends React.Component { getListRef() { return this._listRef; } + setNativeProps(props: Object) { + if (this._listRef) { + this._listRef.setNativeProps(props); + } + } static defaultProps: DefaultProps = { keyExtractor: (item, index) => item.key || String(index), renderScrollComponent: (props: Props) => { diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index fec790df30f98d..680f720e0d3317 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -313,6 +313,12 @@ class VirtualizedList extends React.PureComponent { } } + setNativeProps(props: Object) { + if (this._scrollRef) { + this._scrollRef.setNativeProps(props); + } + } + static defaultProps = { disableVirtualization: false, horizontal: false,