Skip to content

Commit 49f8e22

Browse files
authored
Merge pull request #12 from SurpassRabbit/develop
1. 优化瀑布流计算图片高度的方法
2 parents 8d0f70c + 75a5481 commit 49f8e22

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

app/mobx/News/WelfareMobx.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ class WelfareMobx {
6262

6363
const results = data.results;
6464

65+
const defaultHeights = [277, 216, 211, 206, 287, 214];
66+
6567
results.map((item: RTWeal) => {
6668
const imageWidth = System.SCREEN_WIDTH / 2 - 15;
67-
let imageHeight = imageWidth * 1.15;
68-
imageHeight = parseInt(Math.random() * 100 + imageHeight);
69-
item.height = imageHeight;
69+
// let imageHeight = imageWidth * 1.15;
70+
// imageHeight = parseInt(Math.random() * 100 + imageHeight);
71+
// item.height = imageHeight;
72+
73+
const id = item._id;
74+
75+
const hexId = parseInt(id.substring(id.length - 2), 16);
76+
item.height = defaultHeights[hexId % 6];
77+
7078
item.width = imageWidth;
7179

7280
item.largeUrl = item.url;

app/pages/News/Welfare/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Welfare extends React.Component<Props> {
3535
this.welfareMobx = new WelfareMobx();
3636
}
3737

38-
async componentDidMount() {
38+
async componentDidMount(): void {
3939
await this.welfareMobx.fetchWelfareData(1);
4040
}
4141

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @flow
3+
* Created by Rabbit on 2019-02-25.
4+
*/
5+
import React from 'react';
6+
import { View, Text, Image, StyleSheet } from 'react-native';
7+
8+
type Props = {};
9+
type State = {};
10+
export default class index_new extends React.Component<Props, State> {
11+
render() {
12+
return (
13+
<View style={styles.container}>
14+
15+
</View>
16+
);
17+
}
18+
}
19+
20+
const styles = StyleSheet.create({
21+
container: {
22+
flex: 1
23+
}
24+
});

0 commit comments

Comments
 (0)