Skip to content

Commit 77f72e4

Browse files
committed
添加发布功能
1 parent 9c3267e commit 77f72e4

File tree

11 files changed

+310
-82
lines changed

11 files changed

+310
-82
lines changed

App.js

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88

99
import React, {Component} from 'react';
1010
import {Platform, StyleSheet, Text, View, Image, StatusBar } from 'react-native';
11-
import { createStackNavigator, NavigationActions, createBottomTabNavigator, createAppContainer, TabBarBottom } from 'react-navigation'
11+
import { createStackNavigator, NavigationActions, createBottomTabNavigator, createAppContainer, TabBarBottom } from 'react-navigation'
1212
import { getSession } from './src/utils'
1313
import Home from './src/views/Home'
1414
import Detail from './src/views/Detail'
1515
import Info from './src/views/Info'
1616
import Me from './src/views/Me'
17+
import Message from './src/views/Message'
18+
import Publish from './src/views/Publish'
19+
1720
import { Provider } from 'react-redux'
1821
import { createStore } from 'redux'
1922
import Index from './src/store'
@@ -36,55 +39,17 @@ store.subscribe(() => {
3639

3740
// console.log(AsyncStorage.getItem('userinfo'));
3841
class App extends Component {
39-
constructor () {
40-
super()
41-
this.state = {
42-
nav: '',
43-
login: store.getState().login
44-
}
45-
}
4642
render () {
47-
console.log(this.state.login);
43+
// console.log(this.state.login);
4844

4945
// console.log(store.getState());
5046
// const AppContainer = createAppContainer(AppNavigator(store));
5147
return (
5248
<Provider store={store}>
5349
<AppContainer
54-
ref={navigatorRef => {
55-
this.state.nav = navigatorRef
56-
}}
5750
onNavigationStateChange={
5851
(prevState, currentState, action) => {
5952
StatusBar.setBarStyle('dark-content')
60-
console.log(action);
61-
// this.state.nav.dispatch(SwitchActions.jumpTo({ routeName: action.routeName }))
62-
// setTopLevelNavigator(this.state.nav);
63-
// navigate('Home')
64-
// console.log(prevState, currentState);
65-
// console.log(this.state.nav);
66-
67-
// let state = store.getState().login
68-
// if (state !== '') {
69-
// // this.state.nav
70-
// console.log(this.state.nav);
71-
// this.state.nav._navigation.navigate('Mine')
72-
73-
// // this.state.nav._navigation.dispatch(
74-
// // // this.state.nav._navigation.push('Mine')
75-
// // )
76-
NavigationActions.navigate({ routeName: 'Detail' })
77-
// }
78-
// this.state.nav._navigation.navigate('')
79-
// const currentScene = getCurrentRouteName(currentState)
80-
// const previousScene = getCurrentRouteName(prevState)
81-
// if (previousScene !== currentScene) {
82-
// if (lightContentScenes.indexOf(currentScene) >= 0) {
83-
// StatusBar.setBarStyle('light-content')
84-
// } else {
85-
// StatusBar.setBarStyle('dark-content')
86-
// }
87-
// }
8853
}
8954
}
9055
/>
@@ -98,12 +63,19 @@ function Tab(params) {
9863
return createBottomTabNavigator(
9964
{
10065
Home: {
101-
screen: createStackNavigator({ Home }),
66+
screen: createStackNavigator({ home: Home }),
10267
navigationOptions: ({ navigation }) => ({
10368
tabBarLabel: '首页',
104-
// title: '111',
105-
// headerTitle: null,
106-
// headerBackTitle: null,
69+
tabBarOnPress: ({defaultHandler, navigation}) => {
70+
// console.log(defaultHandler);
71+
// console.log(1111);
72+
// navigation.navigate('Home')
73+
// console.log(navigation);
74+
// console.log(navigation.state.routes[0]);
75+
76+
navigation.state.routes[0].params.queryData();//查询数据
77+
defaultHandler()
78+
},
10779
tabBarIcon: ({ focused, tintColor }) => (
10880
// normalImage='https://www.easyicon.net/api/resizeApi.php?id=1225464&size=16'
10981
// normalImage={require('./src/assets/tabbar_merchant.png')}
@@ -113,14 +85,14 @@ function Tab(params) {
11385
}),
11486
},
11587
Publish: {
116-
screen: createStackNavigator({ publish: Home }),
88+
screen: createStackNavigator({ publish: Publish }),
11789
navigationOptions: ({ navigation }) => ({
11890
tabBarLabel: '发布',
119-
tabBarOnPress: ({defaultHandler, navigation}) => {
120-
// console.log(defaultHandler);
121-
jundeLogin(defaultHandler, navigation)
91+
// tabBarOnPress: ({defaultHandler, navigation}) => {
92+
// // console.log(defaultHandler);
93+
// // jundeLogin(defaultHandler, navigation)
12294

123-
},
95+
// },
12496
tabBarIcon: ({ focused, tintColor }) => (
12597
<Image style={{tintColor, width: 25, height: 25 }} source={ require('./src/assets/publish.png')}></Image>
12698

@@ -129,7 +101,7 @@ function Tab(params) {
129101
},
130102

131103
Message: {
132-
screen: createStackNavigator({ message: Home }),
104+
screen: createStackNavigator({ message: Message }),
133105
navigationOptions: ({ navigation }) => ({
134106
tabBarLabel: '消息',
135107
tabBarOnPress: ({defaultHandler, navigation}) => {
@@ -176,10 +148,6 @@ function Tab(params) {
176148
lazy: true,
177149
animationEnabled: false,
178150
swipeEnabled: false,
179-
onTransitionStart: (start) => {
180-
console.log(strat);
181-
182-
},
183151
tabBarOptions: {
184152
activeTintColor: 'red',
185153
inactiveTintColor: 'green',
@@ -209,6 +177,8 @@ function AppNavigator(store) {
209177
login = store.getState().login
210178

211179
}
180+
console.log(Tabs);
181+
212182
// console.log(store.getState().login);
213183
return createStackNavigator(
214184
{

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"react-native": "0.59.8",
1919
"react-native-gesture-handler": "^1.2.1",
2020
"react-native-htmlview": "^0.14.0",
21+
"react-native-picker-select": "^6.1.0",
2122
"react-native-refresh-list-view": "^1.0.10",
2223
"react-native-render-html": "^4.1.2",
2324
"react-native-side-menu": "^1.1.3",

src/components/Nav/index.js

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,49 @@
11
import React, { Component } from 'react'
22
// import { getALl } from '../../config/api'
33
// import axios from 'axios'
4-
import {Platform, StyleSheet, Text, View, Dimensions, findNodeHandle } from 'react-native';
4+
import {
5+
UIManager, StyleSheet, Text, View, Animated, findNodeHandle } from 'react-native';
6+
// const AnimatedTouchableWithoutFeedback = Animated.createAnimatedComponent(TouchableWithoutFeedback);
7+
58
export default class Nav extends Component {
69
constructor () {
710
super()
811
this.state = {
912
// dataList: [],
10-
isactive: 0
13+
fadeAnim: new Animated.Value(0),
14+
isactive: 0,
15+
TextWidth: 0,
16+
Left: 0,
17+
start: null
1118
}
1219
}
20+
componentDidMount () {
21+
setTimeout(() => {
22+
this.getComponentWidth().then((data) => {
23+
this.setState({
24+
TextWidth: data
25+
})
26+
})
27+
}, 200)
28+
}
29+
getComponentWidth () {
30+
return new Promise((resolve, reject) => {
31+
const handle = findNodeHandle(this.refs.text1)
32+
UIManager.measure(handle,(x, y, width, height, pageX, pageY)=>{
33+
// comWidth = width
34+
resolve(width)
35+
})
36+
})
37+
// console.log(comWidth);
38+
}
39+
1340
getData (item, index) {
14-
this.setState({
15-
isactive: index
41+
this.getComponentWidth().then((data) => {
42+
this.setState({
43+
TextWidth: data,
44+
isactive: index,
45+
Left: index * data
46+
})
1647
})
1748
this.props.getData(item, index)
1849
}
@@ -43,18 +74,37 @@ export default class Nav extends Component {
4374
value: 'job'
4475
}
4576
]
77+
let { fadeAnim } = this.state;
4678
// const actives = this.state.isactive === index ? styles.active : ''
4779
return (
80+
// <AnimatedTouchableWithoutFeedback>
81+
// <Animated.View style={{transform: [{
82+
// translateY: this.state.fadeAnim.interpolate({
83+
// inputRange: [0, 1],
84+
// outputRange: [150, 0] // 0 : 150, 0.5 : 75, 1 : 0
85+
// }),
86+
// }],}}>
4887
<View style={styles.contain}>
88+
{/* <AnimatedTouchableWithoutFeedback */}
4989
{
5090
menuList.map((ele, index) =>
51-
<Text key={index} style={[styles.list, this.state.isactive === index ? styles.active : '']} onPress={ () => this.getData(ele, index)}>
91+
<Text
92+
ref='text1'
93+
key={index} style={[styles.list, this.state.isactive === index ? styles.active : '']} onPress={ () => this.getData(ele, index)}>
5294
{ele.text}
5395
</Text>
5496
)
97+
// <View style={[styles.block, {width: this.state.TextWidth}]}></View>
5598
}
56-
<Text style={styles.block}></Text>
99+
{/* <Animated.View style={[styles.block, {width: this.state.TextWidth, left: this.state.fadeAnim.interpolate({
100+
outputRange:[0, this.state.Left],
101+
inputRange:[0,1],
102+
})}]}>
103+
</Animated.View> */}
104+
<View style={[styles.block, {width: this.state.TextWidth, transform: [{translateX: this.state.Left}]}]}>
105+
</View>
57106
</View>
107+
// </AnimatedTouchableWithoutFeedback>
58108
)
59109
}
60110
}
@@ -104,7 +154,8 @@ const styles = StyleSheet.create({
104154
// color: '#fff',
105155
backgroundColor: 'red',
106156
bottom: 0,
107-
transform: [{translateX: 0}],
157+
height: 2
158+
// transform: [{translateX: 0}],
108159
// width: '14%'
109160
}
110161
})

src/store/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,36 @@ const REMOVE_PREV = 'REMOVE_PREV'
99

1010
// reducer
1111
export default function (state, action) {
12-
console.log(action);
12+
// console.log(action.dataList, state.da);
1313

1414
if (!state) {
1515
state = {
1616
dataList: [],
1717
login: ''
1818
}
1919
}
20+
2021
switch (action.type) {
21-
case INIT_COMMENTS:
22-
// 初始化评论
23-
return { dataList: action.dataList }
2422
case LOAD_DATA:
25-
// 新增评论
26-
return {
23+
// 初始化评论
24+
return {
25+
...state,
2726
dataList: [...state.dataList, ...action.dataList]
28-
}
27+
}
2928
case GET_LOGINNAME:
3029
return {
30+
...state,
3131
login: action.name
3232
}
3333
case REMOVE_LOGIN:
3434
return {
35+
...state,
3536
login: action.name
3637
}
3738
case REMOVE_PREV:
3839
return {
39-
dataList: []
40+
// dataList: [],
41+
...state
4042
}
4143
case DELETE_COMMENT:
4244
// 删除评论

src/views/Detail/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import { connect } from 'react-redux'
6969
// }
7070
componentDidMount() {
7171
this.allDetail()
72+
console.log(11111, '测试');
7273

7374
InteractionManager.runAfterInteractions(() => {
7475
this.props.navigation.setParams({ title: '加载中' })
@@ -94,6 +95,8 @@ import { connect } from 'react-redux'
9495
// console.log(this.state.isLoaded);
9596
// if (this.state.isLoaded) {
9697
let data = this.state.dataList
98+
console.log(this.props);
99+
97100
// console.log(this.state.dataList);
98101
// console.log(data, data.replies);
99102
return (
@@ -133,7 +136,10 @@ import { connect } from 'react-redux'
133136
}}>
134137
<Text style={{color: '#009688'}}>回复</Text>
135138
</TouchableOpacity>
136-
<Text>🖤{ele.ups.length}</Text>
139+
<TouchableOpacity>
140+
<Text>
141+
🖤{ele.ups.length}</Text>
142+
</TouchableOpacity>
137143
</View>
138144
<View style={{flex: 1, flexDirection: 'column',}}>
139145
<HTML renderers={this.state.renderers} html={ele.content} tagsStyles={this.state.tagsStyles} classesStyles={this.state.classesStyles} imagesMaxWidth={Dimensions.get('window').width} />
@@ -151,8 +157,11 @@ import { connect } from 'react-redux'
151157
}
152158

153159
const mapStateToProps = (state) => {
160+
console.log(state);
161+
154162
return {
155-
dataList: state.dataList
163+
dataList: state.dataList,
164+
login: state.login
156165
}
157166
}
158167
export default connect(

src/views/Home/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { loadData, removePrev } from '../../store'
3131
// }
3232
})
3333
componentWillMount () {
34+
this.props.navigation.setParams({ queryData: () => { this.getAxios(this.state.params); } });//在导航中添加查询数据的方法,设置一个钩子
3435
InteractionManager.runAfterInteractions(() => {
3536
this.getAxios(this.state.params)
3637
})
@@ -39,14 +40,16 @@ import { loadData, removePrev } from '../../store'
3940
getData = (item, index) => {
4041
// console.log(this.state.params.tab);
4142

42-
if (item.value !== this.state.params.tab) {
43-
// this.setState({
44-
// dataList: []
45-
// })
46-
this.props.removePrev()
43+
// if (item.value !== this.state.params.tab) {
44+
// // this.setState({
45+
// // dataList: []
46+
// // })
47+
// console.log(111);
4748

48-
// this.props.state = []
49-
}
49+
// this.props.removePrev()
50+
51+
// // this.props.state = []
52+
// }
5053
// console.log(item);
5154

5255
this.setState({
@@ -77,6 +80,7 @@ import { loadData, removePrev } from '../../store'
7780
params: query,
7881
refreshState: RefreshState.NoMoreData
7982
})
83+
8084
this.props.onSubmit(datas)
8185
// })
8286
})

src/views/Info/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class Info extends Component {
1414
// const actives = this.state.isactive === index ? styles.active : ''
1515
return (
1616
<View>
17-
<Text>111</Text>
17+
<Text>关于</Text>
1818
</View>
1919
)
2020
}

0 commit comments

Comments
 (0)