33 * Created by Rabbit on 2018/5/4.
44 */
55
6- import { observable , action , runInAction } from 'mobx' ;
7- import type { RTBDJList , RTGankResult } from '../../servers/News/interfaces' ;
8- import { loadBuDeJieData } from '../../servers/News' ;
6+ import { action , observable , runInAction } from 'mobx' ;
7+ import type { RTBDJList } from '../../servers/News/interfaces' ;
8+ import { RTBDJResult } from '../../servers/News/interfaces ' ;
99import type { RTBuDeJieType } from '../../servers/News' ;
10+ import { loadBuDeJieData } from '../../servers/News' ;
1011import { System } from '../../utils' ;
1112import { ConfigStore } from '../../store/ConfigStore' ;
12- import { Joke , Picture , RTBDJResult , ToolBar , UserInfo } from '../../servers/News/interfaces' ;
1313
14- const ContainerHeight = System . SCREEN_HEIGHT - 49 - 64 - 54 ;
15- const SpacingHeight = 80 ;
14+ import MeasureText from 'react-native-measure-text' ;
15+
16+ /**
17+ * 容器的高度
18+ * @type {number }
19+ */
20+ // const ContainerHeight: number = System.SCREEN_HEIGHT - 49 - 54;
21+ const MaxScreenImageHeight = 7000 ;
22+
23+ const UserInfoHeight = px2dp ( 100 ) ;
24+ const ToolBarHeight = px2dp ( 60 ) ;
25+
26+ const JokeItemWidth = SCREEN_WIDTH - px2dp ( 40 ) ;
27+ const JokeFontSize = FONT_SIZE ( 17 ) ;
28+
29+ const SpacingHeight = 10 ;
30+ const DefaultNormalHeight = 49 ;
31+ const DefaultScrollTopBarHeight = 54 ;
1632
1733class BuDeJieMobx extends ConfigStore {
34+ containerHeight : number =
35+ System . SCREEN_HEIGHT -
36+ DefaultNormalHeight -
37+ Theme . navBarHeight -
38+ Theme . iPhoneXBottomHeight -
39+ DefaultScrollTopBarHeight -
40+ SpacingHeight ;
41+
42+ static async handleJokeTextWidth ( text ) {
43+ const heights = await MeasureText . heights ( {
44+ texts : [ text ] ,
45+ width : JokeItemWidth ,
46+ fontSize : JokeFontSize ,
47+ fontWeight : 'normal'
48+ } ) ;
49+ return parseFloat ( heights . join ( ) ) ;
50+ }
51+
1852 @observable
1953 isRefreshing : boolean = true ;
2054 @observable
2155 dataSource : Array < RTBDJList > ;
2256 @observable
2357 maxtime : string = '' ;
2458
25- @action
59+ /**
60+ * imageHeight: 所有Item中,Image的高度
61+ * containerHeight: Item内容的高度
62+ * userInfoHeight: 顶部用户信息的高度
63+ * itemHeight: Item整体高度
64+ */
65+
66+ @action . bound
2667 async fetchBuDeJieData ( type : RTBuDeJieType , value : string ) {
2768 try {
2869 const dataSource : RTBDJResult = await loadBuDeJieData ( type , value ) ;
2970
30- // console.log('ssssssssssss', dataSource.info.count);
71+ const _newData = dataSource . list . filter ( async ( item : RTBDJList ) => {
72+ const height = ( System . SCREEN_WIDTH * item . height ) / item . width ;
73+ const isGif = item . is_gif === '1' ;
74+
75+ item . imageHeight = height ;
76+ item . isLongPicture = height > this . containerHeight && item . is_gif === '0' ;
77+ item . containerHeight = this . containerHeight ;
78+
79+ if ( item . isLongPicture || isGif ) {
80+ item . imageHeight = SCREEN_HEIGHT * 0.5 ;
81+ }
82+
83+ item . isLongPictureCanOpened = ! ( height > this . containerHeight && height > MaxScreenImageHeight && ! isGif ) ;
84+
85+ const {
86+ text,
87+ profile_image,
88+ name,
89+ passtime,
90+ love,
91+ hate,
92+ repost,
93+ comment,
94+ cdn_img,
95+ containerHeight,
96+ isLongPicture,
97+ isLongPictureCanOpened,
98+ weixin_url,
99+ theme_name,
100+ is_gif,
101+ gifFistFrame,
102+ imageHeight
103+ } = item ;
104+
105+ const userInfoData = {
106+ profile_image,
107+ name,
108+ passtime,
109+ theme_name,
110+ type
111+ } ;
112+
113+ const toolBarData = { love, hate, repost, comment, type } ;
114+ const jokeData = { text, type } ;
115+
116+ const pictureData = {
117+ cdn_img,
118+ imageHeight,
119+ isLongPicture,
120+ isLongPictureCanOpened,
121+ containerHeight,
122+ weixin_url,
123+ is_gif,
124+ type,
125+ gifFistFrame,
126+ ...item
127+ } ;
128+
129+ const JokeHeight = await BuDeJieMobx . handleJokeTextWidth ( item . text ) ;
130+ item . itemHeight = UserInfoHeight + JokeHeight + item . imageHeight + px2dp ( 40 ) ;
31131
32- dataSource . list . map ( ( item : RTBDJList ) => {
33- const imageHeight = ( System . SCREEN_WIDTH * item . height ) / item . width ;
132+ item . jokeHeight = JokeHeight ;
34133
35- item . imageHeight = imageHeight ;
36- item . containerHeight = imageHeight ;
37- item . isLongPicture = false ;
134+ // _dataSource.push(item);
38135
39- if ( imageHeight > ContainerHeight && imageHeight < System . SCREEN_HEIGHT ) {
40- item . containerHeight = imageHeight - SpacingHeight ;
41- item . isLongPicture = false ;
42- } else if ( imageHeight > System . SCREEN_HEIGHT && item . is_gif === '0' ) {
43- item . isLongPicture = true ;
136+ // console.log('ggggggg', item, item.itemHeight);
137+
138+ // return item;
139+
140+ // console.log('2222222', item);
141+
142+ // console.log('itemHeight', UserInfoHeight, JokeHeight, item.imageHeight);
143+
144+ // item.userInfoData = userInfoData;
145+ // item.toolBarData = toolBarData;
146+ // item.jokeData = jokeData;
147+ // item.pictureData = pictureData;
148+ } ) ;
149+
150+ const list = dataSource . list ;
151+ const _dataSource : Array = [ ] ;
152+
153+ for ( let i = 0 ; i < list . length ; i ++ ) {
154+ const item : RTBDJList = list [ i ] ;
155+
156+ const height = ( System . SCREEN_WIDTH * item . height ) / item . width ;
157+ const isGif = item . is_gif === '1' ;
158+
159+ item . imageHeight = height ;
160+ item . isLongPicture = height > this . containerHeight && item . is_gif === '0' ;
161+ item . containerHeight = this . containerHeight ;
162+
163+ if ( item . isLongPicture || isGif ) {
164+ item . imageHeight = SCREEN_HEIGHT * 0.5 ;
44165 }
45166
167+ item . isLongPictureCanOpened = ! ( height > this . containerHeight && height > MaxScreenImageHeight && ! isGif ) ;
168+
169+ const JokeHeight = await BuDeJieMobx . handleJokeTextWidth ( item . text ) ;
170+ item . itemHeight = UserInfoHeight + JokeHeight + item . imageHeight + px2dp ( 40 ) ;
171+
46172 const {
47173 text,
48174 profile_image,
@@ -55,10 +181,12 @@ class BuDeJieMobx extends ConfigStore {
55181 cdn_img,
56182 containerHeight,
57183 isLongPicture,
184+ isLongPictureCanOpened,
58185 weixin_url,
59186 theme_name,
60187 is_gif,
61- gifFistFrame
188+ gifFistFrame,
189+ imageHeight
62190 } = item ;
63191
64192 const userInfoData = {
@@ -68,30 +196,40 @@ class BuDeJieMobx extends ConfigStore {
68196 theme_name,
69197 type
70198 } ;
199+
71200 const toolBarData = { love, hate, repost, comment, type } ;
72201 const jokeData = { text, type } ;
202+
73203 const pictureData = {
74204 cdn_img,
75205 imageHeight,
76206 isLongPicture,
207+ isLongPictureCanOpened,
77208 containerHeight,
78209 weixin_url,
79210 is_gif,
80211 type,
81212 gifFistFrame,
82- ...jokeData
213+ ...item
83214 } ;
84215
216+ item . jokeHeight = JokeHeight ;
85217 item . userInfoData = userInfoData ;
86218 item . toolBarData = toolBarData ;
87219 item . jokeData = jokeData ;
88220 item . pictureData = pictureData ;
89- } ) ;
221+
222+ _dataSource . push ( item ) ;
223+ }
224+
225+ console . log ( '_datasource' , _dataSource ) ;
226+
227+ // console.log('_newData', _newData);
90228
91229 runInAction ( ( ) => {
92- this . dataSource = dataSource . list ;
93- this . maxtime = dataSource . info . maxid ;
230+ this . dataSource = _dataSource ;
94231 } ) ;
232+ this . maxtime = dataSource . info . maxid ;
95233 } catch ( e ) {
96234 // this.showErrorView(e);
97235 }
0 commit comments