HomeScreen.js 3.4 KB

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