33 * Created by Rabbit on 2018/4/12.
44 */
55
6- import React , { useContext , useEffect } from 'react' ;
7- import { StyleSheet , View } from 'react-native' ;
6+ import React , { useContext , useState } from 'react' ;
7+ import { StyleSheet } from 'react-native' ;
88
99import BaseContainer from '../../components/BaseContainer' ;
1010
11- // import { observer, inject } from 'mobx-react';
12- import { observer } from 'mobx-react-lite' ;
11+ import { observer , useObserver } from 'mobx-react-lite' ;
1312
1413import ScrollableTabView , { DefaultTabBar } from 'react-native-scrollable-tab-view' ;
1514
1615import { Welfare } from './Welfare' ;
1716import { BuDeJie } from './BuDeJie' ;
18- // import { BuDeJieDetail } from './BuDeJieDetail';
1917
20- import type { NavigationState } from 'react-navigation' ;
21- import type { RTBuDeJieType } from '../../servers/News' ;
2218import { StoreContext } from '../../utils/Tool' ;
23- import { BaseItem } from './BuDeJie/Components/BaseItem' ;
24- import { BuDeJieMobx } from '../../mobx/News' ;
2519
26- import { TabView , TabBar , SceneMap } from 'react-native-tab-view' ;
20+ import { TabView , TabBar } from 'react-native-tab-view' ;
2721
2822type typeItem = {
2923 title : string ,
30- type : RTBuDeJieType | string
24+ type : string ,
25+ key : number
3126} ;
3227
3328const typeArr : Array < typeItem > = [
34- { title : '全部' , type : 1 } ,
35- { title : '视频' , type : 41 } ,
36- { title : '图片' , type : 10 } ,
37- { title : '笑话' , type : 29 } ,
38- { title : '福利' , type : '福利' }
29+ { key : 'ALL' , title : '全部' , type : 1 } ,
30+ { key : 'VIDEO' , title : '视频' , type : 41 } ,
31+ { key : 'PICTURE' , title : '图片' , type : 10 } ,
32+ { key : 'JOKE' , title : '笑话' , type : 29 } ,
33+ { key : 'WELFARE' , title : '福利' , type : '福利' }
3934];
4035
41- type State = NavigationState< {
42- key : string ,
43- title : string
44- } > ;
45-
46- class News extends React.Component< { } , State> {
47- static title = 'Scrollable top bar' ;
48- static backgroundColor = '#3f51b5' ;
49- static appbarElevation = 0 ;
50-
51- constructor ( props : { } ) {
52- super ( props ) ;
53- this . state = {
54- index : 0 ,
55- routes : [
56- { key : 'ALL' , title : '全部' , type : 1 } ,
57- { key : 'VIDEO' , title : '视频' , type : 41 } ,
58- { key : 'PICTURE' , title : '图片' , type : 10 } ,
59- { key : 'JOKE' , title : '笑话' , type : 29 } ,
60- { key : 'WELFARE' , title : '福利' , type : '福利' }
61- ]
36+ const typeData = {
37+ index : 0 ,
38+ routes : typeArr
39+ } ;
40+
41+ const News = observer(props => {
42+ const store = useContext ( StoreContext ) ;
43+ const { navigation } = props ;
44+ const { publicStore, shiTuStore } = store ;
45+
46+ const [ type , setType ] = useState ( typeData ) ;
47+
48+ function _handleIndexChange ( index ) {
49+ const _type = {
50+ index : index ,
51+ routes : typeArr
6252 } ;
53+ setType ( _type ) ;
6354 }
64- _handleIndexChange = index =>
65- this . setState ( {
66- index
67- } );
6855
69- _renderTabBar = props => {
70- console . log ( 'props' , props ) ;
56+ function _renderTabBar ( props ) {
7157 return (
7258 < TabBar
7359 { ...props }
@@ -78,56 +64,41 @@ class News extends React.Component<{}, State> {
7864 labelStyle = { styles . label }
7965 activeColor = { '#4ECBFC' }
8066 inactiveColor = { 'black' }
81- // renderIndicator={() => (
82- // <View style={{backgroundColor: 'red', height: 1, width: SCREEN_WIDTH / 4 }}/>
83- // )}
8467 />
8568 ) ;
86- } ;
87-
88- // _renderScene = SceneMap({
89- // albums: Welfare,
90- // contacts: BuDeJie,
91- // article: BuDeJie,
92- // chat: BuDeJie
93- // });
69+ }
9470
95- _renderScene = ( { route, jumpTo} ) => {
71+ function _renderScene ( { route , jumpTo } : { route : typeItem , jumpTo : Function } ) {
9672 // console.log('route', route);
97- switch ( route . key ) {
98- case 'WELFARE' :
99- return < Welfare jumpTo = { jumpTo } navigation = { this . props . navigation } type = { route . type } /> ;
100- default :
101- return < BuDeJie jumpTo = { jumpTo } navigation = { this . props . navigation } type = { route . type } /> ;
102- // case 'ALL':
103- // return
104- // case 'VIDEO':
105- // return <BuDeJie jumpTo={jumpTo} navigation={this.props.navigation} type={route.type} />;
106- // case 'PICTURE':
107- // return <BuDeJie jumpTo={jumpTo} navigation={this.props.navigation} type={route.type} />;
108- // case 'JOKE':
109- // return <BuDeJie jumpTo={jumpTo} navigation={this.props.navigation} type={route.type} />;
110- //
111- }
112- } ;
113-
114- render ( ) {
115- return (
116- < BaseContainer title = { '百思不得姐' } isTopNavigator = { true } >
117- < TabView
118- // style={this.props.style}
119- navigationState = { this . state }
120- renderScene = { this . _renderScene }
121- renderTabBar = { this . _renderTabBar }
122- onIndexChange = { this . _handleIndexChange }
123- lazy = { true }
124- swipeDistanceThreshold = { SCREEN_WIDTH / 10 }
125- initialLayout = { { width : SCREEN_WIDTH } }
73+ if ( route . key === 'WELFARE' ) {
74+ return (
75+ < Welfare
76+ jumpTo = { jumpTo }
77+ navigation = { navigation }
78+ type = { route . type }
79+ publicStore = { publicStore }
80+ shiTuStore = { shiTuStore }
12681 />
127- </ BaseContainer >
128- ) ;
82+ ) ;
83+ } else {
84+ return < BuDeJie jumpTo = { jumpTo} navigation = { navigation} type = { route. type } publicStore={ publicStore } /> ;
85+ }
12986 }
130- }
87+
88+ return useObserver ( ( ) => (
89+ < BaseContainer title = { '百思不得姐' } isTopNavigator = { true } >
90+ < TabView
91+ navigationState = { type }
92+ renderScene = { _renderScene }
93+ renderTabBar = { _renderTabBar }
94+ onIndexChange = { _handleIndexChange }
95+ lazy = { true }
96+ swipeDistanceThreshold = { SCREEN_WIDTH / 10 }
97+ initialLayout = { { width : SCREEN_WIDTH } }
98+ />
99+ </ BaseContainer >
100+ ));
101+ } ) ;
131102
132103const News1 = observer ( function ( props ) {
133104 const store = useContext ( StoreContext ) ;
0 commit comments