Skip to content

Commit d90e9b9

Browse files
committed
最新提交
1 parent f646ab0 commit d90e9b9

File tree

14 files changed

+337
-26
lines changed

14 files changed

+337
-26
lines changed

App.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,26 @@
99
import React, {Component} from 'react';
1010
import {Platform, StyleSheet, Text, View, Image, StatusBar } from 'react-native';
1111
import { createStackNavigator, createBottomTabNavigator, createAppContainer, TabBarBottom } from 'react-navigation'
12+
import { getSession } from './src/utils'
1213
import Home from './src/views/Home'
1314
import Detail from './src/views/Detail'
15+
import Info from './src/views/Info'
16+
import Me from './src/views/Me'
17+
import { Provider } from 'react-redux'
18+
// AsyncStorage.setItem('userinfo', 'I like to save it.')
19+
// const storeUserinfo = AsyncStorage.getItem('userinfo')
20+
// let islogin
21+
// console.log(this);
22+
getSession('loginname')
23+
// let a = getSession('loginname')
24+
// console.log(a._55, a);
25+
26+
// console.log(AsyncStorage.getItem('userinfo'));
27+
1428
class App extends Component {
1529
render () {
1630
return (
31+
<Provider store={store}>
1732
<AppContainer
1833
onNavigationStateChange={
1934
(prevState, currentState) => {
@@ -30,6 +45,7 @@ class App extends Component {
3045
}
3146
}
3247
/>
48+
</Provider>
3349
)
3450
}
3551
}
@@ -51,8 +67,8 @@ const Tab = createBottomTabNavigator(
5167
)
5268
}),
5369
},
54-
Nearby: {
55-
screen: createStackNavigator({ Nearby: Home }),
70+
Publish: {
71+
screen: createStackNavigator({ publish: Home }),
5672
navigationOptions: ({ navigation }) => ({
5773
tabBarLabel: '发布',
5874
tabBarIcon: ({ focused, tintColor }) => (
@@ -62,8 +78,8 @@ const Tab = createBottomTabNavigator(
6278
}),
6379
},
6480

65-
Order: {
66-
screen: createStackNavigator({ Order: Home }),
81+
Message: {
82+
screen: createStackNavigator({ message: Home }),
6783
navigationOptions: ({ navigation }) => ({
6884
tabBarLabel: '消息',
6985
tabBarIcon: ({ focused, tintColor }) => (
@@ -73,7 +89,7 @@ const Tab = createBottomTabNavigator(
7389
}),
7490
},
7591
Mine: {
76-
screen: createStackNavigator({ Mine: Home }),
92+
screen: createStackNavigator({ Mine: Me }),
7793
navigationOptions: ({ navigation }) => ({
7894
tabBarLabel: '我的',
7995
tabBarIcon: ({ focused, tintColor }) => (
@@ -83,7 +99,8 @@ const Tab = createBottomTabNavigator(
8399
}),
84100
},
85101
Info: {
86-
screen: createStackNavigator({ Mine: Home }),
102+
screen: createStackNavigator({ Info: Info }),
103+
paths: 'people/:name',
87104
navigationOptions: ({ navigation }) => ({
88105
tabBarLabel: '关于',
89106
tabBarIcon: ({ focused, tintColor }) => (

android/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ android {
138138
}
139139

140140
dependencies {
141+
implementation project(':@react-native-community_async-storage')
141142
implementation project(':react-native-gesture-handler')
142143
implementation fileTree(dir: "libs", include: ["*.jar"])
143144
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Application;
44

55
import com.facebook.react.ReactApplication;
6+
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
67
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
78
import com.facebook.react.ReactNativeHost;
89
import com.facebook.react.ReactPackage;
@@ -24,6 +25,7 @@ public boolean getUseDeveloperSupport() {
2425
protected List<ReactPackage> getPackages() {
2526
return Arrays.<ReactPackage>asList(
2627
new MainReactPackage(),
28+
new AsyncStoragePackage(),
2729
new RNGestureHandlerPackage()
2830
);
2931
}

android/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
rootProject.name = 'cnode'
2+
include ':@react-native-community_async-storage'
3+
project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android')
24
include ':react-native-gesture-handler'
35
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
46

ios/cnode.xcodeproj/project.pbxproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
ED2971652150620600B7C4FE /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED2971642150620600B7C4FE /* JavaScriptCore.framework */; };
4242
1FEB46E0121F470996F70B07 /* libRNGestureHandler.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E7CCB8C49F7D42D28A24A622 /* libRNGestureHandler.a */; };
4343
2B9D443650914636ABB57100 /* libRNGestureHandler-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 147B5297FABB40E392987A98 /* libRNGestureHandler-tvOS.a */; };
44+
4B787931F16149AB88D76FD7 /* libRNCAsyncStorage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DBD2CEC315E846B5A29BAA35 /* libRNCAsyncStorage.a */; };
4445
/* End PBXBuildFile section */
4546

4647
/* Begin PBXContainerItemProxy section */
@@ -351,6 +352,8 @@
351352
5E59F1BA8750480A82F4FB5D /* RNGestureHandler.xcodeproj */ = {isa = PBXFileReference; name = "RNGestureHandler.xcodeproj"; path = "../node_modules/react-native-gesture-handler/ios/RNGestureHandler.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
352353
E7CCB8C49F7D42D28A24A622 /* libRNGestureHandler.a */ = {isa = PBXFileReference; name = "libRNGestureHandler.a"; path = "libRNGestureHandler.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
353354
147B5297FABB40E392987A98 /* libRNGestureHandler-tvOS.a */ = {isa = PBXFileReference; name = "libRNGestureHandler-tvOS.a"; path = "libRNGestureHandler-tvOS.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
355+
6F994D615335488A9A176C02 /* RNCAsyncStorage.xcodeproj */ = {isa = PBXFileReference; name = "RNCAsyncStorage.xcodeproj"; path = "../node_modules/@react-native-community/async-storage/ios/RNCAsyncStorage.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
356+
DBD2CEC315E846B5A29BAA35 /* libRNCAsyncStorage.a */ = {isa = PBXFileReference; name = "libRNCAsyncStorage.a"; path = "libRNCAsyncStorage.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
354357
/* End PBXFileReference section */
355358

356359
/* Begin PBXFrameworksBuildPhase section */
@@ -380,6 +383,7 @@
380383
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
381384
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
382385
1FEB46E0121F470996F70B07 /* libRNGestureHandler.a in Frameworks */,
386+
4B787931F16149AB88D76FD7 /* libRNCAsyncStorage.a in Frameworks */,
383387
);
384388
runOnlyForDeploymentPostprocessing = 0;
385389
};
@@ -571,6 +575,7 @@
571575
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
572576
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
573577
5E59F1BA8750480A82F4FB5D /* RNGestureHandler.xcodeproj */,
578+
6F994D615335488A9A176C02 /* RNCAsyncStorage.xcodeproj */,
574579
);
575580
name = Libraries;
576581
sourceTree = "<group>";
@@ -1200,10 +1205,12 @@
12001205
"$(inherited)",
12011206
"\"$(SRCROOT)/$(TARGET_NAME)\"",
12021207
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1208+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
12031209
);
12041210
HEADER_SEARCH_PATHS = (
12051211
"$(inherited)",
12061212
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
1213+
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
12071214
);
12081215
};
12091216
name = Debug;
@@ -1227,10 +1234,12 @@
12271234
"$(inherited)",
12281235
"\"$(SRCROOT)/$(TARGET_NAME)\"",
12291236
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1237+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
12301238
);
12311239
HEADER_SEARCH_PATHS = (
12321240
"$(inherited)",
12331241
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
1242+
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
12341243
);
12351244
};
12361245
name = Release;
@@ -1254,6 +1263,7 @@
12541263
HEADER_SEARCH_PATHS = (
12551264
"$(inherited)",
12561265
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
1266+
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
12571267
);
12581268
};
12591269
name = Debug;
@@ -1276,6 +1286,7 @@
12761286
HEADER_SEARCH_PATHS = (
12771287
"$(inherited)",
12781288
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
1289+
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
12791290
);
12801291
};
12811292
name = Release;
@@ -1307,10 +1318,12 @@
13071318
"$(inherited)",
13081319
"\"$(SRCROOT)/$(TARGET_NAME)\"",
13091320
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1321+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
13101322
);
13111323
HEADER_SEARCH_PATHS = (
13121324
"$(inherited)",
13131325
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
1326+
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
13141327
);
13151328
};
13161329
name = Debug;
@@ -1342,10 +1355,12 @@
13421355
"$(inherited)",
13431356
"\"$(SRCROOT)/$(TARGET_NAME)\"",
13441357
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1358+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
13451359
);
13461360
HEADER_SEARCH_PATHS = (
13471361
"$(inherited)",
13481362
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
1363+
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
13491364
);
13501365
};
13511366
name = Release;
@@ -1376,10 +1391,12 @@
13761391
"$(inherited)",
13771392
"\"$(SRCROOT)/$(TARGET_NAME)\"",
13781393
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1394+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
13791395
);
13801396
HEADER_SEARCH_PATHS = (
13811397
"$(inherited)",
13821398
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
1399+
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
13831400
);
13841401
};
13851402
name = Debug;
@@ -1410,10 +1427,12 @@
14101427
"$(inherited)",
14111428
"\"$(SRCROOT)/$(TARGET_NAME)\"",
14121429
"\"$(SRCROOT)/$(TARGET_NAME)\"",
1430+
"\"$(SRCROOT)/$(TARGET_NAME)\"",
14131431
);
14141432
HEADER_SEARCH_PATHS = (
14151433
"$(inherited)",
14161434
"$(SRCROOT)/../node_modules/react-native-gesture-handler/ios/**",
1435+
"$(SRCROOT)/../node_modules/@react-native-community/async-storage/ios",
14171436
);
14181437
};
14191438
name = Release;

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"dependencies": {
1010
"@ant-design/react-native": "^3.1.8",
11+
"@react-native-community/async-storage": "^1.4.1",
1112
"@types/react": "^16.8.18",
1213
"@types/react-native": "^0.57.58",
1314
"axios": "^0.18.0",
@@ -21,6 +22,8 @@
2122
"react-native-render-html": "^4.1.2",
2223
"react-native-side-menu": "^1.1.3",
2324
"react-navigation": "^3.11.0",
25+
"react-redux": "^7.0.3",
26+
"redux": "^4.0.1",
2427
"timeago": "^1.6.6",
2528
"tslib": "^1.9.3"
2629
},

