Merge branch 'local' into develop
Showing
20 changed files
with
136 additions
and
97 deletions
@@ -296,6 +296,7 @@ export default function community(platform) { | @@ -296,6 +296,7 @@ export default function community(platform) { | ||
296 | key="SubjectPost" | 296 | key="SubjectPost" |
297 | title="主题帖" | 297 | title="主题帖" |
298 | hideNavBar={false} | 298 | hideNavBar={false} |
299 | + clone={true} | ||
299 | component={SubjectPostContainer} | 300 | component={SubjectPostContainer} |
300 | initial={false} | 301 | initial={false} |
301 | rightButtonImage={require('./images/posting/share.png')} | 302 | rightButtonImage={require('./images/posting/share.png')} |
@@ -317,9 +318,9 @@ export default function community(platform) { | @@ -317,9 +318,9 @@ export default function community(platform) { | ||
317 | <Scene | 318 | <Scene |
318 | key='LikeList' | 319 | key='LikeList' |
319 | hideNavBar={false} | 320 | hideNavBar={false} |
321 | + clone={true} | ||
320 | component={LikeListContainer} | 322 | component={LikeListContainer} |
321 | initial={false} | 323 | initial={false} |
322 | - clone={true} | ||
323 | getSceneStyle={(props) => { | 324 | getSceneStyle={(props) => { |
324 | return this.navPushStyle(props); | 325 | return this.navPushStyle(props); |
325 | }} | 326 | }} |
@@ -166,7 +166,7 @@ export default class NavBarTitle extends React.Component { | @@ -166,7 +166,7 @@ export default class NavBarTitle extends React.Component { | ||
166 | 166 | ||
167 | render() { | 167 | render() { |
168 | let index = this.props.index; | 168 | let index = this.props.index; |
169 | -console.log(width); | 169 | + |
170 | return ( | 170 | return ( |
171 | <Animated.View | 171 | <Animated.View |
172 | style={[ | 172 | style={[ |
@@ -171,7 +171,6 @@ export default class User extends React.Component { | @@ -171,7 +171,6 @@ export default class User extends React.Component { | ||
171 | this._renderRow = this._renderRow.bind(this); | 171 | this._renderRow = this._renderRow.bind(this); |
172 | this._renderSeparator = this._renderSeparator.bind(this); | 172 | this._renderSeparator = this._renderSeparator.bind(this); |
173 | this._updateHorizontalScrollValue = this._updateHorizontalScrollValue.bind(this); | 173 | this._updateHorizontalScrollValue = this._updateHorizontalScrollValue.bind(this); |
174 | - this._updateVerticalScrollValue = this._updateVerticalScrollValue.bind(this); | ||
175 | this._getCurrentPageHeight = this._getCurrentPageHeight.bind(this); | 174 | this._getCurrentPageHeight = this._getCurrentPageHeight.bind(this); |
176 | this.getPageList = this.getPageList.bind(this); | 175 | this.getPageList = this.getPageList.bind(this); |
177 | 176 | ||
@@ -314,10 +313,6 @@ export default class User extends React.Component { | @@ -314,10 +313,6 @@ export default class User extends React.Component { | ||
314 | this.state.scrollValueH.setValue(value); | 313 | this.state.scrollValueH.setValue(value); |
315 | } | 314 | } |
316 | 315 | ||
317 | - _updateVerticalScrollValue(value) { | ||
318 | - this.state.scrollValueV.setValue(value); | ||
319 | - } | ||
320 | - | ||
321 | _getCurrentPageHeight(page) { | 316 | _getCurrentPageHeight(page) { |
322 | let ref = null; | 317 | let ref = null; |
323 | if (page == 0) { | 318 | if (page == 0) { |
@@ -398,10 +393,13 @@ export default class User extends React.Component { | @@ -398,10 +393,13 @@ export default class User extends React.Component { | ||
398 | /> | 393 | /> |
399 | } | 394 | } |
400 | }} | 395 | }} |
401 | - onScroll={(e) => { | ||
402 | - const offsetY = e.nativeEvent.contentOffset.y; | ||
403 | - this._updateVerticalScrollValue(offsetY/150); | ||
404 | - }} | 396 | + onScroll={Animated.event([{ |
397 | + nativeEvent: { | ||
398 | + contentOffset: { | ||
399 | + y: this.state.scrollValueV | ||
400 | + } | ||
401 | + } | ||
402 | + }])} | ||
405 | /> | 403 | /> |
406 | 404 | ||
407 | <UserNavBar | 405 | <UserNavBar |
@@ -98,50 +98,14 @@ class UserNavBar extends React.Component { | @@ -98,50 +98,14 @@ class UserNavBar extends React.Component { | ||
98 | 98 | ||
99 | this.renderBackButton = this.renderBackButton.bind(this); | 99 | this.renderBackButton = this.renderBackButton.bind(this); |
100 | this.renderRightButton = this.renderRightButton.bind(this); | 100 | this.renderRightButton = this.renderRightButton.bind(this); |
101 | - this.setAnimationValue = this.setAnimationValue.bind(this); | ||
102 | - this.headerColor = this.headerColor.bind(this); | ||
103 | } | 101 | } |
104 | 102 | ||
105 | componentDidMount() { | 103 | componentDidMount() { |
106 | - this._listener = this.props.scrollValue.addListener(this.setAnimationValue); | ||
107 | - } | ||
108 | - | ||
109 | - componentWillUnmount() { | ||
110 | - this.props.scrollValue.removeListener(this._listener); | ||
111 | - } | ||
112 | 104 | ||
113 | - setAnimationValue({ value, }) { | ||
114 | - if (value >= 0 && value <= 2) { | ||
115 | - | ||
116 | - if (value > 0.5 && value < 1) { | ||
117 | - value = value + 0.1; | ||
118 | } | 105 | } |
119 | 106 | ||
120 | - this.headerView.setNativeProps({ | ||
121 | - style: { | ||
122 | - backgroundColor: this.headerColor(value), | ||
123 | - }, | ||
124 | - }); | ||
125 | - | ||
126 | - // value = value > 1 ? 1 : value; | ||
127 | - // this.image.setNativeProps({ | ||
128 | - // style: { | ||
129 | - // opacity: value, | ||
130 | - // }, | ||
131 | - // }); | ||
132 | - } | ||
133 | - } | 107 | + componentWillUnmount() { |
134 | 108 | ||
135 | - //color between rgb(255,255,255) and rgb(0,0,0) | ||
136 | - headerColor(progress) { | ||
137 | - const red = 255 + (0 - 255) * progress; | ||
138 | - const green = 255 + (0 - 255) * progress; | ||
139 | - const blue = 255 + (0 - 255) * progress; | ||
140 | - if (progress > 1) { | ||
141 | - return `rgb(0, 0, 0)`; //`darkgray` | ||
142 | - } else { | ||
143 | - return `rgba(${red}, ${green}, ${blue}, ${progress})`; | ||
144 | - } | ||
145 | } | 109 | } |
146 | 110 | ||
147 | renderBackButton() { | 111 | renderBackButton() { |
@@ -192,6 +156,16 @@ class UserNavBar extends React.Component { | @@ -192,6 +156,16 @@ class UserNavBar extends React.Component { | ||
192 | } | 156 | } |
193 | 157 | ||
194 | render() { | 158 | render() { |
159 | + let interpolatedColor = this.props.scrollValue.interpolate({ | ||
160 | + inputRange: [0, 64], | ||
161 | + outputRange: ['rgba(255, 255, 255, 0)', 'rgba(255, 255, 255, 1)'], | ||
162 | + extrapolate: 'clamp' | ||
163 | + }); | ||
164 | + let interpolatedOpacity = this.props.scrollValue.interpolate({ | ||
165 | + inputRange: [0, 64], | ||
166 | + outputRange: [0, 1], | ||
167 | + extrapolate: 'clamp' | ||
168 | + }); | ||
195 | return ( | 169 | return ( |
196 | <Animated.View | 170 | <Animated.View |
197 | ref={(c) => { | 171 | ref={(c) => { |
@@ -199,17 +173,18 @@ class UserNavBar extends React.Component { | @@ -199,17 +173,18 @@ class UserNavBar extends React.Component { | ||
199 | }} | 173 | }} |
200 | style={[ | 174 | style={[ |
201 | styles.header, | 175 | styles.header, |
176 | + {backgroundColor: interpolatedColor} | ||
202 | ]} | 177 | ]} |
203 | > | 178 | > |
204 | - <Image | 179 | + <Animated.Image |
205 | ref={(c) => { | 180 | ref={(c) => { |
206 | this.image = c; | 181 | this.image = c; |
207 | }} | 182 | }} |
208 | source={this.getNavBarBackgroundImage(this.props.channel)} | 183 | source={this.getNavBarBackgroundImage(this.props.channel)} |
209 | - style={[styles.image, {opacity: 0,}]} | 184 | + style={[styles.image, {opacity: interpolatedOpacity}]} |
210 | > | 185 | > |
211 | 186 | ||
212 | - </Image> | 187 | + </Animated.Image> |
213 | {this.renderBackButton()} | 188 | {this.renderBackButton()} |
214 | {this.renderRightButton()} | 189 | {this.renderRightButton()} |
215 | </Animated.View> | 190 | </Animated.View> |
@@ -79,7 +79,6 @@ export default class UserThatNotMe extends React.Component { | @@ -79,7 +79,6 @@ export default class UserThatNotMe extends React.Component { | ||
79 | this._renderRow = this._renderRow.bind(this); | 79 | this._renderRow = this._renderRow.bind(this); |
80 | this._renderSectionHeader = this._renderSectionHeader.bind(this); | 80 | this._renderSectionHeader = this._renderSectionHeader.bind(this); |
81 | this._renderSeparator = this._renderSeparator.bind(this); | 81 | this._renderSeparator = this._renderSeparator.bind(this); |
82 | - this._updateScrollValue = this._updateScrollValue.bind(this); | ||
83 | this.dataSource = new ListView.DataSource({ | 82 | this.dataSource = new ListView.DataSource({ |
84 | rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), | 83 | rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), |
85 | sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2), | 84 | sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2), |
@@ -149,10 +148,6 @@ export default class UserThatNotMe extends React.Component { | @@ -149,10 +148,6 @@ export default class UserThatNotMe extends React.Component { | ||
149 | } | 148 | } |
150 | } | 149 | } |
151 | 150 | ||
152 | - _updateScrollValue(value) { | ||
153 | - this.state.scrollValue.setValue(value); | ||
154 | - } | ||
155 | - | ||
156 | render() { | 151 | render() { |
157 | let {posts, endReached, isRefreshing, isLoadingMore, isFetching} = this.props; | 152 | let {posts, endReached, isRefreshing, isLoadingMore, isFetching} = this.props; |
158 | let dataSource = { | 153 | let dataSource = { |
@@ -165,10 +160,13 @@ export default class UserThatNotMe extends React.Component { | @@ -165,10 +160,13 @@ export default class UserThatNotMe extends React.Component { | ||
165 | ref={(c) => { | 160 | ref={(c) => { |
166 | this.listView = c; | 161 | this.listView = c; |
167 | }} | 162 | }} |
168 | - onScroll={(e) => { | ||
169 | - const offsetY = e.nativeEvent.contentOffset.y; | ||
170 | - this._updateScrollValue(offsetY / 150); | ||
171 | - }} | 163 | + onScroll={Animated.event([{ |
164 | + nativeEvent: { | ||
165 | + contentOffset: { | ||
166 | + y: this.state.scrollValue | ||
167 | + } | ||
168 | + } | ||
169 | + }])} | ||
172 | dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)} | 170 | dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)} |
173 | renderHeader={this._renderHeader} | 171 | renderHeader={this._renderHeader} |
174 | renderRow={this._renderRow} | 172 | renderRow={this._renderRow} |
4.05 KB
8.79 KB
@@ -36,27 +36,39 @@ const { | @@ -36,27 +36,39 @@ const { | ||
36 | } = require('../../constants/actionTypes').default; | 36 | } = require('../../constants/actionTypes').default; |
37 | 37 | ||
38 | export function goToSection(section) { | 38 | export function goToSection(section) { |
39 | + return (dispatch, getState) => { | ||
40 | + let {route} = getState(); | ||
41 | + let tryToClean = route.lastPopScene == 'Section'; | ||
39 | Actions.Section(); | 42 | Actions.Section(); |
40 | - return { | 43 | + dispatch({ |
41 | type: GO_TO_SECTION, | 44 | type: GO_TO_SECTION, |
42 | - payload: section, | ||
43 | - }; | 45 | + payload: {...section, tryToClean}, |
46 | + }); | ||
47 | + } | ||
44 | } | 48 | } |
45 | 49 | ||
46 | export function goToPost(id) { | 50 | export function goToPost(id) { |
51 | + return (dispatch, getState) => { | ||
52 | + let {route} = getState(); | ||
53 | + let tryToClean = route.lastPopScene == 'SubjectPost'; | ||
47 | Actions.SubjectPost({postId:id}); | 54 | Actions.SubjectPost({postId:id}); |
48 | - return { | 55 | + dispatch({ |
49 | type: GO_TO_POST, | 56 | type: GO_TO_POST, |
50 | - payload: id, | ||
51 | - }; | 57 | + payload: {id, tryToClean}, |
58 | + }); | ||
59 | + } | ||
52 | } | 60 | } |
53 | 61 | ||
54 | export function goToLikeList(postId, likeCount) { | 62 | export function goToLikeList(postId, likeCount) { |
63 | + return (dispatch, getState) => { | ||
64 | + let {route} = getState(); | ||
65 | + let tryToClean = route.lastPopScene == 'LikeList'; | ||
55 | Actions.LikeList({title: `共${likeCount}个赞`}); | 66 | Actions.LikeList({title: `共${likeCount}个赞`}); |
56 | - return { | 67 | + dispatch({ |
57 | type: GO_TO_LIKE_LIST, | 68 | type: GO_TO_LIKE_LIST, |
58 | - payload: postId, | ||
59 | - }; | 69 | + payload: {postId, tryToClean}, |
70 | + }); | ||
71 | + } | ||
60 | } | 72 | } |
61 | 73 | ||
62 | export function goToUserOrMe(uid) { | 74 | export function goToUserOrMe(uid) { |
@@ -68,11 +80,7 @@ export function goToUserOrMe(uid) { | @@ -68,11 +80,7 @@ export function goToUserOrMe(uid) { | ||
68 | type: GO_TO_USER, | 80 | type: GO_TO_USER, |
69 | }); | 81 | }); |
70 | } else { | 82 | } else { |
71 | - Actions.UserThatNotMe(); | ||
72 | - dispatch({ | ||
73 | - type: GO_TO_USER_THAT_NOT_ME, | ||
74 | - payload: uid, | ||
75 | - }); | 83 | + dispatch(goToUserThatNotMe(uid)); |
76 | } | 84 | } |
77 | }; | 85 | }; |
78 | } | 86 | } |
@@ -97,14 +105,15 @@ export function goToUser() { | @@ -97,14 +105,15 @@ export function goToUser() { | ||
97 | 105 | ||
98 | export function goToUserThatNotMe(uid) { | 106 | export function goToUserThatNotMe(uid) { |
99 | return (dispatch, getState) => { | 107 | return (dispatch, getState) => { |
100 | - let {user} = getState(); | 108 | + let {user, route} = getState(); |
101 | if (user.profile.uid == uid) { | 109 | if (user.profile.uid == uid) { |
102 | 110 | ||
103 | } else { | 111 | } else { |
112 | + let tryToClean = route.lastPopScene == 'UserThatNotMe'; | ||
104 | Actions.UserThatNotMe(); | 113 | Actions.UserThatNotMe(); |
105 | dispatch({ | 114 | dispatch({ |
106 | type: GO_TO_USER_THAT_NOT_ME, | 115 | type: GO_TO_USER_THAT_NOT_ME, |
107 | - payload: uid, | 116 | + payload: {uid, tryToClean}, |
108 | }); | 117 | }); |
109 | } | 118 | } |
110 | }; | 119 | }; |
@@ -24,15 +24,26 @@ export default function likeList(state = initialState, action) { | @@ -24,15 +24,26 @@ export default function likeList(state = initialState, action) { | ||
24 | 24 | ||
25 | switch (action.type) { | 25 | switch (action.type) { |
26 | case GO_TO_LIKE_LIST: { | 26 | case GO_TO_LIKE_LIST: { |
27 | - let sid = state.sid + 1; | 27 | + |
28 | + let currentSid = state.sid; | ||
29 | + let newItems = state.items; | ||
30 | + let newSid = currentSid; | ||
31 | + // componentWillUnmount未调用,导致clean操作未进行 | ||
32 | + if (action.payload.tryToClean && currentSid > -1 && !state.cleaned) { | ||
33 | + newItems = newItems.pop(); | ||
34 | + newSid = newSid - 1; | ||
35 | + } | ||
36 | + | ||
37 | + let sid = newSid + 1; | ||
28 | // 获取新的初始状态item | 38 | // 获取新的初始状态item |
29 | let item = initialState.item; | 39 | let item = initialState.item; |
30 | // 设置item的value | 40 | // 设置item的value |
31 | - item = item.set('postId', action.payload); | 41 | + item = item.set('postId', action.payload.postId); |
32 | // items新增item | 42 | // items新增item |
33 | - let newItems = state.items.push(item); | 43 | + newItems = newItems.push(item); |
34 | let nextState = state.set('sid', sid) | 44 | let nextState = state.set('sid', sid) |
35 | - .set('items', newItems); | 45 | + .set('items', newItems) |
46 | + .set('cleaned', false); | ||
36 | return nextState; | 47 | return nextState; |
37 | } | 48 | } |
38 | 49 | ||
@@ -69,7 +80,8 @@ export default function likeList(state = initialState, action) { | @@ -69,7 +80,8 @@ export default function likeList(state = initialState, action) { | ||
69 | if (state.items.size > sid) { | 80 | if (state.items.size > sid) { |
70 | let items = state.items.pop(); | 81 | let items = state.items.pop(); |
71 | let nextState = state.set('sid', sid - 1) | 82 | let nextState = state.set('sid', sid - 1) |
72 | - .set('items', items); | 83 | + .set('items', items) |
84 | + .set('cleaned', true); | ||
73 | return nextState; | 85 | return nextState; |
74 | } | 86 | } |
75 | } | 87 | } |
@@ -2,6 +2,7 @@ import { ActionConst } from 'react-native-router-flux'; | @@ -2,6 +2,7 @@ import { ActionConst } from 'react-native-router-flux'; | ||
2 | 2 | ||
3 | const initialState = { | 3 | const initialState = { |
4 | scene: {}, | 4 | scene: {}, |
5 | + lastPopScene: '', | ||
5 | }; | 6 | }; |
6 | 7 | ||
7 | export default function reducer(state = initialState, action = {}) { | 8 | export default function reducer(state = initialState, action = {}) { |
@@ -13,6 +14,12 @@ export default function reducer(state = initialState, action = {}) { | @@ -13,6 +14,12 @@ export default function reducer(state = initialState, action = {}) { | ||
13 | scene: action.scene, | 14 | scene: action.scene, |
14 | }; | 15 | }; |
15 | 16 | ||
17 | + case ActionConst.BACK_ACTION: | ||
18 | + return { | ||
19 | + ...state, | ||
20 | + lastPopScene: state.scene.sceneKey, | ||
21 | + }; | ||
22 | + | ||
16 | // ...other actions | 23 | // ...other actions |
17 | 24 | ||
18 | default: | 25 | default: |
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | * InitialState | 10 | * InitialState |
11 | */ | 11 | */ |
12 | import InitialState from './sectionInitialState'; | 12 | import InitialState from './sectionInitialState'; |
13 | -import Immutable, {Map} from 'immutable'; | 13 | +import Immutable, {Map, List} from 'immutable'; |
14 | 14 | ||
15 | const { | 15 | const { |
16 | SECTION_HEADER_REQUEST, | 16 | SECTION_HEADER_REQUEST, |
@@ -46,16 +46,27 @@ export default function sectionReducer(state = initialState, action) { | @@ -46,16 +46,27 @@ export default function sectionReducer(state = initialState, action) { | ||
46 | switch (action.type) { | 46 | switch (action.type) { |
47 | 47 | ||
48 | case GO_TO_SECTION: { | 48 | case GO_TO_SECTION: { |
49 | - let sid = state.sid + 1; | 49 | + |
50 | + let currentSid = state.sid; | ||
51 | + let newItems = state.items; | ||
52 | + let newSid = currentSid; | ||
53 | + // componentWillUnmount未调用,导致clean操作未进行 | ||
54 | + if (action.payload.tryToClean && currentSid > -1 && !state.cleaned) { | ||
55 | + newItems = newItems.pop(); | ||
56 | + newSid = newSid - 1; | ||
57 | + } | ||
58 | + | ||
59 | + let sid = newSid + 1; | ||
50 | // 获取新的初始状态item | 60 | // 获取新的初始状态item |
51 | let item = initialState.item; | 61 | let item = initialState.item; |
52 | // 设置item的value | 62 | // 设置item的value |
53 | item = item.set('id', action.payload.id) | 63 | item = item.set('id', action.payload.id) |
54 | .set('name', action.payload.name); | 64 | .set('name', action.payload.name); |
55 | // items新增item | 65 | // items新增item |
56 | - let newItems = state.items.push(item); | 66 | + let items = newItems.push(item); |
57 | let nextState = state.set('sid', sid) | 67 | let nextState = state.set('sid', sid) |
58 | - .set('items', newItems); | 68 | + .set('items', items) |
69 | + .set('cleaned', false); | ||
59 | return nextState; | 70 | return nextState; |
60 | } | 71 | } |
61 | 72 | ||
@@ -172,7 +183,8 @@ export default function sectionReducer(state = initialState, action) { | @@ -172,7 +183,8 @@ export default function sectionReducer(state = initialState, action) { | ||
172 | if (state.items.size > sid) { | 183 | if (state.items.size > sid) { |
173 | let items = state.items.pop(); | 184 | let items = state.items.pop(); |
174 | let nextState = state.set('sid', sid - 1) | 185 | let nextState = state.set('sid', sid - 1) |
175 | - .set('items', items); | 186 | + .set('items', items) |
187 | + .set('cleaned', true); | ||
176 | return nextState; | 188 | return nextState; |
177 | } | 189 | } |
178 | } | 190 | } |
@@ -56,17 +56,27 @@ export default function postingReducer(state = initialState, action) { | @@ -56,17 +56,27 @@ export default function postingReducer(state = initialState, action) { | ||
56 | 56 | ||
57 | switch (action.type) { | 57 | switch (action.type) { |
58 | case GO_TO_POST: { | 58 | case GO_TO_POST: { |
59 | - let sid = state.sid + 1; | 59 | + |
60 | + let currentSid = state.sid; | ||
61 | + let newItems = state.items; | ||
62 | + let newSid = currentSid; | ||
63 | + // componentWillUnmount未调用,导致clean操作未进行 | ||
64 | + if (action.payload.tryToClean && currentSid > -1 && !state.cleaned) { | ||
65 | + newItems = newItems.pop(); | ||
66 | + newSid = newSid - 1; | ||
67 | + } | ||
68 | + | ||
69 | + let sid = newSid + 1; | ||
60 | // 获取新的初始状态item | 70 | // 获取新的初始状态item |
61 | let item = initialState.item; | 71 | let item = initialState.item; |
62 | // 设置item的value | 72 | // 设置item的value |
63 | - item = item.set('id', action.payload); | 73 | + item = item.set('id', action.payload.id); |
64 | // items新增item | 74 | // items新增item |
65 | - let newItems = state.items.push(item); | 75 | + newItems = newItems.push(item); |
66 | let nextState = state.set('sid', sid) | 76 | let nextState = state.set('sid', sid) |
67 | - .set('items', newItems); | 77 | + .set('items', newItems) |
78 | + .set('cleaned', false); | ||
68 | return nextState; | 79 | return nextState; |
69 | - // return state.set('id', action.payload); | ||
70 | } | 80 | } |
71 | 81 | ||
72 | case SUBJECT_CONTENT_REQUEST: { | 82 | case SUBJECT_CONTENT_REQUEST: { |
@@ -287,7 +297,8 @@ export default function postingReducer(state = initialState, action) { | @@ -287,7 +297,8 @@ export default function postingReducer(state = initialState, action) { | ||
287 | if (state.items.size > sid) { | 297 | if (state.items.size > sid) { |
288 | let items = state.items.pop(); | 298 | let items = state.items.pop(); |
289 | let nextState = state.set('sid', sid - 1) | 299 | let nextState = state.set('sid', sid - 1) |
290 | - .set('items', items); | 300 | + .set('items', items) |
301 | + .set('cleaned', true); | ||
291 | return nextState; | 302 | return nextState; |
292 | } | 303 | } |
293 | } | 304 | } |
@@ -28,15 +28,26 @@ export default function userThatNotMe(state = initialState, action) { | @@ -28,15 +28,26 @@ export default function userThatNotMe(state = initialState, action) { | ||
28 | 28 | ||
29 | switch (action.type) { | 29 | switch (action.type) { |
30 | case GO_TO_USER_THAT_NOT_ME: { | 30 | case GO_TO_USER_THAT_NOT_ME: { |
31 | - let sid = state.sid + 1; | 31 | + |
32 | + let currentSid = state.sid; | ||
33 | + let newItems = state.items; | ||
34 | + let newSid = currentSid; | ||
35 | + // componentWillUnmount未调用,导致clean操作未进行 | ||
36 | + if (action.payload.tryToClean && currentSid > -1 && !state.cleaned) { | ||
37 | + newItems = newItems.pop(); | ||
38 | + newSid = newSid - 1; | ||
39 | + } | ||
40 | + | ||
41 | + let sid = newSid + 1; | ||
32 | // 获取新的初始状态item | 42 | // 获取新的初始状态item |
33 | let item = initialState.item; | 43 | let item = initialState.item; |
34 | // 设置item的value | 44 | // 设置item的value |
35 | - item = item.setIn(['profile', 'uid'], action.payload); | 45 | + item = item.setIn(['profile', 'uid'], action.payload.uid); |
36 | // items新增item | 46 | // items新增item |
37 | - let newItems = state.items.push(item); | 47 | + newItems = newItems.push(item); |
38 | let nextState = state.set('sid', sid) | 48 | let nextState = state.set('sid', sid) |
39 | - .set('items', newItems); | 49 | + .set('items', newItems) |
50 | + .set('cleaned', false); | ||
40 | return nextState; | 51 | return nextState; |
41 | } | 52 | } |
42 | 53 | ||
@@ -106,7 +117,8 @@ export default function userThatNotMe(state = initialState, action) { | @@ -106,7 +117,8 @@ export default function userThatNotMe(state = initialState, action) { | ||
106 | if (state.items.size > sid) { | 117 | if (state.items.size > sid) { |
107 | let items = state.items.pop(); | 118 | let items = state.items.pop(); |
108 | let nextState = state.set('sid', sid - 1) | 119 | let nextState = state.set('sid', sid - 1) |
109 | - .set('items', items); | 120 | + .set('items', items) |
121 | + .set('cleaned', true); | ||
110 | return nextState; | 122 | return nextState; |
111 | } | 123 | } |
112 | } | 124 | } |
-
Please register or login to post a comment