HomeScreen.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React from "react";
  2. import {connect} from 'react-redux'
  3. import {View, Text, Button,TouchableHighlight,StyleSheet} from "react-native";
  4. import {changeBtnText} from "../../actions/bi/index";
  5. import YRHttpRequest from "../../utils/network/fetch"
  6. import {API} from "../../utils/network/axios/api.config";
  7. class HomeScreen extends React.Component {
  8. loadData=()=>{
  9. //fetch请求
  10. console.log("loadData():",API.TEST_GET);
  11. YRHttpRequest.get(API.TEST_GET).then(res=>{
  12. console.log("res.data=",res);
  13. }).catch(err=>{
  14. console.log("res.data=",err);
  15. })
  16. //axios请求
  17. // console.log("loadData():",API.TEST_GET);
  18. // sendGet({url:API.TEST_GET,params:{
  19. // name:'arison'
  20. // }}).then(res=>{
  21. // console.log("res.data=",res);
  22. // }).catch(err=>{
  23. // console.log("res.data=",err);
  24. // })
  25. }
  26. render() {
  27. const {navigation} = this.props;
  28. return (
  29. <View style={{flex: 1, alignItems: "center", justifyContent: "center"}}>
  30. <Text style={{marginBottom: 10}}>Home Screen</Text>
  31. <Button
  32. title="详情页"
  33. onPress={() => {
  34. navigation.navigate('Details', {name: '动态的'});
  35. }}
  36. />
  37. <Text style={{marginBottom: 10}}>{this.props.btnText}</Text>
  38. <Button title="更新文字"
  39. onPress={() => {
  40. this.props.changeText("我的第一个ReactNative项目!");
  41. }}/>
  42. <Button style={{marginBottom: 10}}
  43. title="断点调式" onPress={()=>{
  44. for (let i = 0; i < 10; i++) {
  45. console.log("i*i=",i*i);
  46. }
  47. }}/>
  48. <TouchableHighlight
  49. underlayColor="#FF00FF"
  50. activeOpacity={1}
  51. style={styles.button} onPress={this.loadData.bind(this)}>
  52. <Text style={styles.text} > Touch Here </Text>
  53. </TouchableHighlight>
  54. </View>
  55. );
  56. }
  57. }
  58. const styles = StyleSheet.create({
  59. container: {
  60. flex: 1,
  61. justifyContent: 'center',
  62. paddingHorizontal: 10
  63. },
  64. button: {
  65. alignItems: 'center',
  66. backgroundColor: '#DDDDDD',
  67. borderRadius:5,
  68. padding: 10,
  69. margin:10
  70. },
  71. countContainer: {
  72. alignItems: 'center',
  73. padding: 10
  74. },
  75. countText: {
  76. color: '#FF00FF'
  77. },
  78. text:{
  79. fontWeight:'600',
  80. color:'#FFFFFF'
  81. }
  82. })
  83. const mapStateToProps = state => ({
  84. btnText:state.pageMainReducer.btnText
  85. })
  86. const mapDispatchToProps = dispatch => ({
  87. changeText:(text)=>{
  88. dispatch(changeBtnText(text));
  89. }
  90. })
  91. export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen)