11/**
22 * @flow
3- * Created by Rabbit on 2018/5/4 .
3+ * Created by Rabbit on 2019-03-05 .
44 */
55
66import React from 'react' ;
@@ -11,40 +11,54 @@ import BaseContainer from '../../../components/BaseContainer';
1111
1212import type { RTBDJList , RTWeal } from '../../../servers/News/interfaces' ;
1313import { BuDeJieMobx } from '../../../mobx/News/BuDeJieMobx' ;
14- import { observer } from 'mobx-react' ;
14+ import { inject , observer } from 'mobx-react' ;
1515import { BaseItem } from './Components/BaseItem' ;
1616import type { NavigationState } from 'react-navigation' ;
17- import { Overlay } from 'teaset' ;
17+ import { ActionSheet , Overlay } from 'teaset' ;
1818import { Button , CustomImage } from '../../../components' ;
1919
2020import { Picture } from '../../../servers/News/interfaces' ;
2121import PlaceholderView from './Components/Views/PlaceholderView' ;
2222import type { RTBuDeJieType } from '../../../servers/News' ;
2323
24+ import { LargeList } from 'react-native-largelist-v3' ;
25+ import { System } from '../../../utils' ;
26+ import { PublicStore } from '../../../store/PublicStore' ;
27+ // import { ChineseWithLastDateFooter } from 'react-native-spring-scrollview/Customize';
28+
2429type Props = {
2530 type : RTBuDeJieType | string ,
26- navigate : NavigationState
31+ navigate : NavigationState ,
32+ publicStore : PublicStore
2733} ;
2834
35+ @inject ( 'publicStore' )
2936@observer
3037class BuDeJie extends React . Component < Props , any > {
3138 buDeJieMobx : BuDeJieMobx ;
3239 customPopView : any ;
40+ _list : LargeList ;
3341
3442 constructor ( props : Props ) {
3543 super ( props ) ;
3644 this . buDeJieMobx = new BuDeJieMobx ( ) ;
3745 }
3846
39- onFetch = async ( value : any = this . buDeJieMobx . maxtime , startFetch : Function , abortFetch : Function ) = > {
40- try {
41- const data = await this . buDeJieMobx . fetchBuDeJieData ( this . props . type , value ) ;
47+ componentDidMount = async ( ) => {
48+ const { maxtime } = this . buDeJieMobx ;
49+ await this . buDeJieMobx . fetchBuDeJieData ( this . props . type , maxtime ) ;
50+ } ;
4251
43- startFetch ( this . buDeJieMobx . dataSource . slice ( ) , 20 ) ;
44- } catch ( e ) {
45- abortFetch ( ) ;
46- console . log ( e ) ;
47- }
52+ actionSheetToSaveImage = ( url : string ) = > {
53+ const { saveImageWithIOS, saveImageWithAndroid } = this . props . publicStore ;
54+ const items = [
55+ {
56+ title : '保存图片' ,
57+ onPress : ( ) => ( System . iOS ? saveImageWithIOS ( url ) : saveImageWithAndroid ( url ) )
58+ }
59+ ] ;
60+ const cancelItem = { title : '取消' } ;
61+ ActionSheet . show ( items , cancelItem ) ;
4862 } ;
4963
5064 picturePress = ( item : Picture | any ) => {
@@ -57,7 +71,10 @@ class BuDeJie extends React.Component<Props, any> {
5771 overlayOpacity = { 1 }
5872 ref = { v => ( this . customPopView = v ) }
5973 >
60- < Button onPress = { ( ) => this . customPopView && this . customPopView . close ( ) } >
74+ < Button
75+ onPress = { ( ) => this . customPopView && this . customPopView . close ( ) }
76+ onLongPress = { ( ) => this . actionSheetToSaveImage ( item . cdn_img ) }
77+ >
6178 < CustomImage
6279 source = { { uri : item . cdn_img } }
6380 resizeMode = { 'contain' }
@@ -78,8 +95,12 @@ class BuDeJie extends React.Component<Props, any> {
7895 this . props . navigate ( 'WebView' , { uri : item . weixin_url } ) ;
7996 } ;
8097
81- renderItem = ( { item } : { item : RTBDJList , index : number } ) => {
98+ renderItem = ( { section , row } : { section : number , row : number } ) => {
8299 const { navigate } = this . props ;
100+ const { largeListData } = this . buDeJieMobx ;
101+
102+ const item = largeListData [ section ] . items [ row ] ;
103+ // console.log('item-----', item);
83104 return (
84105 < BaseItem
85106 itemData = { item }
@@ -94,26 +115,54 @@ class BuDeJie extends React.Component<Props, any> {
94115 } ;
95116
96117 render ( ) {
118+ const { largeListData, maxtime } = this . buDeJieMobx ;
97119 return (
98- < BaseContainer store = { this . buDeJieMobx } isHiddenNavBar = { true } isTopNavigator = { true } >
99- < TableList
100- style = { { backgroundColor : 'white' } }
101- onFetch = { this . onFetch }
102- renderItem = { this . renderItem }
103- keyExtractor = { item => item . id }
104- initialNumToRender = { 10 }
105- paginationType = { 'value' }
106- PaginationFetchingView = { ( ) => {
107- return [
108- < PlaceholderView type = { this . props . type } key = { 'top' } /> ,
109- < PlaceholderView type = { this . props . type } key = { 'center' } /> ,
110- < PlaceholderView type = { this . props . type } key = { 'bottom' } />
111- ] ;
112- } }
113- />
114- </ BaseContainer >
120+ < LargeList
121+ style = { styles . container }
122+ data = { largeListData }
123+ ref = { ref => ( this . _list = ref ) }
124+ heightForIndexPath = { ( { section, row } : { section : number , row : number } ) => {
125+ const item : RTBDJList = largeListData [ section ] . items [ row ] ;
126+ return item . itemHeight ;
127+ } }
128+ renderIndexPath = { this . renderItem }
129+ onRefresh = { async ( ) => {
130+ await this . buDeJieMobx . fetchBuDeJieData ( this . props . type , '' ) ;
131+ this . _list . endRefresh ( ) ;
132+ } }
133+ // loadingFooter={ChineseWithLastDateFooter}
134+ onLoading = { async ( ) => {
135+ await this . buDeJieMobx . fetchBuDeJieData ( this . props . type , maxtime ) ;
136+ this . _list . endLoading ( ) ;
137+ } }
138+ />
115139 ) ;
116140 }
117141}
118142
143+ const styles = StyleSheet . create ( {
144+ container : {
145+ flex : 1
146+ } ,
147+ section : {
148+ flex : 1 ,
149+ backgroundColor : 'gray' ,
150+ justifyContent : 'center' ,
151+ alignItems : 'center'
152+ } ,
153+ row : {
154+ flex : 1 ,
155+ justifyContent : 'center' ,
156+ alignItems : 'center'
157+ } ,
158+ line : {
159+ position : 'absolute' ,
160+ left : 0 ,
161+ right : 0 ,
162+ bottom : 0 ,
163+ height : 1 ,
164+ backgroundColor : '#EEE'
165+ }
166+ } ) ;
167+
119168export { BuDeJie } ;
0 commit comments