Skip to content

Commit 45241f3

Browse files
committed
1. iOS国际化
2. 补全缺失的类型 3. 将async-storage,cameraroll,netinfo替换为社区提供的库 4. 更新之前保存图片的代码,添加新的公共Store 5. 优化目录和代码结构
1 parent 8ad08f4 commit 45241f3

File tree

22 files changed

+525
-180
lines changed

22 files changed

+525
-180
lines changed

android/app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import com.android.build.OutputFile
7575
*/
7676

7777
project.ext.react = [
78-
entryFile: "index.js"
78+
entryFile: "index_old.js"
7979
]
8080

8181
apply from: "../../node_modules/react-native/react.gradle"
@@ -174,6 +174,9 @@ android {
174174
}
175175

176176
dependencies {
177+
implementation project(':@react-native-community_netinfo')
178+
implementation project(':@react-native-community_cameraroll')
179+
implementation project(':@react-native-community_async-storage')
177180
implementation project(':react-native-webview')
178181
implementation project(':rn-fetch-blob')
179182
implementation project(':react-native-vector-icons')

android/app/src/main/java/com/shitu/MainApplication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import android.support.multidex.MultiDex;
66

77
import com.facebook.react.ReactApplication;
8+
import com.reactnativecommunity.netinfo.NetInfoPackage;
9+
import com.reactnativecommunity.cameraroll.CameraRollPackage;
10+
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
811
import com.reactnativecommunity.webview.RNCWebViewPackage;
912
import com.RNFetchBlob.RNFetchBlobPackage;
1013
import com.oblador.vectoricons.VectorIconsPackage;
@@ -36,6 +39,9 @@ public boolean getUseDeveloperSupport() {
3639
protected List<ReactPackage> getPackages() {
3740
return Arrays.<ReactPackage>asList(
3841
new MainReactPackage(),
42+
new NetInfoPackage(),
43+
new CameraRollPackage(),
44+
new AsyncStoragePackage(),
3945
new RNCWebViewPackage(),
4046
new RNFetchBlobPackage(),
4147
new VectorIconsPackage(),

android/settings.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
rootProject.name = 'ShiTu'
2+
include ':@react-native-community_netinfo'
3+
project(':@react-native-community_netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android')
4+
include ':@react-native-community_cameraroll'
5+
project(':@react-native-community_cameraroll').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/cameraroll/android')
6+
include ':@react-native-community_async-storage'
7+
project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android')
28
include ':react-native-webview'
39
project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android')
410
include ':rn-fetch-blob'

app/components/BaseContainer/index.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import React, { Component } from 'react';
77
import { View, StyleSheet } from 'react-native';
88

99
import { observer } from 'mobx-react';
10-
import { SafeAreaView, NavigationEvents } from 'react-navigation';
10+
import { NavigationEvents } from 'react-navigation';
11+
import NetInfo from '@react-native-community/netinfo';
1112

1213
import { NavigatorBar, LoadingSpinner, ErrorView } from '../index';
1314
import { Theme } from 'teaset';
@@ -38,15 +39,57 @@ type Props = {
3839
onWillBlur?: Function,
3940
onDidBlur?: Function,
4041

42+
netInfoCallBack?: (network: NetType) => void, // 网络监听回调
43+
4144
...NavigatorBar.Props
4245
};
4346

47+
export type NetType = {
48+
isConnect: boolean, // 是否连接网络
49+
isWifi: boolean, // 是否是wifi连接
50+
isCellular: boolean // 是否是流量连接
51+
};
52+
53+
type State = {
54+
netInfo: NetType // 网络状态
55+
};
56+
4457
@observer
45-
class BaseContainer extends Component<Props> {
58+
class BaseContainer extends Component<Props, State> {
59+
netInfoListen: any;
4660
componentWillUnmount() {
47-
// Toast.close(0);
61+
this.netInfoListen && NetInfo.removeEventListener('connectionChange', this.networkHandle);
4862
}
4963

64+
componentDidMount = async () => {
65+
// // 添加网络获取判断
66+
NetInfo.getConnectionInfo().then(this.networkHandle);
67+
// 添加网络监听
68+
if (this.netInfoListen) {
69+
NetInfo.removeEventListener('connectionChange', this.networkHandle);
70+
} else {
71+
this.netInfoListen = NetInfo.addEventListener('connectionChange', this.networkHandle);
72+
}
73+
};
74+
75+
networkHandle = (netInfo: NetType) => {
76+
const { netInfoCallBack } = this.props;
77+
const network: NetType = this.getNetInfoStatus(netInfo);
78+
79+
const { store } = this.props;
80+
store && store.setNetInfo(network);
81+
netInfoCallBack && netInfoCallBack(network);
82+
};
83+
84+
getNetInfoStatus = (netInfo: any) => {
85+
const type: string = netInfo.type;
86+
return {
87+
isConnect: type.toUpperCase() === 'WIFI' || type.toUpperCase() === 'CELLULAR',
88+
isWifi: type.toUpperCase() === 'WIFI',
89+
isCellular: type.toUpperCase() === 'CELLULAR'
90+
};
91+
};
92+
5093
renderContent() {
5194
const { store, children, onErrorPress, errorTitle, imageSource, errorStyle } = this.props;
5295
if (!store) return children;
@@ -111,7 +154,7 @@ class BaseContainer extends Component<Props> {
111154
const marginTop = !isHiddenNavBar ? Theme.statusBarHeight + Theme.navBarContentHeight : 0;
112155

113156
return (
114-
<View style={[styles.container, style]} forceInset={{ bottom: 'never', top: 'never' }}>
157+
<View style={[styles.container, style]}>
115158
{!isHiddenNavBar && this.renderNavView()}
116159
<View style={[styles.contentView, { marginTop, backgroundColor }, style, contentViewStyle]}>
117160
{this.renderContent()}

app/mobx/Login/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Created by Rabbit on 2018/8/15.
44
*/
55

6-
import { AsyncStorage } from 'react-native';
6+
import AsyncStorage from '@react-native-community/async-storage';
77

88
import { observable, action, runInAction } from 'mobx';
99

app/mobx/News/BuDeJieMobx.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class BuDeJieMobx extends ConfigStore {
5353
fontWeight: 'normal',
5454
fontFamily: Android ? 'normal' : 'Heiti SC'
5555
});
56-
console.log('heights', heights);
56+
// console.log('heights', heights);
5757
return parseFloat(heights.join());
5858
}
5959

@@ -92,7 +92,7 @@ class BuDeJieMobx extends ConfigStore {
9292
item.itemHeight = USER_INFO_HEIGHT + JokeHeight + ImageHeight + ITEM_HEIGHT_SPACE_HEIGHT;
9393
// item.itemHeight = USER_INFO_HEIGHT + ImageHeight + ITEM_HEIGHT_SPACE_HEIGHT;
9494

95-
console.log('itemHeight', item.itemHeight);
95+
// console.log('itemHeight', item.itemHeight);
9696

9797
const {
9898
text,
@@ -183,7 +183,7 @@ class BuDeJieMobx extends ConfigStore {
183183
});
184184
}
185185

186-
console.log('this.largeListData.slice', this.largeListData.slice());
186+
// console.log('this.largeListData.slice', this.largeListData.slice());
187187
} catch (e) {
188188
this.showErrorView(e.message);
189189
console.log('e', e.message);

app/mobx/News/WelfareMobx.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { observable, action, runInAction } from 'mobx';
77
import type { RTGankResult, RTWeal } from '../../servers/News/interfaces';
88
import { fetchWelfareData } from '../../servers/News';
99
import { System } from '../../utils';
10-
import FetchBlob from 'rn-fetch-blob';
1110
import { CameraRoll } from 'react-native';
1211
import { ConfigStore } from '../../store/ConfigStore';
12+
import FetchBlob from 'rn-fetch-blob';
1313
const Dirs = FetchBlob.fs.dirs;
14+
1415
type loadDataType = 'refreshing' | 'load more' | string;
1516

1617
class WelfareMobx extends ConfigStore {

app/pages/News/BuDeJie/index.js

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @flow
3-
* Created by Rabbit on 2018/5/4.
3+
* Created by Rabbit on 2019-03-05.
44
*/
55

66
import React from 'react';
@@ -11,40 +11,54 @@ import BaseContainer from '../../../components/BaseContainer';
1111

1212
import type { RTBDJList, RTWeal } from '../../../servers/News/interfaces';
1313
import { BuDeJieMobx } from '../../../mobx/News/BuDeJieMobx';
14-
import { observer } from 'mobx-react';
14+
import { inject, observer } from 'mobx-react';
1515
import { BaseItem } from './Components/BaseItem';
1616
import type { NavigationState } from 'react-navigation';
17-
import { Overlay } from 'teaset';
17+
import { ActionSheet, Overlay } from 'teaset';
1818
import { Button, CustomImage } from '../../../components';
1919

2020
import { Picture } from '../../../servers/News/interfaces';
2121
import PlaceholderView from './Components/Views/PlaceholderView';
2222
import 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+
2429
type Props = {
2530
type: RTBuDeJieType | string,
26-
navigate: NavigationState
31+
navigate: NavigationState,
32+
publicStore: PublicStore
2733
};
2834

35+
@inject('publicStore')
2936
@observer
3037
class 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+
119168
export { BuDeJie };

0 commit comments

Comments
 (0)