罗广聪

导航OK,跳转页OK,就剩下登录注册模块

@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 */ 5 */
6 6
7 import React, { Component } from "react"; 7 import React, { Component } from "react";
8 -import { AppRegistry, StyleSheet, Text, View } from "react-native"; 8 +import { AppRegistry, StyleSheet, Text, View, Image } from "react-native";
9 import { StackNavigator, TabNavigator } from "react-navigation"; 9 import { StackNavigator, TabNavigator } from "react-navigation";
10 10
11 import Home from "./src/pages/Home/index"; 11 import Home from "./src/pages/Home/index";
@@ -13,45 +13,67 @@ import InsuranceCircle from "./src/pages/InsuranceCircle/index"; @@ -13,45 +13,67 @@ import InsuranceCircle from "./src/pages/InsuranceCircle/index";
13 import InsuranceChurch from "./src/pages/InsuranceChurch/index"; 13 import InsuranceChurch from "./src/pages/InsuranceChurch/index";
14 import Mine from "./src/pages/Mine/index"; 14 import Mine from "./src/pages/Mine/index";
15 import Login from "./src/pages/Login"; 15 import Login from "./src/pages/Login";
  16 +import AllProduct from "./src/pages/Home/allProduct";
  17 +import CommonWebView from "./src/Components/CommonWebView";
  18 +import Details from "./src/pages/InsuranceCircle/details";
