From 663b4297b39fce85345413a0040e91b8df8313ed Mon Sep 17 00:00:00 2001 From: Hadi Mostafapour Date: Mon, 17 Apr 2017 18:02:48 +0430 Subject: [PATCH 1/3] Use Promises for RefreshControl --- components/ListView.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/ListView.js b/components/ListView.js index 01a28b70..ab9013f5 100644 --- a/components/ListView.js +++ b/components/ListView.js @@ -132,7 +132,16 @@ class ListView extends React.Component { }); if (this.props.onRefresh) { - this.props.onRefresh(); + const callback = this.props.onRefresh(); + const setIdle = () => { + this.setState({ + status: Status.IDLE, + }); + }; + + if(typeof callback === 'object' && typeof callback.then === 'function') { + callback.then(setIdle, setIdle); + } } } From e8ab9c4b02a136a60655022275f7b311df4dbd17 Mon Sep 17 00:00:00 2001 From: Hadi Mostafapour Date: Mon, 17 Apr 2017 18:38:44 +0430 Subject: [PATCH 2/3] Make sure component is mounted due async callback --- components/ListView.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/components/ListView.js b/components/ListView.js index ab9013f5..2d213601 100644 --- a/components/ListView.js +++ b/components/ListView.js @@ -80,6 +80,8 @@ class ListView extends React.Component { // TODO(Braco) - add render separator }; + isMounted = true; + constructor(props, context) { super(props, context); this.handleListViewRef = this.handleListViewRef.bind(this); @@ -124,6 +126,7 @@ class ListView extends React.Component { // Reset the global network indicator state StatusBar.setNetworkActivityIndicatorVisible(false); } + this.isMounted = false; } onRefresh() { @@ -134,9 +137,11 @@ class ListView extends React.Component { if (this.props.onRefresh) { const callback = this.props.onRefresh(); const setIdle = () => { - this.setState({ - status: Status.IDLE, - }); + if(this.isMounted) { + this.setState({ + status: Status.IDLE, + }); + } }; if(typeof callback === 'object' && typeof callback.then === 'function') { From 73b397912d5bf711f0b0d91e0e775cb02bd3f519 Mon Sep 17 00:00:00 2001 From: Hadi Mostafapour Date: Mon, 17 Apr 2017 18:46:53 +0430 Subject: [PATCH 3/3] Update ListView.js --- components/ListView.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/ListView.js b/components/ListView.js index 2d213601..a6e0f6d6 100644 --- a/components/ListView.js +++ b/components/ListView.js @@ -80,7 +80,7 @@ class ListView extends React.Component { // TODO(Braco) - add render separator }; - isMounted = true; + _isMounted = true; constructor(props, context) { super(props, context); @@ -126,7 +126,7 @@ class ListView extends React.Component { // Reset the global network indicator state StatusBar.setNetworkActivityIndicatorVisible(false); } - this.isMounted = false; + this._isMounted = false; } onRefresh() { @@ -137,7 +137,7 @@ class ListView extends React.Component { if (this.props.onRefresh) { const callback = this.props.onRefresh(); const setIdle = () => { - if(this.isMounted) { + if(this._isMounted) { this.setState({ status: Status.IDLE, });