HomeScreen.js 3.4 KB

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