|
@@ -24,9 +24,14 @@ export default class FetchedDataSectionList extends React.Component<Props, State
|
24
|
24
|
|
25
|
25
|
webDataManager: WebDataManager;
|
26
|
26
|
|
27
|
|
- constructor(fetchUrl: string) {
|
|
27
|
+ willFocusSubscription : function;
|
|
28
|
+ willBlurSubscription : function;
|
|
29
|
+ refreshInterval: IntervalID;
|
|
30
|
+
|
|
31
|
+ constructor(fetchUrl: string, refreshTime : number) {
|
28
|
32
|
super();
|
29
|
33
|
this.webDataManager = new WebDataManager(fetchUrl);
|
|
34
|
+ this.refreshTime = refreshTime;
|
30
|
35
|
}
|
31
|
36
|
|
32
|
37
|
state = {
|
|
@@ -48,10 +53,40 @@ export default class FetchedDataSectionList extends React.Component<Props, State
|
48
|
53
|
* Refresh the FetchedData on first screen load
|
49
|
54
|
*/
|
50
|
55
|
componentDidMount() {
|
|
56
|
+ this.willFocusSubscription = this.props.navigation.addListener(
|
|
57
|
+ 'willFocus',
|
|
58
|
+ payload => {
|
|
59
|
+ this.onScreenFocus();
|
|
60
|
+ }
|
|
61
|
+ );
|
|
62
|
+ this.willBlurSubscription = this.props.navigation.addListener(
|
|
63
|
+ 'willBlur',
|
|
64
|
+ payload => {
|
|
65
|
+ this.onScreenBlur();
|
|
66
|
+ }
|
|
67
|
+ );
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ onScreenFocus() {
|
51
|
71
|
this._onRefresh();
|
|
72
|
+ if (this.refreshTime > 0)
|
|
73
|
+ this.refreshInterval = setInterval(() => this._onRefresh(), this.refreshTime)
|
52
|
74
|
}
|
53
|
75
|
|
|
76
|
+ onScreenBlur() {
|
|
77
|
+ clearInterval(this.refreshInterval);
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+ componentWillUnmount() {
|
|
82
|
+ this.willBlurSubscription.remove();
|
|
83
|
+ this.willFocusSubscription.remove();
|
|
84
|
+
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+
|
54
|
88
|
_onRefresh = () => {
|
|
89
|
+ console.log('refresh');
|
55
|
90
|
this.setState({refreshing: true});
|
56
|
91
|
this.webDataManager.readData().then((fetchedData) => {
|
57
|
92
|
this.setState({
|