Skip to content

Commit d096458

Browse files
committed
1. Flow类型优化
2. 去掉冗余代码
1 parent e5dc418 commit d096458

File tree

16 files changed

+49
-53
lines changed

16 files changed

+49
-53
lines changed

.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
6969
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
7070

7171
[version]
72-
^0.78.0
72+
^0.86.0

app/mobx/News/BuDeJieMobx.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const JOKE_ITEM_WIDTH = SCREEN_WIDTH - px2dp(40);
4242
const JOKE_FONT_SIZE = FONT_SIZE(17);
4343

4444
class BuDeJieMobx extends ConfigStore {
45-
static async handleJokeTextWidth(text) {
45+
static async handleJokeTextWidth(text: string) {
4646
const heights = await MeasureText.heights({
4747
texts: [text],
4848
width: JOKE_ITEM_WIDTH,
@@ -52,9 +52,7 @@ class BuDeJieMobx extends ConfigStore {
5252
return parseFloat(heights.join());
5353
}
5454

55-
static async handleLargeListData(parameters) {
56-
const { data, type } = parameters;
57-
55+
static async handleLargeListData(data: Array<RTBDJList>, type: any) {
5856
const containerHeight =
5957
SCREEN_HEIGHT -
6058
DEFAULT_TAB_BAR_HEIGHT -
@@ -63,7 +61,7 @@ class BuDeJieMobx extends ConfigStore {
6361
DEFAULT_SCROLL_TOP_BAR_HEIGHT -
6462
DEFAULT_SPACE_HEIGHT;
6563

66-
const dataSource: Array = [];
64+
const dataSource: Array<any> = [];
6765

6866
const largeListData = { items: [] };
6967
const _containerHeight = containerHeight;
@@ -85,8 +83,7 @@ class BuDeJieMobx extends ConfigStore {
8583
item.isLongPictureCanOpened = !(height > _containerHeight && height > MAX_SCREEN_IMAGE_HEIGHT && !isGif);
8684

8785
const JokeHeight = await BuDeJieMobx.handleJokeTextWidth(item.text);
88-
const ImageHeight = item.imageHeight;
89-
// const ImageHeight = 0;
86+
const ImageHeight = item?.imageHeight ? item.imageHeight : 0;
9087
item.itemHeight = USER_INFO_HEIGHT + JokeHeight + ImageHeight + ITEM_HEIGHT_SPACE_HEIGHT;
9188

9289
const {
@@ -106,7 +103,8 @@ class BuDeJieMobx extends ConfigStore {
106103
theme_name,
107104
is_gif,
108105
gifFistFrame,
109-
imageHeight
106+
imageHeight,
107+
itemHeight
110108
} = item;
111109

112110
const userInfoData = { profile_image, name, passtime, theme_name, type };
@@ -124,7 +122,8 @@ class BuDeJieMobx extends ConfigStore {
124122
is_gif,
125123
type,
126124
gifFistFrame,
127-
...item
125+
itemHeight,
126+
...jokeData
128127
};
129128

130129
item.userInfoData = userInfoData;
@@ -146,12 +145,7 @@ class BuDeJieMobx extends ConfigStore {
146145
@observable
147146
maxtime: string = '';
148147
@observable
149-
largeListData: Array = [{ items: [] }];
150-
151-
constructor(type) {
152-
super();
153-
console.log('type------', type);
154-
}
148+
largeListData: Array<any> = [{ items: [] }];
155149

156150
/**
157151
* imageHeight: 所有Item中,Image的高度
@@ -165,10 +159,7 @@ class BuDeJieMobx extends ConfigStore {
165159
try {
166160
const buDeJieData: RTBDJResult = await loadBuDeJieData(type, value);
167161

168-
const { largeListData, dataSource } = await BuDeJieMobx.handleLargeListData({
169-
data: buDeJieData.list,
170-
type: type
171-
});
162+
const { largeListData, dataSource } = await BuDeJieMobx.handleLargeListData(buDeJieData.list, type);
172163

173164
console.log('largeListData', largeListData);
174165

@@ -190,12 +181,10 @@ class BuDeJieMobx extends ConfigStore {
190181
}
191182

192183
console.log('this.largeListData.slice', this.largeListData.slice());
193-
194184
} catch (e) {
195185
this.showErrorView(e);
196186
}
197187
}
198-
199188
}
200189

201190
export { BuDeJieMobx };

app/pages/Login/Register.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export class Register extends React.Component<Props> {
2222
<Button
2323
title={'点我跳转'}
2424
onPress={() => {
25-
this.props.navigation.push('Login');
25+
// this.props.navigation.push('Login');
26+
// this.props.navigation.navigate('AppRouter');
27+
this.props.navigation.navigate('WebView', {data: '123'});
2628
}}
2729
/>
2830
</BaseContainer>

app/pages/News/BuDeJie/Components/BaseItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Props = {
2222
};
2323

2424
const BaseItem = (props: Props) => {
25-
const { userInfoData, toolBarData } = props.itemData;
25+
const { userInfoData } = props.itemData;
2626
const { itemData, itemPress, picturePress, videoPress } = props;
2727

2828
// console.log('itemData', itemData);

app/pages/News/BuDeJie/Components/Items/JokeItem.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ export const JokeItem = (props: Props) => {
2424
const styles = StyleSheet.create({
2525
jokeView: {
2626
marginHorizontal: px2dp(20),
27-
// marginTop: 3,
2827
marginVertical: px2dp(10)
2928
},
3029
jokeText: {
31-
// lineHeight: px2dp(44),
3230
fontSize: FONT_SIZE(17)
3331
}
3432
});

app/pages/News/BuDeJie/Components/Items/PictureItem.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ const renderPicture = (props: Props) => {
2222
is_gif,
2323
gifFistFrame,
2424
isLongPictureCanOpened,
25-
itemHeight
2625
} = props.pictureData;
2726

28-
// console.log('pictureData', props.pictureData);
29-
3027
const isLongPictureCanOpenedAndNoGif = isLongPictureCanOpened && is_gif === '0';
3128

3229
if (isLongPicture) {

app/pages/News/BuDeJie/Components/Items/VideoItem.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
*/
55

66
import React from 'react';
7-
import { StyleSheet, Text, View, Image } from 'react-native';
7+
import { StyleSheet, View } from 'react-native';
88

99
import { CustomImage, Button } from '../../../../../components';
1010
import type { Picture } from '../../../../../servers/News/interfaces';
1111
import Icon from 'react-native-vector-icons/FontAwesome';
12+
import { System } from '../../../../../utils';
1213

1314
type Props = {
1415
pictureData: Picture,
@@ -38,7 +39,9 @@ export const VideoItem = (props: Props) => {
3839
const styles = StyleSheet.create({
3940
container: {
4041
flex: 1,
41-
marginHorizontal: px2dp(20),
42-
// marginVertical: px2dp(10)
42+
marginHorizontal: px2dp(20)
43+
},
44+
picture: {
45+
width: System.SCREEN_WIDTH - px2dp(40)
4346
}
4447
});

app/pages/News/BuDeJie/index_new.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class BuDeJie extends React.Component<Props, any> {
8080
const { largeListData } = this.buDeJieMobx;
8181

8282
const item = largeListData[section].items[row];
83-
console.log('item-----', item);
83+
// console.log('item-----', item);
8484
return (
8585
<BaseItem
8686
itemData={item}
@@ -102,7 +102,7 @@ class BuDeJie extends React.Component<Props, any> {
102102
data={largeListData}
103103
ref={ref => (this._list = ref)}
104104
heightForIndexPath={({ section, row }: { section: number, row: number }) => {
105-
const item = largeListData[section].items[row];
105+
const item: RTBDJList = largeListData[section].items[row];
106106
return item.itemHeight;
107107
}}
108108
renderIndexPath={this.renderItem}

app/pages/News/News.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { BuDeJieDetail } from './BuDeJieDetail';
1919

2020
import type { NavigationState } from 'react-navigation';
2121
import type { RTBuDeJieType } from '../../servers/News';
22-
import MeasureText from 'react-native-measure-text';
2322

2423
type State = {
2524
typeArr: Array<typeItem>
@@ -31,25 +30,25 @@ type typeItem = {
3130
navigate: NavigationState
3231
};
3332

34-
@inject('powerStore')
33+
@inject('powerStore', 'configStore')
3534
@observer
3635
class News extends React.Component<any, State> {
37-
async componentDidMount(): void {
38-
36+
componentDidMount = async () => {
37+
console.log('navigation', this.props.navigation);
3938
this.props.navigation.setParams({
4039
title: '百思不得姐'
4140
});
42-
}
41+
};
4342

4443
constructor(props: any) {
4544
super(props);
4645
const { navigate } = this.props.navigation;
4746
this.state = {
4847
typeArr: [
48+
{ title: '笑话', type: 29, navigate: navigate },
4949
{ title: '图片', type: 10, navigate: navigate },
5050
{ title: '全部', type: 1, navigate: navigate },
5151
{ title: '视频', type: 41, navigate: navigate },
52-
{ title: '笑话', type: 29, navigate: navigate },
5352
{ title: '福利', type: '福利', navigate: navigate }
5453
]
5554
};
@@ -74,6 +73,7 @@ class News extends React.Component<any, State> {
7473
tabLabel={item.title}
7574
key={i}
7675
navigate={item.navigate}
76+
configStore={this.props.configStore}
7777
powerStore={this.props.powerStore}
7878
/>
7979
);

app/pages/News/Welfare/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { WaterfallList } from 'react-native-largelist-v3';
88
import { NormalFooter } from 'react-native-spring-scrollview/NormalFooter';
99

1010
import { WelfareMobx } from '../../../mobx/News';
11-
import { inject, observer } from 'mobx-react';
11+
import { observer } from 'mobx-react';
1212
import type { RTWeal } from '../../../servers/News/interfaces';
1313
import { Button, CustomImage } from '../../../components';
1414
import { System } from '../../../utils';
@@ -22,17 +22,19 @@ type Props = {
2222
powerStore: PowerStore,
2323
configStore: ConfigStore
2424
};
25-
@inject('powerStore', 'configStore')
2625
@observer
2726
class Welfare extends React.Component<Props> {
28-
constructor(props) {
27+
welfareMobx: WelfareMobx;
28+
customPopView: any;
29+
30+
constructor(props: any) {
2931
super(props);
3032
this.welfareMobx = new WelfareMobx();
3133
}
3234

33-
async componentDidMount(): void {
35+
componentDidMount = async () => {
3436
await this.welfareMobx.loadWelfareData('refreshing');
35-
}
37+
};
3638

3739
actionSheetToSaveImage = (item: RTWeal) => {
3840
const items = [

0 commit comments

Comments
 (0)