src/config/api.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// export default {
22
const all = 'https://cnodejs.org/api/v1/topics'
33
const alldetail = 'https://cnodejs.org/api/v1/topic'
4+
const access = `https://cnodejs.org/api/v1/accesstoken`
5+
const userinfo = `https://cnodejs.org/api/v1/user/`
46
// }
57
import axios from 'axios'
68

@@ -10,8 +12,9 @@ export function getALl (params) {
1012
// }
1113
// console.log(url);
1214
// url = getUrl(params, url)
13-
return axios(all, {
14-
methods: 'get',
15+
return axios({
16+
url: all,
17+
method: 'get',
1518
params
1619
// body: JSON.stringify(params)
1720
})
@@ -20,10 +23,26 @@ export function getDetail (id) {
2023

2124
return axios({
2225
url: `${alldetail}/${id}`,
23-
methods: 'get'
26+
method: 'get'
2427
// params
2528
})
2629
}
30+
31+
export function getAccess (accesstoken) {
32+
return axios({
33+
url:access,
34+
method: 'post',
35+
data: {
36+
accesstoken
37+
}
38+
})
39+
}
40+
export function getUsers (user) {
41+
return axios({
42+
url: `${userinfo}${user}`,
43+
method: 'get'
44+
})
45+
}
2746
export function getUrl (params, url) {
2847
if (params) {
2948
let paramsArray = [];

src/store/index.js

Whitespace-only changes.

src/utils/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var moment = require('moment');
2+
import 'moment/locale/zh-cn'
3+
import AsyncStorage from '@react-native-community/async-storage'
4+
export function fillterTime (time) {
5+
return moment(time).fromNow()
6+
}
7+
8+
export function setSession (key, value) {
9+
AsyncStorage.setItem(key, value)
10+
}
11+
12+
export function getSession (key) {
13+
AsyncStorage.getItem(key).then(data => {
14+
console.log(data)
15+
})
16+
}
17+
export function removeSession (key, fn) {
18+
return AsyncStorage.removeItem(key).then(error => {
19+
fn()
20+
})
21+
}

src/views/Detail/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { View, Text, ScrollView, TouchableOpacity,
44
// import HTMLView from 'react-native-htmlview';
55
import HTML from 'react-native-render-html';
66
import { getDetail } from '../../config/api'
7+
import { fillterTime } from '../../utils'
8+
79
export default class Detail extends Component {
810
constructor (props) {
911
// console.log(props);
@@ -62,9 +64,9 @@ export default class Detail extends Component {
6264
static navigationOptions = ({ navigation }) => ({
6365
headerTitle: navigation.state.params.data.title
6466
})
65-
fillterTime = (time) => {
66-
return moment(time).fromNow()
67-
}
67+
// fillterTime = (time) => {
68+
// return moment(time).fromNow()
69+
// }
6870
componentDidMount() {
6971
this.allDetail()
7072
InteractionManager.runAfterInteractions(() => {
@@ -94,19 +96,20 @@ export default class Detail extends Component {
9496
// console.log(this.state.dataList);
9597
// console.log(data, data.replies);
9698
return (
99+
data && data.replies ?
97100
<View style={{flex: 1,
98101
flexDirection: 'column',
99102
justifyContent: 'center',
100103
alignItems: 'stretch',}}>
101104
<ScrollView style={{padding: 6}}>
102105
<HTML renderers={this.state.renderers} html={data.content} tagsStyles={this.state.tagsStyles} classesStyles={this.state.classesStyles} imagesMaxWidth={Dimensions.get('window').width} />
103-
{ data && data.replies ?
106+
{/* { data && data.replies ? */}
104107
<View style={{borderTopWidth: 1, borderBottomWidth: 1, borderTopColor: '#ccc', borderBottomColor: '#ccc', paddingVertical: 10}}>
105108
<Text style={{color: '#009688', fontSize: 18}}>评论({data.replies.length})</Text>
106109
</View>
107-
: null }
110+
{/* : null } */}
108111
{
109-
(data && data.replies) && data.replies.length > 0 && data.replies.map((ele, index) =>
112+
data.replies.map((ele, index) =>
110113
<View key={index} style={{ paddingVertical: 10, borderBottomColor: '#ccc', borderBottomWidth: 1}}>
111114
<View style={{flex: 1, flexDirection: 'row',}}>
112115
<Image
@@ -119,7 +122,7 @@ export default class Detail extends Component {
119122
{ele.author.loginname}
120123
</Text>
121124
<Text>
122-
{index + 1}{this.props.navigation.state.params.getTime(ele.create_at)}
125+
{index + 1}{fillterTime(ele.create_at)}
123126
</Text>
124127
</View>
125128
</View>
@@ -139,6 +142,7 @@ export default class Detail extends Component {
139142
}
140143
</ScrollView>
141144
</View>
145+
: null
142146
// </View>
143147
)
144148
// }

0 commit comments

Comments
 (0)