列表页cell点击收藏后再点击进入详情页无法同步更新,从列表进入详情页使用的react-navigation方法传递参数的方法,除此之外其他代码编写同老师一样
来源:7-6 为Popular(最热)与Trending(趋势)模块的详情页添加收藏的功能
我是一颗尘土
2018-05-16
写回答
1回答
-
CrazyCodeBoy
2018-05-22
1.当点击Cell跳转的时候需要将带有收藏状态的projectModel传递到详情页:
renderRow(data) { const projectModel = data.item; return <RepositoryCell projectModel={projectModel} theme={this.props.theme} onSelect={() => ActionUtils.onSelectRepository({ projectModel: projectModel, flag: FLAG_STORAGE.flag_popular, ...this.props, onUpdateFavorite: () => this.onUpdateFavorite(), })} onFavorite={(item, isFavorite) => ActionUtils.onFavorite(favoriteDao, item, isFavorite)}/> }
2. 在详情页取出收藏状态:
this.params = this.props.navigation.state.params; let {projectModel} = this.params; this.url = projectModel.item.html_url ? projectModel.item.html_url : TRENDING_URL + projectModel.item.fullName; var title = projectModel.item.full_name ? projectModel.item.full_name : projectModel.item.fullName; this.favoriteDao = new FavoriteDao(this.params.flag); this.state = { url: this.url, canGoBack: false, title: title, isFavorite: projectModel.isFavorite, favoriteIcon: projectModel.isFavorite ? require('../../res/images/ic_star.png') : require('../../res/images/ic_star_navbar.png'), }
00
相似问题