Authored by 于良

品牌增加下拉刷新 review by 孙凯

... ... @@ -22,6 +22,7 @@ import BrandSearch from './search/BrandSearch';
import LoadingIndicator from '../../../common/components/LoadingIndicator';
import IndexListView from './IndexListView';
import {ScrollCount} from '../../utils/Utils';
import NoNetworkTip from '../../../common/components/NoNetworkTip';
export default class Brand extends Component {
constructor(props) {
... ... @@ -133,6 +134,9 @@ export default class Brand extends Component {
let {
showSearch,
isFetching,
listError,
reourceFetching,
reourceError,
brandFliter,
selectedChannelId,
brandListForBoy,
... ... @@ -147,18 +151,47 @@ export default class Brand extends Component {
search,
} = this.props;
let data;
let data = brandListForBoy;
let reource = reourceForBoy;
if (selectedChannelId == 1) {
data = brandListForBoy;
reource = reourceForBoy;
} else if (selectedChannelId == 2) {
data = brandListForGirl;
reource = reourceForGirl;
} else if (selectedChannelId == 3) {
data = brandListForKid;
reource = reourceForKid;
} else if (selectedChannelId == 4) {
data = brandListForLifeStyle;
reource = reourceForLifeStyle;
}
let showLoading = (isFetching && data.get('all_list').size == 0)
|| (reourceFetching && reource.get('banner').size == 0 && reource.get('custom_brands').size == 0);
if (showLoading) {
return (
<View style={styles.container}>
<ChannelSelector selectedChannelId={selectedChannelId} onSelectChannel={this.props.onSelectChannel}/>
<LoadingIndicator
isVisible={showLoading}
/>
</View>
);
} else if (listError && data.get('all_list').size == 0 && reource.get('banner').size == 0 && reource.get('custom_brands').size == 0) {
return (
<View style={styles.container}>
<ChannelSelector selectedChannelId={selectedChannelId} onSelectChannel={this.props.onSelectChannel}/>
<NoNetworkTip
onPressReload={this.props.onRefresh}
/>
</View>
);
}
let list;
let listDataSource;
let contentContainerStyle;
... ... @@ -195,6 +228,8 @@ export default class Brand extends Component {
if (!list) {
return null;
}
let isPullToRefresh = isFetching || reourceFetching;
return (
<View style={styles.container}>
... ... @@ -210,14 +245,15 @@ export default class Brand extends Component {
showsVerticalScrollIndicator={showsVerticalScrollIndicator}
renderSectionHeader={renderSectionHeader}
renderHeader={this.renderHeader}
enablePullToRefresh={true}
isOnPullToRefresh={isPullToRefresh}
onRefreshData={() => {
this.props.onRefresh && this.props.onRefresh();
}}
/>
{showIndexForListView ? <IndexListView dataSource={list.keySeq().toArray()} onLetterPress={this.scrollToSection}/> : null}
<LoadingIndicator
isVisible={isFetching}
/>
{showSearch ? <BrandSearch
data={search}
onTextChange={this.props.onTextChange}
... ...
... ... @@ -61,6 +61,7 @@ class BrandContainer extends Component {
this._setInitialListSize = this._setInitialListSize.bind(this);
this._onPressBrandItem = this._onPressBrandItem.bind(this);
this._onPressSearchHistoryItem = this._onPressSearchHistoryItem.bind(this);
this.onRefresh = this.onRefresh.bind(this);
this.subscription = NativeAppEventEmitter.addListener(
... ... @@ -105,6 +106,14 @@ class BrandContainer extends Component {
this.subscription && this.subscription.remove();
}
onRefresh() {
let {selectedChannelId} = this.props.brand;
this.props.actions.getBrandList(selectedChannelId);
this.props.actions.getBrandResource(selectedChannelId);
this.props.actions.searchHistory();
this.props.actions.hotKeyword();
}
//原生跳转
_onPressBrandItem(data, fromSearch=false){
ReactNative.NativeModules.YH_CommonHelper.pushBrandVC(data);
... ... @@ -357,6 +366,9 @@ class BrandContainer extends Component {
showSearch,
initialListSize,
isFetching,
listError,
reourceFetching,
reourceError,
selectedChannelId,
brandFliter,
brandListForBoy,
... ... @@ -376,6 +388,9 @@ class BrandContainer extends Component {
<View style={styles.container}>
<Brand
isFetching={isFetching}
listError={listError}
reourceFetching={reourceFetching}
reourceError={reourceError}
initialListSize={initialListSize}
selectedChannelId={selectedChannelId}
abversion={abversion}
... ... @@ -403,6 +418,7 @@ class BrandContainer extends Component {
setInitialListSize={this._setInitialListSize}
onPressBrandItem={this._onPressBrandItem}
onPressSearchHistoryItem={this._onPressSearchHistoryItem}
onRefresh={this.onRefresh}
/>
</View>
);
... ...
... ... @@ -2,63 +2,40 @@
import {Record, List, Map} from 'immutable';
let listData = Record({
all_list: Map(),
all_list_key: Map(),
hot_list: List(),
new_list: List(),
hasSuccess: false,
});
let reourceData = Record({
banner: Map(),
custom_brands: Map(),
brandsText: List(),
hasSuccess: false,
});
let InitialState = Record({
isFetching: false,
brandFliter: 0,
selectedChannelId: 1,
initialListSize: 0,
brandListForBoy: new (Record({
all_list: Map(),
all_list_key: Map(),
hot_list: List(),
new_list: List(),
hasSuccess: false,
})),
brandListForGirl: new (Record({
all_list: Map(),
hot_list: List(),
new_list: List(),
all_list_key: Map(),
hasSuccess: false,
})),
brandListForKid: new (Record({
all_list: Map(),
hot_list: List(),
all_list_key: Map(),
new_list: List(),
hasSuccess: false,
})),
brandListForLifeStyle: new (Record({
all_list: Map(),
hot_list: List(),
all_list_key: Map(),
new_list: List(),
hasSuccess: false,
})),
reourceForBoy: new (Record({
banner: Map(),
custom_brands: Map(),
brandsText: List(),
hasSuccess: false,
})),
reourceForGirl: new (Record({
banner: Map(),
custom_brands: Map(),
brandsText: List(),
hasSuccess: false,
})),
reourceForKid: new (Record({
banner: Map(),
custom_brands: Map(),
brandsText: List(),
hasSuccess: false,
})),
reourceForLifeStyle: new (Record({
banner: Map(),
custom_brands: Map(),
brandsText: List(),
hasSuccess: false,
})),
isFetching: false,
listError: null,
brandListForBoy: new listData,
brandListForGirl: new listData,
brandListForKid: new listData,
brandListForLifeStyle: new listData,
reourceFetching: false,
reourceError: null,
reourceForBoy: new reourceData,
reourceForGirl: new reourceData,
reourceForKid: new reourceData,
reourceForLifeStyle: new reourceData,
showSearch: false,
search: new (Record({
history: List(),
... ...
... ... @@ -73,7 +73,8 @@ export default function brandReducer(state=initialState, action) {
case GET_BRAND_LIST_FOR_BOY_REQUEST:
{
return state.set('isFetching', true);
return state.set('isFetching', true)
.set('listError', null);
}
case GET_BRAND_LIST_FOR_BOY_SUCCESS:
{
... ... @@ -89,17 +90,20 @@ export default function brandReducer(state=initialState, action) {
.setIn(['brandListForBoy', 'new_list'], Immutable.fromJS(new_list))
.setIn(['brandListForBoy', 'all_list_key'], Immutable.fromJS(all_list_key))
.setIn(['brandListForBoy', 'hasSuccess'], true)
.set('isFetching', false);
.set('isFetching', false)
.set('listError', null);
}
case GET_BRAND_LIST_FOR_BOY_FAILURE:
{
return state.setIn(['brandListForBoy', 'hasSuccess'], false)
.set('isFetching', false);
.set('isFetching', false)
.set('listError', action.payload);
}
case GET_BRAND_LIST_FOR_GIRL_REQUEST:
{
return state.set('isFetching', true);
return state.set('isFetching', true)
.set('listError', null);
}
case GET_BRAND_LIST_FOR_GIRL_SUCCESS:
{
... ... @@ -115,16 +119,19 @@ export default function brandReducer(state=initialState, action) {
.setIn(['brandListForGirl', 'new_list'], Immutable.fromJS(new_list))
.setIn(['brandListForGirl', 'all_list_key'], Immutable.fromJS(all_list_key))
.setIn(['brandListForGirl', 'hasSuccess'], true)
.set('isFetching', false);
.set('isFetching', false)
.set('listError', null);
}
case GET_BRAND_LIST_FOR_GIRL_FAILURE:
{
return state.setIn(['brandListForGirl', 'hasSuccess'], false)
.set('isFetching', false);
.set('isFetching', false)
.set('listError', action.payload);
}
case GET_BRAND_LIST_FOR_KID_REQUEST:
{
return state.set('isFetching', true);
return state.set('isFetching', true)
.set('listError', null);
}
case GET_BRAND_LIST_FOR_KID_SUCCESS:
{
... ... @@ -140,16 +147,19 @@ export default function brandReducer(state=initialState, action) {
.setIn(['brandListForKid', 'new_list'], Immutable.fromJS(new_list))
.setIn(['brandListForKid', 'all_list_key'], Immutable.fromJS(all_list_key))
.setIn(['brandListForKid', 'hasSuccess'], true)
.set('isFetching', false);
.set('isFetching', false)
.set('listError', null);
}
case GET_BRAND_LIST_FOR_KID_FAILURE:
{
return state.setIn(['brandListForKid', 'hasSuccess'], false)
.set('isFetching', false);
.set('isFetching', false)
.set('listError', action.payload);
}
case GET_BRAND_LIST_FOR_LIFESTYLE_REQUEST:
{
return state.set('isFetching', true);
return state.set('isFetching', true)
.set('listError', null);
}
case GET_BRAND_LIST_FOR_LIFESTYLE_SUCCESS:
{
... ... @@ -165,16 +175,19 @@ export default function brandReducer(state=initialState, action) {
.setIn(['brandListForLifeStyle', 'new_list'], Immutable.fromJS(new_list))
.setIn(['brandListForLifeStyle', 'all_list_key'], Immutable.fromJS(all_list_key))
.setIn(['brandListForLifeStyle', 'hasSuccess'], true)
.set('isFetching', false);
.set('isFetching', false)
.set('listError', null);
}
case GET_BRAND_LIST_FOR_LIFESTYLE_FAILURE:
{
return state.setIn(['brandListForLifeStyle', 'hasSuccess'], false)
.set('isFetching', false);
.set('isFetching', false)
.set('listError', action.payload);
}
case GET_BRAND_RESOURCE_FOR_BOY_REQUEST:
{
return state;
return state.set('reourceFetching', true)
.set('reourceError', null);
}
case GET_BRAND_RESOURCE_FOR_BOY_SUCCESS:
{
... ... @@ -184,19 +197,24 @@ export default function brandReducer(state=initialState, action) {
brandsText,
} = action.payload;
return state.setIn(['reourceForBoy', 'banner'], Immutable.fromJS(banner))
return state.set('reourceFetching', false)
.set('reourceError', null)
.setIn(['reourceForBoy', 'banner'], Immutable.fromJS(banner))
.setIn(['reourceForBoy', 'custom_brands'], Immutable.fromJS(custom_brands))
.setIn(['reourceForBoy', 'brandsText'], Immutable.fromJS(brandsText))
.setIn(['reourceForBoy', 'hasSuccess'], true);
}
case GET_BRAND_RESOURCE_FOR_BOY_FAILURE:
{
return state.setIn(['reourceForBoy', 'hasSuccess'], false);
return state.set('reourceFetching', false)
.set('reourceError', action.payload)
.setIn(['reourceForBoy', 'hasSuccess'], false);
}
case GET_BRAND_RESOURCE_FOR_GIRL_REQUEST:
{
return state;
return state.set('reourceFetching', true)
.set('reourceError', null);
}
case GET_BRAND_RESOURCE_FOR_GIRL_SUCCESS:
{
... ... @@ -206,19 +224,24 @@ export default function brandReducer(state=initialState, action) {
brandsText,
} = action.payload;
return state.setIn(['reourceForGirl', 'banner'], Immutable.fromJS(banner))
return state.set('reourceFetching', false)
.set('reourceError', null)
.setIn(['reourceForGirl', 'banner'], Immutable.fromJS(banner))
.setIn(['reourceForGirl', 'custom_brands'], Immutable.fromJS(custom_brands))
.setIn(['reourceForGirl', 'brandsText'], Immutable.fromJS(brandsText))
.setIn(['reourceForGirl', 'hasSuccess'], true);
}
case GET_BRAND_RESOURCE_FOR_GIRL_FAILURE:
{
return state.setIn(['reourceForGirl', 'hasSuccess'], false);
return state.set('reourceFetching', false)
.set('reourceError', action.payload)
.setIn(['reourceForGirl', 'hasSuccess'], false);
}
case GET_BRAND_RESOURCE_FOR_KID_REQUEST:
{
return state;
return state.set('reourceFetching', true)
.set('reourceError', null);
}
case GET_BRAND_RESOURCE_FOR_KID_SUCCESS:
{
... ... @@ -228,19 +251,24 @@ export default function brandReducer(state=initialState, action) {
brandsText,
} = action.payload;
return state.setIn(['reourceForKid', 'banner'], Immutable.fromJS(banner))
return state.set('reourceFetching', false)
.set('reourceError', null)
.setIn(['reourceForKid', 'banner'], Immutable.fromJS(banner))
.setIn(['reourceForKid', 'custom_brands'], Immutable.fromJS(custom_brands))
.setIn(['reourceForKid', 'brandsText'], Immutable.fromJS(brandsText))
.setIn(['reourceForKid', 'hasSuccess'], true);
}
case GET_BRAND_RESOURCE_FOR_KID_FAILURE:
{
return state.setIn(['reourceForKid', 'hasSuccess'], false);
return state.set('reourceFetching', false)
.set('reourceError', action.payload)
.setIn(['reourceForKid', 'hasSuccess'], false);
}
case GET_BRAND_RESOURCE_FOR_LIFESTYLE_REQUEST:
{
return state;
return state.set('reourceFetching', true)
.set('reourceError', null);
}
case GET_BRAND_RESOURCE_FOR_LIFESTYLE_SUCCESS:
{
... ... @@ -250,14 +278,18 @@ export default function brandReducer(state=initialState, action) {
brandsText,
} = action.payload;
return state.setIn(['reourceForLifeStyle', 'banner'], Immutable.fromJS(banner))
return state.set('reourceFetching', false)
.set('reourceError', null)
.setIn(['reourceForLifeStyle', 'banner'], Immutable.fromJS(banner))
.setIn(['reourceForLifeStyle', 'custom_brands'], Immutable.fromJS(custom_brands))
.setIn(['reourceForLifeStyle', 'brandsText'], Immutable.fromJS(brandsText))
.setIn(['reourceForLifeStyle', 'hasSuccess'], true);
}
case GET_BRAND_RESOURCE_FOR_LIFESTYLE_FAILURE:
{
return state.setIn(['reourceForLifeStyle', 'hasSuccess'], false);
return state.set('reourceFetching', false)
.set('reourceError', action.payload)
.setIn(['reourceForLifeStyle', 'hasSuccess'], false);
}
case BRAND_SHOW_SEARCH: {
... ...