HomeScreen.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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('YRDatePicker', {name: '进度条'});
  48. }}
  49. />
  50. <Button
  51. title="自定义对话框"
  52. onPress={() => {
  53. navigation.navigate('YRModel', {name: '进度条'});
  54. }}
  55. />
  56. <Text style={{marginBottom: 10}}>{this.props.btnText}</Text>
  57. <Button title="更新文字"
  58. onPress={() => {
  59. this.props.changeText("我的第一个ReactNative项目!");
  60. }}/>
  61. <Button style={{marginBottom: 10}}
  62. title="断点调式" onPress={()=>{
  63. for (let i = 0; i < 10; i++) {
  64. console.log("i*i=",i*i);
  65. }
  66. }}/>
  67. <TouchableHighlight
  68. underlayColor="#FF00FF"
  69. activeOpacity={1}
  70. style={styles.button} onPress={this.loadData.bind(this)}>
  71. <Text style={styles.text} > Touch Here </Text>
  72. </TouchableHighlight>
  73. </View>
  74. );
  75. }
  76. }
  77. const styles = StyleSheet.create({
  78. container: {
  79. flex: 1,
  80. justifyContent: 'center',
  81. paddingHorizontal: 10
  82. },
  83. button: {
  84. alignItems: 'center',
  85. backgroundColor: '#DDDDDD',
  86. borderRadius:5,
  87. padding: 10,
  88. margin:10
  89. },
  90. countContainer: {
  91. alignItems: 'center',
  92. padding: 10
  93. },
  94. countText: {
  95. color: '#FF00FF'
  96. },
  97. text:{
  98. fontWeight:'600',
  99. color:'#FFFFFF'
  100. }
  101. })
  102. const mapStateToProps = state => ({
  103. btnText:state.pageMainReducer.btnText
  104. })
  105. const mapDispatchToProps = dispatch => ({
  106. changeText:(text)=>{
  107. dispatch(changeBtnText(text));
  108. }
  109. })
  110. export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen)