优化关注列表下拉刷新逻辑,更新react-native-simple-store至1.1.0 review by 草莓
Showing
4 changed files
with
17 additions
and
10 deletions
@@ -29,6 +29,12 @@ export default class Interest extends Component { | @@ -29,6 +29,12 @@ export default class Interest extends Component { | ||
29 | }); | 29 | }); |
30 | } | 30 | } |
31 | 31 | ||
32 | + componentDidMount() { | ||
33 | + InteractionManager.runAfterInteractions(() => { | ||
34 | + this.listView && this.listView.getScrollResponder().startPullToRefresh(); | ||
35 | + }); | ||
36 | + } | ||
37 | + | ||
32 | componentWillReceiveProps(nextProps) { | 38 | componentWillReceiveProps(nextProps) { |
33 | if (nextProps.data.ptr) { | 39 | if (nextProps.data.ptr) { |
34 | this.listView && this.listView.scrollTo({x: 0, y: 0, animated: false, }); | 40 | this.listView && this.listView.scrollTo({x: 0, y: 0, animated: false, }); |
@@ -84,9 +90,7 @@ export default class Interest extends Component { | @@ -84,9 +90,7 @@ export default class Interest extends Component { | ||
84 | enablePullToRefresh={true} | 90 | enablePullToRefresh={true} |
85 | isOnPullToRefresh={isPullToRefresh} | 91 | isOnPullToRefresh={isPullToRefresh} |
86 | onRefreshData={() => { | 92 | onRefreshData={() => { |
87 | - if (list.size != 0 && !isPullToRefresh) { | ||
88 | this.props.onRefresh && this.props.onRefresh(); | 93 | this.props.onRefresh && this.props.onRefresh(); |
89 | - } | ||
90 | }} | 94 | }} |
91 | onEndReached={() => { | 95 | onEndReached={() => { |
92 | if (list.size != 0) { | 96 | if (list.size != 0) { |
@@ -84,7 +84,6 @@ class InterestContainer extends Component { | @@ -84,7 +84,6 @@ class InterestContainer extends Component { | ||
84 | 84 | ||
85 | componentDidMount() { | 85 | componentDidMount() { |
86 | this.props.actions.loadCachedInterestList(); | 86 | this.props.actions.loadCachedInterestList(); |
87 | - this.props.actions.interestList(true); | ||
88 | } | 87 | } |
89 | 88 | ||
90 | componentWillUnmount() { | 89 | componentWillUnmount() { |
@@ -2,6 +2,9 @@ | @@ -2,6 +2,9 @@ | ||
2 | 2 | ||
3 | import ReactNative from 'react-native'; | 3 | import ReactNative from 'react-native'; |
4 | import InterestService from '../../services/InterestService'; | 4 | import InterestService from '../../services/InterestService'; |
5 | +import store from 'react-native-simple-store'; | ||
6 | + | ||
7 | +const YH_RNCacheTypeInterestList = 'YH_RNCacheTypeInterestList'; | ||
5 | 8 | ||
6 | const { | 9 | const { |
7 | SET_TYPE, | 10 | SET_TYPE, |
@@ -37,8 +40,12 @@ export function loadCachedInterestList() { | @@ -37,8 +40,12 @@ export function loadCachedInterestList() { | ||
37 | return; | 40 | return; |
38 | } | 41 | } |
39 | 42 | ||
40 | - ReactNative.NativeModules.YH_ClassifyHelper.loadCachedInterestData() | 43 | + store.get(YH_RNCacheTypeInterestList) |
41 | .then(data => { | 44 | .then(data => { |
45 | + if (!data) { | ||
46 | + return; | ||
47 | + } | ||
48 | + | ||
42 | dispatch({ | 49 | dispatch({ |
43 | type: LOAD_CACHED_INTEREST_LIST, | 50 | type: LOAD_CACHED_INTEREST_LIST, |
44 | payload: data, | 51 | payload: data, |
@@ -112,12 +119,9 @@ export function interestList(reload=false) { | @@ -112,12 +119,9 @@ export function interestList(reload=false) { | ||
112 | let list = [...oldList, ...payload.list]; | 119 | let list = [...oldList, ...payload.list]; |
113 | payload.list = list; | 120 | payload.list = list; |
114 | } else { | 121 | } else { |
115 | - ReactNative.NativeModules.YH_ClassifyHelper.updateCachedInterestData(payload.list) | 122 | + store.save(YH_RNCacheTypeInterestList, payload.list) |
116 | .then(data => { | 123 | .then(data => { |
117 | - dispatch({ | ||
118 | - type: LOAD_CACHED_INTEREST_LIST, | ||
119 | - payload: payload.list, | ||
120 | - }); | 124 | + |
121 | }) | 125 | }) |
122 | .catch(error => { | 126 | .catch(error => { |
123 | 127 |
@@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
22 | "react-native-progress": "^3.0.1", | 22 | "react-native-progress": "^3.0.1", |
23 | "react-native-router-flux": "^3.32.0", | 23 | "react-native-router-flux": "^3.32.0", |
24 | "react-native-scrollable-mixin": "^1.0.1", | 24 | "react-native-scrollable-mixin": "^1.0.1", |
25 | - "react-native-simple-store": "^1.0.1", | 25 | + "react-native-simple-store": "^1.1.0", |
26 | "react-native-swiper": "^1.4.11", | 26 | "react-native-swiper": "^1.4.11", |
27 | "react-redux": "^4.4.5", | 27 | "react-redux": "^4.4.5", |
28 | "react-static-container": "^1.0.1", | 28 | "react-static-container": "^1.0.1", |
-
Please register or login to post a comment