优化回调方法调用 review by 盖剑秋
Showing
9 changed files
with
49 additions
and
87 deletions
@@ -170,11 +170,12 @@ export default function community(platform) { | @@ -170,11 +170,12 @@ export default function community(platform) { | ||
170 | rightButtonImage={rightImage} | 170 | rightButtonImage={rightImage} |
171 | onRight={this.homeOnRight} | 171 | onRight={this.homeOnRight} |
172 | renderTitle={this.contanerIsYohoBuy() ? this.renderHomeTitle : null} | 172 | renderTitle={this.contanerIsYohoBuy() ? this.renderHomeTitle : null} |
173 | - getPostingState={ | ||
174 | - () => { | ||
175 | - return store.getState().posting.inPosting; | ||
176 | - } | ||
177 | - } | 173 | + getPostingState={() => { |
174 | + return store.getState().posting.inPosting; | ||
175 | + }} | ||
176 | + getSceneStyle={(props) => { | ||
177 | + return this.navPushStyle(props); | ||
178 | + }} | ||
178 | /> | 179 | /> |
179 | 180 | ||
180 | <Scene | 181 | <Scene |
@@ -206,6 +207,9 @@ export default function community(platform) { | @@ -206,6 +207,9 @@ export default function community(platform) { | ||
206 | hideNavBar={true} | 207 | hideNavBar={true} |
207 | component={UserContainer} | 208 | component={UserContainer} |
208 | initial={false} | 209 | initial={false} |
210 | + getSceneStyle={(props) => { | ||
211 | + return this.navPushStyle(props); | ||
212 | + }} | ||
209 | /> | 213 | /> |
210 | 214 | ||
211 | <Scene | 215 | <Scene |
@@ -242,6 +246,9 @@ export default function community(platform) { | @@ -242,6 +246,9 @@ export default function community(platform) { | ||
242 | clone={true} | 246 | clone={true} |
243 | component={UserThatNotMeContainer} | 247 | component={UserThatNotMeContainer} |
244 | initial={false} | 248 | initial={false} |
249 | + getSceneStyle={(props) => { | ||
250 | + return this.navPushStyle(props); | ||
251 | + }} | ||
245 | /> | 252 | /> |
246 | 253 | ||
247 | 254 |
@@ -64,21 +64,11 @@ export default class CommunityList extends React.Component { | @@ -64,21 +64,11 @@ export default class CommunityList extends React.Component { | ||
64 | <ListCell | 64 | <ListCell |
65 | key={sectionID + rowID} | 65 | key={sectionID + rowID} |
66 | data={rowData} | 66 | data={rowData} |
67 | - onPressPost={() => { | ||
68 | - this.props.onPressPost && this.props.onPressPost(rowData.get('id')); | ||
69 | - }} | ||
70 | - onPressAvatar={(url) => { | ||
71 | - this.props.onPressAvatar && this.props.onPressAvatar(url); | ||
72 | - }} | ||
73 | - onPressSectionTag={() => { | ||
74 | - this.props.onPressSectionTag && this.props.onPressSectionTag(rowData.get('section').toJS()); | ||
75 | - }} | ||
76 | - onPressComment={() => { | ||
77 | - this.props.onPressComment && this.props.onPressComment(rowData.get('id')); | ||
78 | - }} | ||
79 | - onPressLike={() => { | ||
80 | - this.props.onPressLike && this.props.onPressLike(rowData); | ||
81 | - }} | 67 | + onPressPost={this.props.onPressPost} |
68 | + onPressAvatar={this.props.onPressAvatar} | ||
69 | + onPressSectionTag={this.props.onPressSectionTag} | ||
70 | + onPressComment={this.props.onPressComment} | ||
71 | + onPressLike={this.props.onPressLike} | ||
82 | /> | 72 | /> |
83 | ); | 73 | ); |
84 | } | 74 | } |
@@ -99,6 +89,7 @@ export default class CommunityList extends React.Component { | @@ -99,6 +89,7 @@ export default class CommunityList extends React.Component { | ||
99 | renderSeparator={this._renderSeparator} | 89 | renderSeparator={this._renderSeparator} |
100 | enableEmptySections={true} | 90 | enableEmptySections={true} |
101 | scrollEnabled={false} | 91 | scrollEnabled={false} |
92 | + onEndReached={() => {}} | ||
102 | /> | 93 | /> |
103 | ); | 94 | ); |
104 | 95 |
@@ -180,9 +180,7 @@ export default class Home extends React.Component { | @@ -180,9 +180,7 @@ export default class Home extends React.Component { | ||
180 | duration={this.props.bannerDuration} | 180 | duration={this.props.bannerDuration} |
181 | width={width} | 181 | width={width} |
182 | height={bannerHeight} | 182 | height={bannerHeight} |
183 | - onPress={(url) => { | ||
184 | - this.props.onPressBanner && this.props.onPressBanner(url); | ||
185 | - }} | 183 | + onPress={this.props.onPressBanner} |
186 | /> | 184 | /> |
187 | ); | 185 | ); |
188 | } | 186 | } |
@@ -193,9 +191,7 @@ export default class Home extends React.Component { | @@ -193,9 +191,7 @@ export default class Home extends React.Component { | ||
193 | duration={this.props.noticeDuration} | 191 | duration={this.props.noticeDuration} |
194 | width={width} | 192 | width={width} |
195 | height={40} | 193 | height={40} |
196 | - onPress={(url) => { | ||
197 | - this.props.onPressNotice && this.props.onPressNotice(url); | ||
198 | - }} | 194 | + onPress={this.props.onPressNotice} |
199 | /> | 195 | /> |
200 | ); | 196 | ); |
201 | case 'section': | 197 | case 'section': |
@@ -218,21 +214,11 @@ export default class Home extends React.Component { | @@ -218,21 +214,11 @@ export default class Home extends React.Component { | ||
218 | <ListCell | 214 | <ListCell |
219 | key={sectionID + rowID} | 215 | key={sectionID + rowID} |
220 | data={rowData} | 216 | data={rowData} |
221 | - onPressPost={() => { | ||
222 | - this.props.onPressPost && this.props.onPressPost(rowData.get('id')); | ||
223 | - }} | ||
224 | - onPressAvatar={() => { | ||
225 | - this.props.onPressAvatar && this.props.onPressAvatar(rowData.get('author').get('uid')); | ||
226 | - }} | ||
227 | - onPressSectionTag={() => { | ||
228 | - this.props.onPressSectionTag && this.props.onPressSectionTag(rowData.get('section').toJS()); | ||
229 | - }} | ||
230 | - onPressComment={() => { | ||
231 | - this.props.onPressComment && this.props.onPressComment(rowData.get('id')); | ||
232 | - }} | ||
233 | - onPressLike={() => { | ||
234 | - this.props.onPressLike && this.props.onPressLike(rowData); | ||
235 | - }} | 217 | + onPressPost={this.props.onPressPost} |
218 | + onPressAvatar={this.props.onPressAvatar} | ||
219 | + onPressSectionTag={this.props.onPressSectionTag} | ||
220 | + onPressComment={this.props.onPressComment} | ||
221 | + onPressLike={this.props.onPressLike} | ||
236 | /> | 222 | /> |
237 | ); | 223 | ); |
238 | } | 224 | } |
@@ -30,6 +30,7 @@ export default class ListCell extends React.Component { | @@ -30,6 +30,7 @@ export default class ListCell extends React.Component { | ||
30 | isOwner: React.PropTypes.bool, | 30 | isOwner: React.PropTypes.bool, |
31 | isTop: React.PropTypes.bool, | 31 | isTop: React.PropTypes.bool, |
32 | isLike: React.PropTypes.bool, | 32 | isLike: React.PropTypes.bool, |
33 | + id: React.PropTypes.number, | ||
33 | title: React.PropTypes.string, | 34 | title: React.PropTypes.string, |
34 | desc: React.PropTypes.string, | 35 | desc: React.PropTypes.string, |
35 | thumbs: ImmutablePropTypes.listOf( | 36 | thumbs: ImmutablePropTypes.listOf( |
@@ -58,7 +59,7 @@ export default class ListCell extends React.Component { | @@ -58,7 +59,7 @@ export default class ListCell extends React.Component { | ||
58 | 59 | ||
59 | render() { | 60 | render() { |
60 | let data = this.props.data.toJS(); | 61 | let data = this.props.data.toJS(); |
61 | - let {author, timeago, isOwner, isTop, isLike, title, desc, thumbs, section, commentCount, likeCount} = data; | 62 | + let {author, timeago, isOwner, isTop, isLike, id, title, desc, thumbs, section, commentCount, likeCount} = data; |
62 | let likeImage = isLike ? require('../../images/home/like.png') : require('../../images/home/unlike.png'); | 63 | let likeImage = isLike ? require('../../images/home/like.png') : require('../../images/home/unlike.png'); |
63 | 64 | ||
64 | return ( | 65 | return ( |
@@ -66,10 +67,9 @@ export default class ListCell extends React.Component { | @@ -66,10 +67,9 @@ export default class ListCell extends React.Component { | ||
66 | style={styles.row} | 67 | style={styles.row} |
67 | activeOpacity={0.8} | 68 | activeOpacity={0.8} |
68 | onPress={() => { | 69 | onPress={() => { |
69 | - this.props.onPressPost && this.props.onPressPost(); | 70 | + this.props.onPressPost && this.props.onPressPost(id); |
70 | }} | 71 | }} |
71 | > | 72 | > |
72 | - | ||
73 | <View style={styles.top}> | 73 | <View style={styles.top}> |
74 | <UserBrief | 74 | <UserBrief |
75 | avatar={author.avatar} | 75 | avatar={author.avatar} |
@@ -77,7 +77,7 @@ export default class ListCell extends React.Component { | @@ -77,7 +77,7 @@ export default class ListCell extends React.Component { | ||
77 | timeago={timeago} | 77 | timeago={timeago} |
78 | isOwner={isOwner} | 78 | isOwner={isOwner} |
79 | onPressAvatar={() => { | 79 | onPressAvatar={() => { |
80 | - this.props.onPressAvatar && this.props.onPressAvatar(); | 80 | + this.props.onPressAvatar && this.props.onPressAvatar(author.uid); |
81 | }} | 81 | }} |
82 | /> | 82 | /> |
83 | {isTop ? <Text style={styles.topTag}>置顶</Text> : null} | 83 | {isTop ? <Text style={styles.topTag}>置顶</Text> : null} |
@@ -89,7 +89,7 @@ export default class ListCell extends React.Component { | @@ -89,7 +89,7 @@ export default class ListCell extends React.Component { | ||
89 | <SectionItem | 89 | <SectionItem |
90 | name={section.name} | 90 | name={section.name} |
91 | onPressSection={() => { | 91 | onPressSection={() => { |
92 | - this.props.onPressSectionTag && this.props.onPressSectionTag(); | 92 | + this.props.onPressSectionTag && this.props.onPressSectionTag(section); |
93 | }} | 93 | }} |
94 | /> | 94 | /> |
95 | <View style={styles.buttonContainer}> | 95 | <View style={styles.buttonContainer}> |
@@ -97,7 +97,7 @@ export default class ListCell extends React.Component { | @@ -97,7 +97,7 @@ export default class ListCell extends React.Component { | ||
97 | source={require('../../images/home/mes.png')} | 97 | source={require('../../images/home/mes.png')} |
98 | number={commentCount} | 98 | number={commentCount} |
99 | onPressButton={() => { | 99 | onPressButton={() => { |
100 | - this.props.onPressComment && this.props.onPressComment(); | 100 | + this.props.onPressComment && this.props.onPressComment(id); |
101 | }} | 101 | }} |
102 | /> | 102 | /> |
103 | <NumberButton | 103 | <NumberButton |
@@ -105,7 +105,7 @@ export default class ListCell extends React.Component { | @@ -105,7 +105,7 @@ export default class ListCell extends React.Component { | ||
105 | source={likeImage} | 105 | source={likeImage} |
106 | number={likeCount} | 106 | number={likeCount} |
107 | onPressButton={() => { | 107 | onPressButton={() => { |
108 | - this.props.onPressLike && this.props.onPressLike(); | 108 | + this.props.onPressLike && this.props.onPressLike(data); |
109 | }} | 109 | }} |
110 | /> | 110 | /> |
111 | </View> | 111 | </View> |
@@ -179,9 +179,7 @@ export default class Section extends React.Component { | @@ -179,9 +179,7 @@ export default class Section extends React.Component { | ||
179 | duration={this.props.noticeDuration} | 179 | duration={this.props.noticeDuration} |
180 | width={width} | 180 | width={width} |
181 | height={40} | 181 | height={40} |
182 | - onPress={(url) => { | ||
183 | - this.props.onPressNotice && this.props.onPressNotice(url); | ||
184 | - }} | 182 | + onPress={this.props.onPressNotice} |
185 | /> | 183 | /> |
186 | ); | 184 | ); |
187 | case 'list': | 185 | case 'list': |
@@ -68,21 +68,11 @@ export default class SectionList extends React.Component { | @@ -68,21 +68,11 @@ export default class SectionList extends React.Component { | ||
68 | <ListCell | 68 | <ListCell |
69 | key={rowID} | 69 | key={rowID} |
70 | data={rowData} | 70 | data={rowData} |
71 | - onPressPost={() => { | ||
72 | - this.props.onPressPost && this.props.onPressPost(rowData.get('id')); | ||
73 | - }} | ||
74 | - onPressAvatar={() => { | ||
75 | - this.props.onPressAvatar && this.props.onPressAvatar(rowData.get('author').get('uid')); | ||
76 | - }} | ||
77 | - onPressSectionTag={() => { | ||
78 | - this.props.onPressSectionTag && this.props.onPressSectionTag(rowData.get('section').toJS()); | ||
79 | - }} | ||
80 | - onPressComment={() => { | ||
81 | - this.props.onPressComment && this.props.onPressComment(rowData.get('id')); | ||
82 | - }} | ||
83 | - onPressLike={() => { | ||
84 | - this.props.onPressLike && this.props.onPressLike(rowData); | ||
85 | - }} | 71 | + onPressPost={this.props.onPressPost} |
72 | + onPressAvatar={this.props.onPressAvatar} | ||
73 | + onPressSectionTag={this.props.onPressSectionTag} | ||
74 | + onPressComment={this.props.onPressComment} | ||
75 | + onPressLike={this.props.onPressLike} | ||
86 | /> | 76 | /> |
87 | ); | 77 | ); |
88 | } | 78 | } |
@@ -102,9 +92,7 @@ export default class SectionList extends React.Component { | @@ -102,9 +92,7 @@ export default class SectionList extends React.Component { | ||
102 | renderSeparator={this._renderSeparator} | 92 | renderSeparator={this._renderSeparator} |
103 | enableEmptySections={true} | 93 | enableEmptySections={true} |
104 | scrollEnabled={false} | 94 | scrollEnabled={false} |
105 | - onEndReached={() => { | ||
106 | - | ||
107 | - }} | 95 | + onEndReached={() => {}} |
108 | /> | 96 | /> |
109 | ); | 97 | ); |
110 | 98 |
@@ -55,6 +55,7 @@ export default class User extends React.Component { | @@ -55,6 +55,7 @@ export default class User extends React.Component { | ||
55 | isOwner: React.PropTypes.bool, | 55 | isOwner: React.PropTypes.bool, |
56 | isTop: React.PropTypes.bool, | 56 | isTop: React.PropTypes.bool, |
57 | isLike: React.PropTypes.bool, | 57 | isLike: React.PropTypes.bool, |
58 | + id: React.PropTypes.number, | ||
58 | title: React.PropTypes.string, | 59 | title: React.PropTypes.string, |
59 | desc: React.PropTypes.string, | 60 | desc: React.PropTypes.string, |
60 | thumbs: ImmutablePropTypes.listOf( | 61 | thumbs: ImmutablePropTypes.listOf( |
@@ -81,6 +82,7 @@ export default class User extends React.Component { | @@ -81,6 +82,7 @@ export default class User extends React.Component { | ||
81 | isOwner: React.PropTypes.bool, | 82 | isOwner: React.PropTypes.bool, |
82 | isTop: React.PropTypes.bool, | 83 | isTop: React.PropTypes.bool, |
83 | isLike: React.PropTypes.bool, | 84 | isLike: React.PropTypes.bool, |
85 | + id: React.PropTypes.number, | ||
84 | title: React.PropTypes.string, | 86 | title: React.PropTypes.string, |
85 | desc: React.PropTypes.string, | 87 | desc: React.PropTypes.string, |
86 | thumbs: ImmutablePropTypes.listOf( | 88 | thumbs: ImmutablePropTypes.listOf( |
@@ -123,21 +123,11 @@ export default class UserThatNotMe extends React.Component { | @@ -123,21 +123,11 @@ export default class UserThatNotMe extends React.Component { | ||
123 | <ListCell | 123 | <ListCell |
124 | key={sectionID + rowID} | 124 | key={sectionID + rowID} |
125 | data={rowData} | 125 | data={rowData} |
126 | - onPressPost={() => { | ||
127 | - this.props.onPressPost && this.props.onPressPost(rowData.get('id')); | ||
128 | - }} | ||
129 | - onPressAvatar={() => { | ||
130 | - this.props.onPressAvatar && this.props.onPressAvatar(rowData.get('author').get('uid')); | ||
131 | - }} | ||
132 | - onPressSectionTag={() => { | ||
133 | - this.props.onPressSectionTag && this.props.onPressSectionTag(rowData.get('section').toJS()); | ||
134 | - }} | ||
135 | - onPressComment={() => { | ||
136 | - this.props.onPressComment && this.props.onPressComment(rowData.get('id')); | ||
137 | - }} | ||
138 | - onPressLike={() => { | ||
139 | - this.props.onPressLike && this.props.onPressLike(rowData); | ||
140 | - }} | 126 | + onPressPost={this.props.onPressPost} |
127 | + onPressAvatar={this.props.onPressAvatar} | ||
128 | + onPressSectionTag={this.props.onPressSectionTag} | ||
129 | + onPressComment={this.props.onPressComment} | ||
130 | + onPressLike={this.props.onPressLike} | ||
141 | /> | 131 | /> |
142 | ); | 132 | ); |
143 | default: | 133 | default: |
@@ -100,10 +100,10 @@ export function likeOperation(post) { | @@ -100,10 +100,10 @@ export function likeOperation(post) { | ||
100 | return (dispatch, getState) => { | 100 | return (dispatch, getState) => { |
101 | 101 | ||
102 | let operation = () => { | 102 | let operation = () => { |
103 | - if (post.get('isLike')) { | ||
104 | - dispatch(postUnlike(post.get('id'))); | 103 | + if (post.isLike) { |
104 | + dispatch(postUnlike(post.id)); | ||
105 | } else { | 105 | } else { |
106 | - dispatch(postLike(post.get('id'))); | 106 | + dispatch(postLike(post.id)); |
107 | } | 107 | } |
108 | }; | 108 | }; |
109 | 109 |
-
Please register or login to post a comment