Skip to content

Commit dd3aa12

Browse files
committed
1. 更新瀑布流的代码,使用largeList提供的组件
2. 更新teaset库版本
1 parent 75a5481 commit dd3aa12

File tree

11 files changed

+283
-147
lines changed

11 files changed

+283
-147
lines changed

android/app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import com.android.build.OutputFile
7575
*/
7676

7777
project.ext.react = [
78-
entryFile: "index.js"
78+
entryFile: "index_old.js"
7979
]
8080

8181
apply from: "../../node_modules/react-native/react.gradle"
@@ -175,6 +175,7 @@ android {
175175
}
176176

177177
dependencies {
178+
compile project(':react-native-spring-scrollview')
178179
compile project(':rn-fetch-blob')
179180
compile project(':react-native-vector-icons')
180181
compile project(':react-native-splash-screen')

android/app/src/main/java/com/shitu/MainApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.support.multidex.MultiDex;
66

77
import com.facebook.react.ReactApplication;
8+
import com.bolan9999.SpringScrollViewPackage;
89
import com.RNFetchBlob.RNFetchBlobPackage;
910
import com.oblador.vectoricons.VectorIconsPackage;
1011
import org.devio.rn.splashscreen.SplashScreenReactPackage;
@@ -33,6 +34,7 @@ public boolean getUseDeveloperSupport() {
3334
protected List<ReactPackage> getPackages() {
3435
return Arrays.<ReactPackage>asList(
3536
new MainReactPackage(),
37+
new SpringScrollViewPackage(),
3638
new RNFetchBlobPackage(),
3739
new VectorIconsPackage(),
3840
new SplashScreenReactPackage(),

android/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
rootProject.name = 'ShiTu'
2+
include ':react-native-spring-scrollview'
3+
project(':react-native-spring-scrollview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-spring-scrollview/android')
24
include ':rn-fetch-blob'
35
project(':rn-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/rn-fetch-blob/android')
46
include ':react-native-vector-icons'

app/mobx/News/WelfareMobx.js

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import { observable, action, runInAction } from 'mobx';
77
import type { RTGankResult, RTWeal } from '../../servers/News/interfaces';
8-
import { loadWelfareData } from '../../servers/News';
8+
import { fetchWelfareData } from '../../servers/News';
99
import { System } from '../../utils';
1010
import FetchBlob from 'rn-fetch-blob';
1111
import { CameraRoll } from 'react-native';
12+
import { ConfigStore } from '../../store/ConfigStore';
1213
const Dirs = FetchBlob.fs.dirs;
14+
type loadDataType = 'refreshing' | 'load more' | string;
1315

14-
let loadMoreNumber = [];
15-
16-
class WelfareMobx {
16+
class WelfareMobx extends ConfigStore {
1717
@observable
1818
isRefreshing: boolean = true;
1919
@observable
@@ -56,84 +56,52 @@ class WelfareMobx {
5656
};
5757

5858
@action.bound
59-
async fetchWelfareData(page: number) {
59+
async loadWelfareData(type: loadDataType = 'refreshing') {
60+
this.page = type === 'refreshing' ? 1 : this.page + 1;
61+
6062
try {
61-
const data = await loadWelfareData(page);
63+
const data = await fetchWelfareData(this.page);
6264

6365
const results = data.results;
6466

6567
const defaultHeights = [277, 216, 211, 206, 287, 214];
6668

6769
results.map((item: RTWeal) => {
6870
const imageWidth = System.SCREEN_WIDTH / 2 - 15;
69-
// let imageHeight = imageWidth * 1.15;
70-
// imageHeight = parseInt(Math.random() * 100 + imageHeight);
71-
// item.height = imageHeight;
72-
7371
const id = item._id;
74-
7572
const hexId = parseInt(id.substring(id.length - 2), 16);
7673
item.height = defaultHeights[hexId % 6];
77-
7874
item.width = imageWidth;
79-
8075
item.largeUrl = item.url;
8176
item.url = WelfareMobx.handleImageToSmallSize(item.url);
8277
});
8378

84-
if (page !== 1) {
85-
// console.log('page不等于1', page);
79+
if (type === 'load more') {
8680
runInAction(() => {
87-
this.page = page;
8881
this.dataSource = this.dataSource.concat(results);
8982
});
9083
} else {
9184
runInAction(() => {
9285
this.page = 1;
9386
this.dataSource = results;
9487
});
95-
96-
// console.log('page等于1', page);
9788
}
98-
99-
runInAction(() => {
100-
this.isRefreshing = false;
101-
});
89+
// console.log('page', this.page);
90+
// console.log('isRefreshing', this.isRefreshing);
10291
} catch (e) {
92+
this.showToast(e);
93+
console.log(e);
94+
} finally {
10395
runInAction(() => {
10496
this.isRefreshing = false;
10597
});
106-
console.log(e);
10798
}
10899
}
109100

110101
static handleImageToSmallSize(url: string) {
111102
// thumbnail|缩略,quare|方形缩略图, thumb180, wap360, small|小图, bmiddle|中图,mw600|600, wap720, mw720|720, mw1024|1024, large|原图。
112-
113103
return url.replace('large', 'wap360');
114104
}
115-
116-
@action.bound
117-
async refreshData() {
118-
runInAction(() => {
119-
this.isRefreshing = true;
120-
});
121-
await this.fetchWelfareData(1);
122-
}
123-
124-
@action.bound
125-
async loadMoreData(distanceFromEnd: Array<number>) {
126-
if (loadMoreNumber.length === 2) loadMoreNumber = [];
127-
128-
loadMoreNumber.push(distanceFromEnd);
129-
130-
let page = this.page;
131-
132-
if (loadMoreNumber.length === 2) {
133-
page += 1;
134-
await this.fetchWelfareData(page);
135-
}
136-
}
137105
}
138106

139107
export { WelfareMobx };

app/pages/News/Welfare/index.js

Lines changed: 42 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,37 @@
11
/**
22
* @flow
3-
* Created by Rabbit on 2018/5/4.
3+
* Created by Rabbit on 2019-02-25.
44
*/
5-
65
import React from 'react';
7-
import { StyleSheet, Text, View, Image, ActivityIndicator, Modal, TouchableWithoutFeedback } from 'react-native';
8-
import { MasonryList } from '../../../components';
9-
import BaseContainer from '../../../components/BaseContainer';
6+
import { StyleSheet } from 'react-native';
7+
import { WaterfallList } from 'react-native-largelist-v3';
8+
import { NormalFooter } from 'react-native-spring-scrollview/NormalFooter';
109

1110
import { WelfareMobx } from '../../../mobx/News';
12-
13-
import { observer } from 'mobx-react';
11+
import { inject, observer } from 'mobx-react';
12+
import type { RTWeal } from '../../../servers/News/interfaces';
1413
import { Button, CustomImage } from '../../../components';
15-
import type { NavigationState } from 'react-navigation';
16-
import { RTWeal } from '../../../servers/News/interfaces';
1714
import { System } from '../../../utils';
1815
import { ActionSheet, Overlay } from 'teaset';
19-
import { inject } from 'mobx-react';
16+
import type { NavigationState } from 'react-navigation';
2017
import { PowerStore } from '../../../store/PowerStore';
18+
import { ConfigStore } from '../../../store/ConfigStore';
2119

2220
type Props = {
2321
navigate: NavigationState,
24-
powerStore: PowerStore
22+
powerStore: PowerStore,
23+
configStore: ConfigStore
2524
};
26-
27-
@inject('powerStore')
25+
@inject('powerStore', 'configStore')
2826
@observer
2927
class Welfare extends React.Component<Props> {
30-
welfareMobx: WelfareMobx;
31-
customPopView: any;
32-
33-
constructor(props: Props) {
28+
constructor(props) {
3429
super(props);
3530
this.welfareMobx = new WelfareMobx();
3631
}
3732

3833
async componentDidMount(): void {
39-
await this.welfareMobx.fetchWelfareData(1);
34+
await this.welfareMobx.loadWelfareData('refreshing');
4035
}
4136

4237
actionSheetToSaveImage = (item: RTWeal) => {
@@ -52,7 +47,7 @@ class Welfare extends React.Component<Props> {
5247
title: '设置主屏幕',
5348
type: 'default',
5449
onPress: async () => {
55-
// alert('设置成功');
50+
this.props.configStore.showToast('设置成功');
5651
await this.props.powerStore.setShiTuBackgroundImage(item.url);
5752
}
5853
}
@@ -66,7 +61,7 @@ class Welfare extends React.Component<Props> {
6661
<Overlay.PopView
6762
style={{ alignItems: 'center', justifyContent: 'center' }}
6863
overlayOpacity={1}
69-
type="zoomIn"
64+
type="zoomOut"
7065
ref={v => (this.customPopView = v)}
7166
>
7267
<Button
@@ -88,70 +83,47 @@ class Welfare extends React.Component<Props> {
8883
Overlay.show(overlayView);
8984
}
9085

91-
renderItem = ({ item }: { item: RTWeal, index: number, column: number }) => {
86+
renderItem = (item: RTWeal) => {
9287
return (
93-
<Button onPress={() => this.showPopCustom(item)}>
94-
<CustomImage
95-
source={{ uri: item.url }}
96-
style={[styles.cell, { height: item.height, backgroundColor: 'white' }]}
97-
/>
88+
<Button onPress={() => this.showPopCustom(item)} style={{ flex: 1 }}>
89+
<CustomImage source={{ uri: item.url }} style={[styles.cell]} />
9890
</Button>
9991
);
10092
};
10193

102-
renderFooterComponent = () => {
103-
const { isRefreshing } = this.welfareMobx;
104-
return (
105-
!isRefreshing && (
106-
<View
107-
style={{
108-
height: 50,
109-
flex: 1,
110-
alignItems: 'center',
111-
justifyContent: 'center'
112-
}}
113-
>
114-
<ActivityIndicator size={'small'} />
115-
</View>
116-
)
117-
);
118-
};
119-
12094
render() {
121-
const { dataSource, isRefreshing, refreshData, loadMoreData } = this.welfareMobx;
122-
95+
const { dataSource, isRefreshing, loadWelfareData } = this.welfareMobx;
12396
return (
124-
<BaseContainer key={'base'} isHiddenNavBar={true} isTopNavigator={true} store={this.welfareMobx}>
125-
<MasonryList
126-
onRefresh={refreshData}
127-
style={{ backgroundColor: 'white' }}
128-
refreshing={isRefreshing}
129-
data={dataSource.slice()}
130-
renderItem={this.renderItem}
131-
getHeightForItem={({ item }) => item.height + 2}
132-
numColumns={2}
133-
initialNumToRender={10}
134-
keyExtractor={item => item._id}
135-
ListEmptyComponent={() => <View />}
136-
ListHeaderComponent={() => <View />}
137-
ListFooterComponent={this.renderFooterComponent}
138-
onEndReachedThreshold={0.1}
139-
onEndReached={loadMoreData}
140-
/>
141-
</BaseContainer>
97+
<WaterfallList
98+
ref={ref => (this._scrollView = ref)}
99+
data={dataSource}
100+
style={styles.container}
101+
heightForItem={item => item.height + 10}
102+
preferColumnWidth={SCREEN_WIDTH / 2 - 10}
103+
renderItem={this.renderItem}
104+
onRefresh={() => {
105+
loadWelfareData('refreshing');
106+
!isRefreshing && this._scrollView.endRefresh(); // 报错
107+
}}
108+
onLoading={async () => {
109+
loadWelfareData('load more');
110+
this._scrollView.endLoading();
111+
}}
112+
// loadingFooter={NormalFooter}
113+
/>
142114
);
143115
}
144116
}
145117

118+
export { Welfare };
119+
146120
const styles = StyleSheet.create({
147121
container: {
148-
flex: 1
122+
paddingHorizontal: 3
149123
},
150124
cell: {
151-
margin: 1,
152-
alignItems: 'center',
153-
justifyContent: 'center'
125+
flex: 1,
126+
margin: 5,
127+
backgroundColor: 'white'
154128
}
155129
});
156-
157-
export { Welfare };

app/pages/News/Welfare/index_new.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)