16 19
17 const MainTabBar = TabNavigator({ 20 const MainTabBar = TabNavigator({
18 - Home: { screen: Home, navigationOptions: { title: "首页"} }, 21 + Home: {
19 - InsuranceCircle: { screen: InsuranceCircle }, 22 + screen: Home,
20 - InsuranceChurch: { screen: InsuranceChurch }, 23 + navigationOptions: {
21 - Mine: { screen: Mine } 24 + // title: "首页",
22 -}); 25 + tabBarIcon: ({ focused }) =>
23 - 26 + focused ? (
24 -class Main extends Component { 27 + <Image source={require("./src/assets/tabbar/ic_home_s.png")} />
25 - constructor(props) { 28 + ) : (
26 - super(props); 29 + <Image source={require("./src/assets/tabbar/ic_home_n.png")} />
27 - this.state = { 30 + )
28 - isLoading: false, 31 + }
29 - isLogin: true 32 + },
30 - }; 33 + InsuranceCircle: {
  34 + screen: InsuranceCircle,
  35 + navigationOptions: {
  36 + // title: "首页",
  37 + tabBarIcon: ({ focused }) =>
  38 + focused ? (
  39 + <Image source={require("./src/assets/tabbar/ic_circle_s.png")} />
  40 + ) : (
  41 + <Image source={require("./src/assets/tabbar/ic_circle_n.png")} />
  42 + )
  43 + }
  44 + },
  45 + InsuranceChurch: {
  46 + screen: InsuranceChurch,
  47 + navigationOptions: {
  48 + // title: "首页",
  49 + tabBarIcon: ({ focused }) =>
  50 + focused ? (
  51 + <Image source={require("./src/assets/tabbar/ic_umbrella_s.png")} />
  52 + ) : (
  53 + <Image source={require("./src/assets/tabbar/ic_umbrella_n.png")} />
  54 + )
  55 + }
  56 + },
  57 + Mine: {
  58 + screen: Mine,
  59 + navigationOptions: {
  60 + // title: "首页",
  61 + tabBarIcon: ({ focused }) =>
  62 + focused ? (
  63 + <Image source={require("./src/assets/tabbar/ic_mine_s.png")} />
  64 + ) : (
  65 + <Image source={require("./src/assets/tabbar/ic_mine_n.png")} />
  66 + )
  67 + }
31 } 68 }
32 - render() { 69 +},{
33 - const { isLogin } = this.state; 70 + swipeEnabled: true,
34 - return isLogin ? ( 71 + tabBarOptions: {
35 - <MainTabBar /> 72 + activeTintColor: "#1B9341"
36 - ) : (  
37 - <Login  
38 - loginSuccess={this.props.loginSuccess}  
39 - onLogin={this.props.onLogin}  
40 - />  
41 - );  
42 } 73 }
43 -}  
44 -  
45 -const ProtectGod = StackNavigator({  
46 - Main: { screen: Main },  
47 - Home: { screen: Home, navigationOptions: { headerTitle: "首页"} },  
48 - InsuranceCircle: { screen: InsuranceCircle },  
49 - InsuranceChurch: { screen: InsuranceChurch },  
50 - Mine: { screen: Mine },  
51 - Login: { screen: Login }  
52 }); 74 });
53 75
54 -// export default class ProtectGod extends Component { 76 +// class Main extends Component {
55 // constructor(props) { 77 // constructor(props) {
56 // super(props); 78 // super(props);
57 // this.state = { 79 // this.state = {
@@ -59,62 +81,56 @@ const ProtectGod = StackNavigator({ @@ -59,62 +81,56 @@ const ProtectGod = StackNavigator({
59 // isLogin: true 81 // isLogin: true
60 // }; 82 // };
61 // } 83 // }
62 -// componentWillMount() {  
63 -// // console.log("componentWillMount生命周期");  
64 -// // var that = this;  
65 -// // return fetch(`https://devpay.brae.co/test/insurance/login`,{  
66 -// // method: "POST",  
67 -// // headers: {  
68 -// // 'Accept': 'application/json',  
69 -// // 'Content-Type': 'application/json',  
70 -// // },  
71 -// // })  
72 -// // .then((resp) => {  
73 -// // console.log("测试接口",resp);  
74 -// // // return false;  
75 -// // if (resp.status === 200) {  
76 -// // return resp.json();  
77 -// // } else {  
78 -// // console.error("something went wrong!");  
79 -// // }  
80 -// // })  
81 -// // .then((respJson) => {  
82 -// // if (respJson.enmsg != 'ok') {  
83 -// // console.error(err);  
84 -// // alert(respJson.cnmsg);  
85 -// // } else {  
86 -// // that.setState({  
87 -// // testData: respJson.data  
88 -// // });  
89 -// // console.log('state.testData',that.state.testData);  
90 -// // }  
91 -// // })  
92 -// // .catch((err) => console.error(err))  
93 -// }  
94 -  
95 // render() { 84 // render() {
96 -// console.log("看看这个登录state", this.state.isLogin); 85 +// const { isLogin } = this.state;
97 -// return this.state.isLoading ? null : ( 86 +
98 -// <Main 87 +// return isLogin ? (
99 -// loginSuccess={this.state.isLogin} 88 +// <MainTabBar />
100 -// selectedItem={this.state.selectedItem} 89 +// ) : (
101 -// onLogin={isLogin => { 90 +// <Login
102 -// this.setState({ 91 +// loginSuccess={this.props.loginSuccess}
103 -// isLogin: isLogin 92 +// onLogin={this.props.onLogin}
104 -// });  
105 -// }}  
106 // /> 93 // />
107 // ); 94 // );
108 // } 95 // }
109 // } 96 // }
110 97
111 -const styles = StyleSheet.create({ 98 +const ProtectGod = StackNavigator(
112 - container: { 99 + {
113 - flex: 1, 100 + // Main: { screen: Main },
114 - justifyContent: "center", 101 + MainTabBar: { screen: MainTabBar },
115 - alignItems: "center", 102 + Home: { screen: Home },
116 - backgroundColor: "#F5FCFF" 103 + InsuranceCircle: { screen: InsuranceCircle },
  104 + InsuranceChurch: { screen: InsuranceChurch },
  105 + Mine: { screen: Mine },
  106 + Login: { screen: Login },
  107 + AllProduct: {
  108 + screen: AllProduct,
  109 + navigationOptions: { headerTitle: "全部产品" }
  110 + },
  111 + CommonWebView: { screen: CommonWebView },
  112 + Details: { screen: Details }
  113 + },
  114 + {
  115 + navigationOptions: {
  116 + // 顶部标题颜色
  117 + // headerTintColor: 'red',
  118 + // 顶部背景颜色
  119 + // headerStyle: {backgroundColor: "white"},
  120 + // headerTitleStyle: {alignSelf: 'center'},
  121 + }
117 } 122 }
118 -}); 123 +);
  124 +
  125 +const styles = StyleSheet.create(
  126 + {
  127 + // container: {
  128 + // flex: 1,
  129 + // justifyContent: "center",
  130 + // alignItems: "center",
  131 + // backgroundColor: "#F5FCFF"
  132 + // }
  133 + }
  134 +);
119 135
120 AppRegistry.registerComponent("ProtectGod", () => ProtectGod); 136 AppRegistry.registerComponent("ProtectGod", () => ProtectGod);
@@ -4,17 +4,19 @@ import { @@ -4,17 +4,19 @@ import {
4 WebView, 4 WebView,
5 View, 5 View,
6 } from 'react-native'; 6 } from 'react-native';
  7 +import { StackNavigator, TabNavigator } from 'react-navigation';
  8 +
7 9
8 export default class CommonWebview extends Component { 10 export default class CommonWebview extends Component {
9 constructor(props) { 11 constructor(props) {
10 super(props); 12 super(props);
11 } 13 }
12 render() { 14 render() {
13 - console.log("url",this.props.url) 15 + console.log("url",this.props)
14 return ( 16 return (
15 <WebView 17 <WebView
16 style={styles.container} 18 style={styles.container}
17 - source={{uri: this.props.url}} 19 + source={{uri: this.props.navigation.state.params.item.url}}
18 /> 20 />
19 ); 21 );
20 } 22 }
@@ -8,9 +8,11 @@ import { @@ -8,9 +8,11 @@ import {
8 TouchableOpacity, 8 TouchableOpacity,
9 Image 9 Image
10 } from "react-native"; 10 } from "react-native";
  11 +import { StackNavigator, TabNavigator } from 'react-navigation';
11 import CommonWebView from "../../Components/CommonWebView"; 12 import CommonWebView from "../../Components/CommonWebView";
12 13
13 export default class AllProduct extends Component { 14 export default class AllProduct extends Component {
  15 +
14 constructor(props) { 16 constructor(props) {
15 super(props); 17 super(props);
16 this.state = { 18 this.state = {
@@ -44,6 +46,7 @@ export default class AllProduct extends Component { @@ -44,6 +46,7 @@ export default class AllProduct extends Component {
44 } 46 }
45 47
46 render() { 48 render() {
  49 + const { navigate } = this.props.navigation;
47 return ( 50 return (
48 <View style={styles.container}> 51 <View style={styles.container}>
49 {/* <NewsList /> */} 52 {/* <NewsList /> */}
@@ -56,14 +59,7 @@ export default class AllProduct extends Component { @@ -56,14 +59,7 @@ export default class AllProduct extends Component {
56 <TouchableOpacity 59 <TouchableOpacity
57 style={styles.itemContainer} 60 style={styles.itemContainer}
58 key={index} 61 key={index}
59 - onPress={() => { 62 + onPress={() => navigate("CommonWebView", { item: item })}
60 - this.props.navigator.push({  
61 - component: CommonWebView,  
62 - passProps: {  
63 - url: item.url  
64 - }  
65 - });  
66 - }}  
67 > 63 >
68 <Image style={styles.itemImgWrapper} source={item.imgurl} /> 64 <Image style={styles.itemImgWrapper} source={item.imgurl} />
69 <View style={styles.itemRightWrapper}> 65 <View style={styles.itemRightWrapper}>
@@ -88,7 +84,6 @@ const styles = StyleSheet.create({ @@ -88,7 +84,6 @@ const styles = StyleSheet.create({
88 justifyContent: "flex-start", 84 justifyContent: "flex-start",
89 alignItems: "stretch", 85 alignItems: "stretch",
90 backgroundColor: "#EFEFEF", 86 backgroundColor: "#EFEFEF",
91 - paddingTop: 74  
92 }, 87 },
93 scrollViewContainer: { 88 scrollViewContainer: {
94 height: 300 89 height: 300
@@ -8,14 +8,14 @@ import { @@ -8,14 +8,14 @@ import {
8 TouchableOpacity, 8 TouchableOpacity,
9 ScrollView 9 ScrollView
10 } from "react-native"; 10 } from "react-native";
11 -import { StackNavigator, TabNavigator } from 'react-navigation'; 11 +import { StackNavigator, TabNavigator } from "react-navigation";
12 import Swiper from "react-native-swiper"; 12 import Swiper from "react-native-swiper";
13 -import AllProduct from "./allProduct"; 13 +// import AllProduct from "./allProduct";
14 import CommonWebView from "../../Components/CommonWebView"; 14 import CommonWebView from "../../Components/CommonWebView";
15 15
16 export default class Home extends Component { 16 export default class Home extends Component {
17 static navigationOptions = { 17 static navigationOptions = {
18 - title: '首页', 18 + title: "首页"
19 }; 19 };
20 constructor(props) { 20 constructor(props) {
21 super(props); 21 super(props);
@@ -79,14 +79,13 @@ export default class Home extends Component { @@ -79,14 +79,13 @@ export default class Home extends Component {
79 console.log("thisprops", this.props); 79 console.log("thisprops", this.props);
80 } 80 }
81 _renderMap() { 81 _renderMap() {
  82 + const { navigate } = this.props.navigation;
82 return this.state.ListData.map((item, index) => { 83 return this.state.ListData.map((item, index) => {
83 return ( 84 return (
84 <TouchableOpacity 85 <TouchableOpacity
85 style={styles.itemContainer} 86 style={styles.itemContainer}
86 key={index} 87 key={index}
87 - onPress={() => { 88 + onPress={() => navigate("CommonWebView", { item: item })}
88 - this._jumpToWebView(item);  
89 - }}  
90 > 89 >
91 <Image style={styles.itemImgWrapper} source={item.imgurl} /> 90 <Image style={styles.itemImgWrapper} source={item.imgurl} />
92 <View style={styles.itemRightWrapper}> 91 <View style={styles.itemRightWrapper}>
@@ -97,22 +96,8 @@ export default class Home extends Component { @@ -97,22 +96,8 @@ export default class Home extends Component {
97 ); 96 );
98 }); 97 });
99 } 98 }
100 - _jumpToWebView(item) {  
101 - // console.log("跳转到webview的item",item);  
102 - this.props.navigator.push({  
103 - component: CommonWebView,  
104 - passProps: {  
105 - url: item.url  
106 - }  
107 - });  
108 - }  
109 - gotoAllProduct() {  
110 - this.props.navigator.push({  
111 - component: AllProduct,  
112 - title: "全部产品"  
113 - });  
114 - }  
115 _swiper() { 99 _swiper() {
  100 + const { navigate } = this.props.navigation;
116 return ( 101 return (
117 <View style={{ height: 120 }}> 102 <View style={{ height: 120 }}>
118 <Swiper 103 <Swiper
@@ -122,7 +107,7 @@ export default class Home extends Component { @@ -122,7 +107,7 @@ export default class Home extends Component {
122 height={120} 107 height={120}
123 dotStyle={{ 108 dotStyle={{
124 width: 6, 109 width: 6,
125 - height: 6, 110 + height: 6
126 }} 111 }}
127 activeDotStyle={{ 112 activeDotStyle={{
128 width: 6, 113 width: 6,
@@ -130,15 +115,14 @@ export default class Home extends Component { @@ -130,15 +115,14 @@ export default class Home extends Component {
130 }} 115 }}
131 > 116 >
132 {this.state.swiperImgList.map((item, index) => { 117 {this.state.swiperImgList.map((item, index) => {
133 - {/* console.log("图片item",item); */} 118 + {
  119 + /* console.log("图片item",item); */
  120 + }
134 return ( 121 return (
135 <TouchableOpacity 122 <TouchableOpacity
136 style={styles.slide} 123 style={styles.slide}
137 key={index} 124 key={index}
138 - onPress={() => { 125 + onPress={() => navigate("CommonWebView", { item: item })}
139 - console.log("我是轮播图")  
140 - this._jumpToWebView(item);  
141 - }}  
142 > 126 >
143 <Image 127 <Image
144 style={styles.slideImg} 128 style={styles.slideImg}
@@ -153,16 +137,16 @@ export default class Home extends Component { @@ -153,16 +137,16 @@ export default class Home extends Component {
153 ); 137 );
154 } 138 }
155 render() { 139 render() {
  140 + console.log("首页的this.props", this);
156 const { navigate } = this.props.navigation; 141 const { navigate } = this.props.navigation;
157 return ( 142 return (
158 <View style={styles.container}> 143 <View style={styles.container}>
159 - {/* <Carousel /> */}  
160 {this._swiper()} 144 {this._swiper()}
161 <TouchableOpacity 145 <TouchableOpacity
162 style={styles.midContainer} 146 style={styles.midContainer}
163 - onPress={() => { 147 + onPress={() =>
164 - this.gotoAllProduct(); 148 + navigate("AllProduct")
165 - }} 149 + }
166 > 150 >
167 <Image 151 <Image
168 source={require("../../assets/home/pic.png")} 152 source={require("../../assets/home/pic.png")}
@@ -237,10 +221,7 @@ const styles = StyleSheet.create({ @@ -237,10 +221,7 @@ const styles = StyleSheet.create({
237 // color: "#202020", 221 // color: "#202020",
238 }, 222 },
239 listContainer: { 223 listContainer: {
240 - // height: 150 224 + flex: 1
241 - flex: 1,  
242 - // paddingBottom: 64,  
243 - // marginBottom: 49  
244 }, 225 },
245 itemContainer: { 226 itemContainer: {
246 height: 90, 227 height: 90,
@@ -278,7 +259,7 @@ const styles = StyleSheet.create({ @@ -278,7 +259,7 @@ const styles = StyleSheet.create({
278 color: "#7A7A7A", 259 color: "#7A7A7A",
279 fontSize: 13, 260 fontSize: 13,
280 marginTop: 10, 261 marginTop: 10,
281 - textAlign: "center", 262 + textAlign: "center"
282 // marginBottom: 10 263 // marginBottom: 10
283 } 264 }
284 }); 265 });
@@ -49,6 +49,7 @@ export default class InsuranceChurch extends Component { @@ -49,6 +49,7 @@ export default class InsuranceChurch extends Component {
49 } 49 }
50 50
51 render() { 51 render() {
  52 + const { navigate } = this.props.navigation;
52 return ( 53 return (
53 <View style={styles.container}> 54 <View style={styles.container}>
54 <ScrollView 55 <ScrollView
@@ -60,14 +61,7 @@ export default class InsuranceChurch extends Component { @@ -60,14 +61,7 @@ export default class InsuranceChurch extends Component {
60 <TouchableOpacity 61 <TouchableOpacity
61 style={styles.itemContainer} 62 style={styles.itemContainer}
62 key={index} 63 key={index}
63 - onPress={() => { 64 + onPress={() => navigate("CommonWebView", { item: item })}
64 - this.props.navigator.push({  
65 - component: CommonWebView,  
66 - passProps: {  
67 - url: item.url  
68 - }  
69 - });  
70 - }}  
71 > 65 >
72 <Image style={styles.itemImgWrapper} source={item.imgurl} /> 66 <Image style={styles.itemImgWrapper} source={item.imgurl} />
73 <View style={styles.itemRightWrapper}> 67 <View style={styles.itemRightWrapper}>
@@ -16,7 +16,7 @@ export default class Details extends Component { @@ -16,7 +16,7 @@ export default class Details extends Component {
16 constructor(props) { 16 constructor(props) {
17 super(props); 17 super(props);
18 this.state = { 18 this.state = {
19 - data: this.props.data, 19 + data: this.props.navigation.state.params.item,
20 text: "" 20 text: ""
21 }; 21 };
22 } 22 }
@@ -138,7 +138,6 @@ const styles = StyleSheet.create({ @@ -138,7 +138,6 @@ const styles = StyleSheet.create({
138 justifyContent: "flex-start", 138 justifyContent: "flex-start",
139 alignItems: "stretch", 139 alignItems: "stretch",
140 backgroundColor: "white", 140 backgroundColor: "white",
141 - paddingTop: 64  
142 }, 141 },
143 KAVContainer: { 142 KAVContainer: {
144 flex: 1, 143 flex: 1,
@@ -109,6 +109,7 @@ export default class InsuranceCircle extends Component { @@ -109,6 +109,7 @@ export default class InsuranceCircle extends Component {
109 } 109 }
110 110
111 render() { 111 render() {
  112 + const { navigate } = this.props.navigation;
112 return ( 113 return (
113 <View style={styles.container}> 114 <View style={styles.container}>
114 <ScrollView 115 <ScrollView
@@ -120,14 +121,7 @@ export default class InsuranceCircle extends Component { @@ -120,14 +121,7 @@ export default class InsuranceCircle extends Component {
120 <TouchableOpacity 121 <TouchableOpacity
121 style={styles.itemContainer} 122 style={styles.itemContainer}
122 key={index} 123 key={index}
123 - onPress={() => { 124 + onPress={() => navigate("Details", { item: item })}
124 - this.props.navigator.push({  
125 - component: Details,  
126 - passProps: {  
127 - data: {...item},  
128 - },  
129 - });  
130 - }}  
131 > 125 >
132 <Text style={styles.itemTitle} numberOfLines={2}> 126 <Text style={styles.itemTitle} numberOfLines={2}>
133 {item.title} 127 {item.title}