33 * Created by Rabbit on 2019-03-05.
44 */
55
6- import React from 'react' ;
7- import { StyleSheet , Text , View , Image , FlatList , Modal , ActivityIndicator } from 'react-native' ;
6+ import React , { useEffect , useRef } from 'react' ;
7+ import { StyleSheet } from 'react-native' ;
88
9- import { TableList } from '../../../components' ;
109import BaseContainer from '../../../components/BaseContainer' ;
1110
1211import type { RTBDJList , RTWeal } from '../../../servers/News/interfaces' ;
1312import { BuDeJieMobx } from '../../../mobx/News/BuDeJieMobx' ;
14- import { inject , observer } from 'mobx-react' ;
13+ import { observer , useObservable } from 'mobx-react-lite ' ;
1514import { BaseItem } from './Components/BaseItem' ;
1615import type { NavigationState } from 'react-navigation' ;
1716import { ActionSheet , Overlay } from 'teaset' ;
@@ -21,59 +20,55 @@ import { Picture } from '../../../servers/News/interfaces';
2120import PlaceholderView from './Components/Views/PlaceholderView' ;
2221import type { RTBuDeJieType } from '../../../servers/News' ;
2322
24- import { LargeList } from 'react-native-largelist-v3' ;
23+ import { LargeList , WaterfallList } from 'react-native-largelist-v3' ;
2524import { System } from '../../../utils' ;
2625import { PublicStore } from '../../../store/PublicStore' ;
26+ import { ConfigStore } from '../../../store/ConfigStore' ;
2727// import { ChineseWithLastDateFooter } from 'react-native-spring-scrollview/Customize';
2828
2929type Props = {
3030 type : RTBuDeJieType | string ,
31- navigate : NavigationState ,
32- publicStore : PublicStore
31+ navigation : NavigationState ,
32+ publicStore : PublicStore ,
33+ configStore : ConfigStore
3334} ;
3435
35- @inject ( 'publicStore' )
36- @observer
37- class BuDeJie extends React . Component < Props , any > {
38- buDeJieMobx : BuDeJieMobx ;
39- customPopView : any ;
40- _list : LargeList ;
41-
42- constructor ( props : Props ) {
43- super ( props ) ;
44- this . buDeJieMobx = new BuDeJieMobx ( ) ;
45- }
36+ function actionSheetToSaveImage ( url : string , props : Props ) {
37+ const { saveImageWithIOS, saveImageWithAndroid } = props . publicStore ;
38+ const items = [
39+ {
40+ title : '保存图片' ,
41+ onPress : ( ) => ( System . iOS ? saveImageWithIOS ( url ) : saveImageWithAndroid ( url ) )
42+ }
43+ ] ;
44+ const cancelItem = { title : '取消' } ;
45+ ActionSheet . show ( items , cancelItem ) ;
46+ }
47+ const BuDeJie = observer ( function ( props : Props ) {
48+ const { navigation, type } = props ;
49+ const buDeJieMobx = useObservable ( new BuDeJieMobx ( ) ) ;
50+ const { largeListData, maxtime = '' , fetchBuDeJieData } = buDeJieMobx ;
4651
47- componentDidMount = async ( ) => {
48- const { maxtime } = this . buDeJieMobx ;
49- await this . buDeJieMobx . fetchBuDeJieData ( this . props . type , maxtime ) ;
50- } ;
52+ const waterfallRef : WaterfallList = useRef ( ) ;
53+ const customOverlayRef : Overlay = useRef ( ) ;
5154
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 ) ;
62- } ;
55+ useEffect ( ( ) => {
56+ fetchBuDeJieData ( type , '' ) ;
57+ } , [ ] ) ;
6358
64- picturePress = ( item : Picture | any ) => {
59+ function picturePress ( item : Picture , props : Props ) {
6560 if ( item . isLongPicture || ! item . is_gif ) {
66- this . props . navigate ( 'WebView' , { uri : item . weixin_url } ) ;
61+ navigation . navigate ( 'WebView' , { uri : item . weixin_url } ) ;
6762 } else {
6863 const overlayView = (
6964 < Overlay . PopView
7065 style = { { alignItems : 'center' , justifyContent : 'center' } }
7166 overlayOpacity = { 1 }
72- ref = { v => ( this . customPopView = v ) }
67+ ref = { customOverlayRef }
7368 >
7469 < Button
75- onPress = { ( ) => this . customPopView && this . customPopView . close ( ) }
76- onLongPress = { ( ) => this . actionSheetToSaveImage ( item . cdn_img ) }
70+ onPress = { ( ) => customOverlayRef && customOverlayRef . current . close ( ) }
71+ onLongPress = { ( ) => actionSheetToSaveImage ( item . cdn_img , props ) }
7772 >
7873 < CustomImage
7974 source = { { uri : item . cdn_img } }
@@ -89,56 +84,50 @@ class BuDeJie extends React.Component<Props, any> {
8984 ) ;
9085 Overlay . show ( overlayView ) ;
9186 }
92- } ;
93-
94- videoPress = ( item : Picture ) => {
95- this . props . navigate ( 'WebView' , { uri : item . weixin_url } ) ;
96- } ;
87+ }
9788
98- renderItem = ( { section , row } : { section : number , row : number } ) => {
99- const { navigate } = this . props ;
100- const { largeListData } = this . buDeJieMobx ;
89+ function videoPress ( item : Picture ) {
90+ navigation . navigate ( 'WebView' , { uri : item . weixin_url } ) ;
91+ }
10192
93+ function renderItem ( { section, row } : { section : number , row : number } ) {
10294 const item = largeListData [ section ] . items [ row ] ;
103- // console.log('item-----', item);
10495 return (
10596 < BaseItem
10697 itemData = { item }
107- navigate = { navigate }
10898 itemPress = { ( ) => {
10999 alert ( item . text ) ;
110100 } }
111- picturePress = { ( ) => this . picturePress ( item ) }
112- videoPress = { ( ) => this . videoPress ( item ) }
101+ picturePress = { ( ) => picturePress ( item , props ) }
102+ videoPress = { ( ) => videoPress ( item ) }
113103 />
114104 ) ;
115- } ;
105+ }
116106
117- render ( ) {
118- const { largeListData, maxtime } = this . buDeJieMobx ;
119- return (
107+ return (
108+ < BaseContainer isHiddenNavBar = { true } isTopNavigator = { true } store = { buDeJieMobx } >
120109 < LargeList
121110 style = { styles . container }
122111 data = { largeListData }
123- ref = { ref => ( this . _list = ref ) }
112+ ref = { waterfallRef }
124113 heightForIndexPath = { ( { section, row } : { section : number , row : number } ) => {
125114 const item : RTBDJList = largeListData [ section ] . items [ row ] ;
126115 return item . itemHeight ;
127116 } }
128- renderIndexPath = { this . renderItem }
117+ renderIndexPath = { renderItem }
129118 onRefresh = { async ( ) => {
130- await this . buDeJieMobx . fetchBuDeJieData ( this . props . type , '' ) ;
131- this . _list . endRefresh ( ) ;
119+ await fetchBuDeJieData ( type , '' ) ;
120+ waterfallRef . current . endRefresh ( ) ;
132121 } }
133122 // loadingFooter={ChineseWithLastDateFooter}
134123 onLoading = { async ( ) => {
135- await this . buDeJieMobx . fetchBuDeJieData ( this . props . type , maxtime ) ;
136- this . _list . endLoading ( ) ;
124+ await fetchBuDeJieData ( type , maxtime ) ;
125+ waterfallRef . current . endLoading ( ) ;
137126 } }
138127 />
139- ) ;
140- }
141- }
128+ </ BaseContainer >
129+ ) ;
130+ } ) ;
142131
143132const styles = StyleSheet . create ( {
144133 container : {
0 commit comments