Authored by 孙凯

add goodGroup 点击置顶效果 review by hongmo

... ... @@ -34,6 +34,8 @@ export default class Detail extends Component {
super(props);
this.renderRow = this.renderRow.bind(this);
this.renderHeader = this.renderHeader.bind(this);
this.scrollTo = this.scrollTo.bind(this);
this.listView = null;
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
... ... @@ -50,6 +52,16 @@ export default class Detail extends Component {
}
}
onLayout(rowID, e) {
let {y} = e.nativeEvent.layout;
this.props.onPressGoodY(y);
}
scrollTo(){
let {goods_group_y} = this.props.resource;
this.listView.scrollTo({x: 0, y: goods_group_y, animated: false});
}
renderHeader() {
let {resource} = this.props;
let {author,article} = resource;
... ... @@ -81,8 +93,8 @@ export default class Detail extends Component {
let list = data?data[goods_group_Filter]:null;
return (
<View style={styles.GoodsGroupHeader}>
<GoodsGroupHeader resource={{rowData,goods_group_Filter}} onPressFilter= {this.props.onPressFilter}/>
<View style={styles.GoodsGroupHeader} onLayout={this.onLayout.bind(this, rowID)}>
<GoodsGroupHeader resource={{rowData,goods_group_Filter}} onPressFilter= {this.props.onPressFilter} scrollTo={this.scrollTo}/>
<GoodsGroupList resource={list} onPressProduct={this.props.onPressProduct}/>
</View>
);
... ... @@ -135,6 +147,7 @@ export default class Detail extends Component {
return (
<ListView
ref={(ref)=>this.listView=ref}
contentContainerStyle={styles.contentContainer}
enableEmptySections={true}
showsVerticalScrollIndicator={false}
... ...
... ... @@ -46,6 +46,7 @@ export default class GoodsGroupHeader extends React.Component {
if (this.selectedIndex == rowID) {
return;
}
this.props.scrollTo && this.props.scrollTo();
this.props.onPressFilter && this.props.onPressFilter(rowID);
}}>
<View style={{width: itemW - 20,height: itemH - 20,borderColor: 'black',borderWidth: borderWidth}}>
... ...
... ... @@ -46,4 +46,5 @@ export default keyMirror({
GET_ARTICLE_LIST_FAILURE: null,
SET_GOOESGROUP_FILTER: null,
SET_GOOESGROUP_Y: null,
});
... ...
... ... @@ -54,7 +54,7 @@ class DetailContainer extends Component {
this._onPressMoreLink = this._onPressMoreLink.bind(this);
this._onPressProduct = this._onPressProduct.bind(this);
this._onPressWeixin = this._onPressWeixin.bind(this);
this._onPressGoodY = this._onPressGoodY.bind(this);
}
componentDidMount() {
... ... @@ -84,6 +84,10 @@ class DetailContainer extends Component {
this.props.actions.setGoodsGroupFilter(value);
}
_onPressGoodY(y) {
this.props.actions.setGoodsGroupY(y);
}
_onPressAuthor(url) {
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
... ... @@ -123,6 +127,7 @@ class DetailContainer extends Component {
onPressMoreLink={this._onPressMoreLink}
onPressProduct={this._onPressProduct}
onPressWeixin={this._onPressWeixin}
onPressGoodY={this._onPressGoodY}
/>
</View>
);
... ...
... ... @@ -38,6 +38,7 @@ const {
PRODUCT_BY_SKNS_FAILURE,
SET_GOOESGROUP_FILTER,
SET_GOOESGROUP_Y,
} = require('../../constants/actionTypes').default;
... ... @@ -557,3 +558,10 @@ export function setGoodsGroupFilter(filter) {
payload: filter
};
}
export function setGoodsGroupY(y) {
return {
type: SET_GOOESGROUP_Y,
payload: y
};
}
... ...
... ... @@ -35,6 +35,7 @@ let InitialState = Record({
data: List(),
})),
goods_group_Filter: 0,
goods_group_y: 0,
});
export default InitialState;
... ...
... ... @@ -33,6 +33,7 @@ const {
PRODUCT_BY_SKNS_SUCCESS,
SET_GOOESGROUP_FILTER,
SET_GOOESGROUP_Y,
} = require('../../constants/actionTypes').default;
... ... @@ -150,6 +151,9 @@ export default function detailReducer(state=initialState, action) {
case SET_GOOESGROUP_FILTER: {
return state.set('goods_group_Filter', action.payload);
}
case SET_GOOESGROUP_Y: {
return state.set('goods_group_y', action.payload);
}
}
return state;
... ...