22 * @flow
33 * Created by Rabbit on 2019-02-25.
44 */
5- import React from 'react' ;
5+ import React , { useEffect , useRef } from 'react' ;
66import { StyleSheet } from 'react-native' ;
77import { WaterfallList } from 'react-native-largelist-v3' ;
88import { NormalFooter } from 'react-native-spring-scrollview/NormalFooter' ;
99
1010import { WelfareMobx } from '../../../mobx/News' ;
11- import { inject , observer } from 'mobx-react' ;
11+ // import { observer, inject } from 'mobx-react';
12+ import { observer } from 'mobx-react-lite' ;
13+
1214import type { RTWeal } from '../../../servers/News/interfaces' ;
1315import { Button , CustomImage } from '../../../components' ;
1416import { System } from '../../../utils' ;
@@ -18,31 +20,27 @@ import { ConfigStore } from '../../../store/ConfigStore';
1820import { PublicStore } from '../../../store/PublicStore' ;
1921import { ShiTuStore } from '../../../store/ShiTu/ShiTuStore' ;
2022
23+ const welfareMobx = new WelfareMobx ( ) ;
24+
2125type Props = {
2226 navigate : NavigationState ,
2327 configStore : ConfigStore ,
2428 publicStore : PublicStore ,
2529 shiTuStore : ShiTuStore
2630} ;
2731
28- @observer
29- class Welfare extends React . Component < Props > {
30- welfareMobx : WelfareMobx ;
31- customPopView : any ;
32-
33- constructor ( props : any ) {
34- super ( props ) ;
35- this . welfareMobx = new WelfareMobx ( ) ;
36- }
37-
38- componentDidMount = async ( ) => {
39- console . log ( 'props' , this . props ) ;
32+ const Welfare = observer ( function ( props : Props ) {
33+ const { dataSource, isRefreshing, loadWelfareData } = welfareMobx ;
34+ const scrollViewRef : WaterfallList = useRef ( ) ;
35+ const customPopView : Overlay = useRef ( ) ;
36+ const { publicStore, configStore, shiTuStore } = props ;
4037
41- await this . welfareMobx . loadWelfareData ( 'refreshing' ) ;
42- } ;
38+ useEffect ( ( ) => {
39+ welfareMobx . loadWelfareData ( 'refreshing' ) ;
40+ } , [ ] ) ;
4341
44- actionSheetToSaveImage = ( item : RTWeal ) = > {
45- const { saveImageWithIOS, saveImageWithAndroid } = this . props . publicStore ;
42+ function actionSheetToSaveImage ( item : RTWeal ) {
43+ const { saveImageWithIOS, saveImageWithAndroid } = publicStore ;
4644 const items = [
4745 {
4846 title : '保存图片' ,
@@ -52,27 +50,26 @@ class Welfare extends React.Component<Props> {
5250 title : '设置主屏幕' ,
5351 type : 'default' ,
5452 onPress : async ( ) => {
55- this . props . configStore . showToast ( '设置成功' ) ;
56- // await this.props.
57- await this . props . shiTuStore . setBackgroundImageUrl ( item . url ) ;
53+ configStore . showToast ( '设置成功' ) ;
54+ await shiTuStore . setBackgroundImageUrl ( item . url ) ;
5855 }
5956 }
6057 ] ;
6158 const cancelItem = { title : '取消' } ;
6259 ActionSheet . show ( items , cancelItem ) ;
63- } ;
60+ }
6461
65- showPopCustom ( item : RTWeal ) {
62+ function showPopCustom ( item : RTWeal ) {
6663 const overlayView = (
6764 < Overlay . PopView
6865 style = { { alignItems : 'center' , justifyContent : 'center' } }
6966 overlayOpacity = { 1 }
7067 type = "zoomOut"
71- ref = { v => ( this . customPopView = v ) }
68+ ref = { customPopView }
7269 >
7370 < Button
74- onLongPress = { ( ) => this . actionSheetToSaveImage ( item ) }
75- onPress = { ( ) => this . customPopView && this . customPopView . close ( ) }
71+ onLongPress = { ( ) => actionSheetToSaveImage ( item ) }
72+ onPress = { ( ) => customPopView && customPopView . current . close ( ) }
7673 >
7774 < CustomImage
7875 source = { { uri : item . largeUrl } }
@@ -89,37 +86,34 @@ class Welfare extends React.Component<Props> {
8986 Overlay . show ( overlayView ) ;
9087 }
9188
92- renderItem = ( item : RTWeal ) = > {
89+ function renderItem ( item : RTWeal ) {
9390 return (
94- < Button onPress = { ( ) => this . showPopCustom ( item ) } style = { { flex : 1 } } >
91+ < Button onPress = { ( ) => showPopCustom ( item ) } style = { { flex : 1 } } >
9592 < CustomImage source = { { uri : item . url } } style = { [ styles . cell ] } />
9693 </ Button >
9794 ) ;
98- } ;
99-
100- render ( ) {
101- const { dataSource, isRefreshing, loadWelfareData } = this . welfareMobx ;
102- return (
103- < WaterfallList
104- ref = { ref => ( this . _scrollView = ref ) }
105- data = { dataSource }
106- style = { styles . container }
107- heightForItem = { item => item . height + 10 }
108- preferColumnWidth = { SCREEN_WIDTH / 2 - 10 }
109- renderItem = { this . renderItem }
110- onRefresh = { ( ) => {
111- loadWelfareData ( 'refreshing' ) ;
112- ! isRefreshing && this . _scrollView . endRefresh ( ) ; // 报错
113- } }
114- onLoading = { async ( ) => {
115- loadWelfareData ( 'load more' ) ;
116- this . _scrollView . endLoading ( ) ;
117- } }
118- // loadingFooter={NormalFooter}
119- />
120- ) ;
12195 }
122- }
96+
97+ return (
98+ < WaterfallList
99+ ref = { scrollViewRef }
100+ data = { dataSource }
101+ style = { styles . container }
102+ heightForItem = { item => item . height + 10 }
103+ preferColumnWidth = { SCREEN_WIDTH / 2 - 10 }
104+ renderItem = { renderItem }
105+ onRefresh = { ( ) => {
106+ loadWelfareData ( 'refreshing' ) ;
107+ ! isRefreshing && scrollViewRef . current . endRefresh ( ) ; // 报错
108+ } }
109+ onLoading = { async ( ) => {
110+ loadWelfareData ( 'load more' ) ;
111+ scrollViewRef && scrollViewRef . current . endLoading ( ) ;
112+ } }
113+ // loadingFooter={NormalFooter}
114+ />
115+ ) ;
116+ } ) ;
123117
124118export { Welfare } ;
125119
0 commit comments