Authored by chenl

增加了明星原创资讯相关点击事件。review by 孙凯。

... ... @@ -18,10 +18,11 @@ export default function native(platform) {
Classify(platform);
Seckill(platform);
Guang(platform);
Plustar(platform);
if (Platform.OS === 'ios') {
Community(platform);
Plustar(platform);
QRCode(platform);
} else {
... ...
... ... @@ -36,7 +36,6 @@ import {
import {
setBrandId,
setUdid,
setId,
} from './reducers/detail/detailActions';
... ... @@ -105,7 +104,6 @@ export default function native(platform) {
let id=this.props.id;
let udid=this.props.udid;
store.dispatch(setId(id));
store.dispatch(setUdid(udid));
return (
<Provider store={store}>
<DetailContainer />
... ...
... ... @@ -15,6 +15,8 @@ import ReactNative, {
NativeAppEventEmitter,
StyleSheet,
} from 'react-native';
import SingleImage from './SingleImage';
import {SlicedImage} from '../../../common/components/SlicedImage';
... ... @@ -27,30 +29,28 @@ export default class BrandArticleCell extends Component {
}
componentDidMount() {
}
//时间和访问次数以及是否喜欢
_renderTimeAndVisit(time, visit, likeNum, id, isliked){
_renderTimeAndVisit(time, visit, likeNum, id, rowID, isliked){
let likeicon = isliked ? require("../../images/like_on.png") : require("../../images/like_off.png");
let likestyle = isliked ? styles.darkgrayfont : styles.grayfont;
return (
<View style={styles.timebar}>
<Text style={styles.time} numberOfLines={1}>{time}&nbsp;&nbsp;&nbsp;&nbsp;</Text>
<Image style={styles.timeicon} source={require("../../images/time_icon.png")} />
<Text style={styles.grayfont} numberOfLines={1}>{time}&nbsp;&nbsp;&nbsp;&nbsp;</Text>
<Text style={styles.time} numberOfLines={1}>{visit}&nbsp;&nbsp;&nbsp;&nbsp;</Text>
<Image style={styles.eyeicon} source={require("../../images/eye_icon.png")} />
<Text style={styles.grayfont} numberOfLines={1}>{visit}&nbsp;&nbsp;&nbsp;&nbsp;</Text>
<TouchableOpacity
style={styles.likecontainer}
activeOpacity={1}
onPress={()=>{
this.props.onPressArticleLike && this.props.onPressArticleLike(id, !isliked)
this.props.onPressArticleLike && this.props.onPressArticleLike(id, rowID, !isliked, likeNum)
}}>
<Image style={styles.likeicon} source={likeicon} />
<Text style={styles.time} numberOfLines={1}>{likeNum}</Text>
<Text style={likestyle} numberOfLines={1}>{likeNum}</Text>
</TouchableOpacity>
... ... @@ -61,7 +61,7 @@ export default class BrandArticleCell extends Component {
render() {
let {rowData} = this.props;
let {rowData, rowID} = this.props;
//url跳转地址
let url = rowData.get('url');
//id
... ... @@ -69,9 +69,8 @@ export default class BrandArticleCell extends Component {
//标题
let title = rowData.get('title');
//图片
let imgUrl = rowData.get('src').replace('{mode}', 2).replace('{width}', 290).replace('{height}', 386);
//imgUrl = SlicedImage.getSlicedUrl(rowData.get('src'), 290, 386, 2);
//let brandIconUrl = SlicedImage.getSlicedUrl(data.get('brand_img', ''), 150, 80, 2);
let imgUrl = rowData.get('src').replace('{mode}', 2).replace('{width}', width).replace('{height}', width);
// let imgUrl = SlicedImage.getSlicedUrl(rowData.get('src'), width, width, 2);
//介绍
let intro = rowData.get('intro');
//发布时间
... ... @@ -79,11 +78,11 @@ export default class BrandArticleCell extends Component {
//访问次数
let viewsNum = rowData.get('views_num');
//喜欢信息
let like = rowData.get('like');
let likedata = rowData.get('like');
//是否喜欢
let isLiked = like.get("isLiked");
let isLiked = likedata ? likedata.get("isLiked") : false;
//喜欢人数
let likeCount = like.get("count");
let likeCount = likedata ? likedata.get("count") : "0";
return (
<View style={styles.cellContainer}>
... ... @@ -95,7 +94,7 @@ export default class BrandArticleCell extends Component {
this.props.onPressArticle && this.props.onPressArticle(url)
}}>
<Image style={styles.image} source={{uri:imgUrl}} />
<SingleImage source={imgUrl} />
<Text style={styles.title}>{title}</Text>
... ... @@ -103,7 +102,7 @@ export default class BrandArticleCell extends Component {
<Text style={styles.content} numberOfLines={4}>{intro}</Text>
{this._renderTimeAndVisit(publishTime, viewsNum, likeCount, id, isLiked)}
{this._renderTimeAndVisit(publishTime, viewsNum, likeCount, id, rowID, isLiked)}
</View>
... ... @@ -121,11 +120,10 @@ let styles = StyleSheet.create({
touchableContainer: {
width: width,
},
image: {
width: width,
height: width / 1.5,
},
// image: {
// width: width,
// height: Math.ceil(width * 410 / 655),
// },
title:{
width: width,
... ... @@ -139,24 +137,49 @@ let styles = StyleSheet.create({
content:{
width: width,
fontSize: 15,
color: '#999999',
color: '#3E3A39',
paddingLeft: 15,
paddingRight: 15,
paddingBottom:5,
},
timebar:{
width: width,
height: 30,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
paddingLeft: 15,
paddingRight: 15,
paddingBottom:5,
},
time:{
likecontainer:{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end',
},
grayfont:{
fontSize: 15,
color: '#b0b0b0',
color: '#A5A5A5',
marginLeft: 5,
},
darkgrayfont:{
fontSize: 15,
color: '#444444',
marginLeft: 5,
},
timeicon:{
width: 12,
height:12,
},
eyeicon:{
width: 16,
height:12,
marginLeft: 6,
},
likeicon:{
width: 20,
height:20,
width: 18,
height:17,
marginTop: 1,
},
});
... ...
... ... @@ -16,7 +16,6 @@ import ReactNative, {
TouchableOpacity,
} from 'react-native';
//import SlicedImage from '../../../common/components/SlicedImage';
import BrandArticleCell from './BrandArticleCell';
export default class BrandArticleList extends Component {
... ... @@ -64,22 +63,24 @@ export default class BrandArticleList extends Component {
render() {
let {articleList} = this.props;
return (
<View style={styles.container}>
<ListView
contentContainerStyle={styles.contentContainer}
dataSource={this.dataSource.cloneWithRows(articleList)}
renderRow={this._renderRow}
enableEmptySections = {true}
renderSeparator={this._renderSeparator}
onPressArticle={this.props.onPressArticle}
onPressArticleLike={this.props.onPressArticleLike}
renderHeader={this._renderHeader}
/>
if(articleList){
return (
<View style={styles.container}>
</View>
);
<ListView
contentContainerStyle={styles.contentContainer}
dataSource={this.dataSource.cloneWithRows(articleList)}
renderRow={this._renderRow}
enableEmptySections = {true}
renderSeparator={this._renderSeparator}
onPressArticle={this.props.onPressArticle}
onPressArticleLike={this.props.onPressArticleLike}
renderHeader={this._renderHeader}
/>
</View>
);
}
}
}
... ...
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
const {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ListView,
Dimensions,
TouchableOpacity,
} = ReactNative;
export default class SingleImage extends React.Component {
constructor(props) {
super(props);
this.state = {
width: Dimensions.get('window').width,
height: 0,
};
}
shouldComponentUpdate(nextProps,nextState){
if (Immutable.is(nextProps.source, this.props.source) && nextState.height==this.state.height) {
return false;
} else {
return true;
}
}
componentDidMount() {
let {source} = this.props;
Image.getSize(source, (width, height) => {
this.setState({width, height});
});
}
render() {
let {source} = this.props;
return (
<View style={{width: Dimensions.get('window').width,height: (this.state.height/this.state.width)*Dimensions.get('window').width}}>
<Image
source={{uri: source}}
style={{width: Dimensions.get('window').width,height: (this.state.height/this.state.width)*Dimensions.get('window').width}}
>
</Image>
</View>
);
return null;
}
};
let styles = StyleSheet.create({
});
... ...
... ... @@ -8,7 +8,6 @@ export default keyMirror({
SET_GENDER: null,
SET_ID: null,
SET_BRAND_ID:null,
SET_UDID:null,
SET_BRAND_INTRO_UNFOLD: null,
SET_MORE_PRODUCT_URL: null,
CLEAR_ADD_CANCEL_TIP: null,
... ... @@ -50,6 +49,7 @@ export default keyMirror({
CANCEL_FAVORITE_SUCCESS: null,
CANCEL_FAVORITE_FAILURE: null,
PRAISE_ARTICLE_CHANGE: null,
PRAISE_ARTICLE_REQUEST: null,
PRAISE_ARTICLE_SUCCESS: null,
PRAISE_ARTICLE_FAILURE: null,
... ...
... ... @@ -77,14 +77,11 @@ class DetailContainer extends Component {
}
_onPressArticle(url) {
console.log("chenlin", "_onPressArticle:URL:" + url);
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
_onPressArticleLike(id, isLiked) {
console.log("chenlin", "_onPressArticleLike:id" + id + ",isLiked:" + isLiked);
let opt = isLiked ? "ok" : "cancel";
this.props.actions.praiseArticle(id,opt);
_onPressArticleLike(id, index, isLiked, oldLikeNum) {
this.props.actions.praiseArticle(id, index, isLiked, oldLikeNum);
}
_onPressFav(bFav='true') {
... ...
... ... @@ -15,7 +15,6 @@ const {
SET_ID,
SET_BRAND_ID,
SET_GENDER,
SET_UDID,
SET_BRAND_INTRO_UNFOLD,
SET_MORE_PRODUCT_URL,
CLEAR_ADD_CANCEL_TIP,
... ... @@ -41,6 +40,7 @@ const {
CANCEL_FAVORITE_SUCCESS,
CANCEL_FAVORITE_FAILURE,
PRAISE_ARTICLE_CHANGE,
PRAISE_ARTICLE_REQUEST,
PRAISE_ARTICLE_SUCCESS,
PRAISE_ARTICLE_FAILURE,
... ... @@ -155,13 +155,6 @@ export function setGender(gender) {
};
}
export function setUdid(udid){
return {
type: SET_UDID,
payload:udid
};
}
export function addCanelFavTipRemove(){
return {
type: CLEAR_ADD_CANCEL_TIP
... ... @@ -436,10 +429,17 @@ export function praiseArticleRequest(){
};
}
export function praiseArticleSuccess(json){
export function praiseArticleChange(index, isLiked, likenum){
return {
type: PRAISE_ARTICLE_CHANGE,
payload:{index, isLiked, likenum}
};
}
export function praiseArticleSuccess(index, isLiked, likenum){
return {
type: PRAISE_ARTICLE_SUCCESS,
payload:json
payload:{index, isLiked, likenum}
};
}
... ... @@ -450,24 +450,23 @@ export function praiseArticleFailure(error){
};
}
export function praiseArticle(articleId, opt) {
export function praiseArticle(articleId, index, isLiked, oldLikeNum) {
return (dispatch, getState) => {
let {app, detail} = getState();
let {udid} = detail;
console.log("chenlin", "getState:" + JSON.stringify(getState()));
let newNum = isLiked ? parseInt(oldLikeNum) + 1 : parseInt(oldLikeNum) - 1;
let articleRequest = (articleId, udid, opt) => {
dispatch(praiseArticleRequest());
return new DetailService(app.servicehost).praiseArticle(articleId, udid, opt)
let articleRequest = (articleId, isLiked) => {
dispatch(praiseArticleChange(index, isLiked, newNum));
return new DetailService(app.servicehost).praiseArticle(articleId, isLiked)
.then(json=>{
dispatch(praiseArticleSuccess(json));
dispatch(praiseArticleSuccess(index, isLiked, json));
})
.catch(error=>{
dispatch(praiseArticleFailure(error));
});
}
articleRequest(articleId, udid, opt);
articleRequest(articleId, isLiked);
};
}
... ...
... ... @@ -12,7 +12,6 @@ const {
SET_ID,
SET_BRAND_ID,
SET_GENDER,
SET_UDID,
SET_BRAND_INTRO_UNFOLD,
SET_MORE_PRODUCT_URL,
CLEAR_ADD_CANCEL_TIP,
... ... @@ -37,6 +36,7 @@ const {
CANCEL_FAVORITE_SUCCESS,
CANCEL_FAVORITE_FAILURE,
PRAISE_ARTICLE_CHANGE,
PRAISE_ARTICLE_REQUEST,
PRAISE_ARTICLE_SUCCESS,
PRAISE_ARTICLE_FAILURE,
... ... @@ -66,9 +66,6 @@ export default function plustarReducer(state=initialState, action) {
case SET_BRAND_ID:{
return state.set('brandId', action.payload);
}
case SET_UDID:{
return state.set('udid', action.payload);
}
case SET_BRAND_INTRO_UNFOLD:{
return state.setIn(['brandInfo', 'titleUnfold'], action.payload);
}
... ... @@ -84,11 +81,14 @@ export default function plustarReducer(state=initialState, action) {
case ARTICLE_BY_BRAND_SUCCESS:{
return state.set('articleList', Immutable.fromJS(action.payload));
}
case PRAISE_ARTICLE_SUCCESS:{
console.log("chenlin", "PRAISE_ARTICLE_SUCCESS:" + JSON.stringify(action.payload));
case PRAISE_ARTICLE_CHANGE:{
let {index, isLiked, likenum} = action.payload;
let like = {isLiked: isLiked, count: likenum};
return state.setIn(['articleList', index, 'like'], Immutable.fromJS(like));
}
case PRAISE_ARTICLE_SUCCESS:
case PRAISE_ARTICLE_FAILURE:{
console.log("chenlin", "PRAISE_ARTICLE_FAILURE:" + JSON.stringify(action.payload));
return state;
}
case BRADN_FAV_REQUEST:{
return state.setIn(['brandFav', 'isFetching'], true)
... ...
... ... @@ -71,11 +71,7 @@ export default class DetailService {
url: '/guang/service/v1/article/getArticleByBrand',
body: {
brand_id: brandId,
uid: uid,
udid: udid,
// client_type: clientType,
// limit: 3,
// private_key: privateKeyList[clientType],
limit: 3,
}
})
.then((json) => {
... ... @@ -140,18 +136,18 @@ export default class DetailService {
});
}
//点赞,opt:ok表示点赞,cancel表示取消点赞
async praiseArticle(id, udid, opt='ok') {
//点赞,isLiked:true表示点赞,false表示取消点赞
async praiseArticle(id, isLiked) {
let url = isLiked ? '/guang/api/v2/praise/setPraise' : '/guang/api/v2/praise/cancel';
return await this.api.post({
url: '/guang/opt/praiseArticle',
url: url,
body: {
id: id,
udid: udid,
opt: opt
article_id: id,
}
})
.then((json) => {
console.log("chenlin", "点赞返回数据:" + JSON.stringify(json));
return json;
})
.catch((error) => {
... ...