HomeScreen.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import React from "react";
  2. import {connect} from 'react-redux'
  3. import {View, Text, Button,TouchableHighlight,StyleSheet,Image,TouchableOpacity} 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. import NavigationUtil from "../navigator/NavigationUtil";
  9. const YRRnBridge = NativeModules.YRRnBridge;
  10. class HomeScreen extends React.Component {
  11. static navigationOptions = {
  12. title: 'DetailsScreen',
  13. headerBackTitle:'返回',//设置返回此页面的返回按钮文案,有长度限制
  14. headerLeft:(
  15. <TouchableOpacity style={{marginLeft:0,width:50,height:30}}
  16. onPress={() => {
  17. YRRnBridge.goBack();
  18. }}
  19. >
  20. <Image style={{marginLeft:20,marginTop:6,width:12,height:20,}}
  21. source={{uri: 'uu_back-icon'}}
  22. ></Image>
  23. </TouchableOpacity>
  24. )
  25. }
  26. loadData=()=>{
  27. //fetch请求
  28. console.log("loadData():",API.TEST_GET);
  29. YRHttpRequest.get(API.TEST_GET).then(res=>{
  30. console.log("res.data=",res);
  31. }).catch(err=>{
  32. console.log("res.data=",err);
  33. })
  34. //axios请求
  35. // console.log("loadData():",API.TEST_GET);
  36. // sendGet({url:API.TEST_GET,params:{
  37. // name:'arison'
  38. // }}).then(res=>{
  39. // console.log("res.data=",res);
  40. // }).catch(err=>{
  41. // console.log("res.data=",err);
  42. // })
  43. }
  44. componentDidMount() {
  45. //适配iOS侧滑返回
  46. this.viewDidAppear = this.props.navigation.addListener( //类似OC里的 viewDidAppear方法
  47. 'didFocus',// 有4个取值 willFocus即将显示、didFocus完成显示、willBlur即将消失、didBlur消失
  48. (obj)=>{
  49. YRRnBridge.gestureEnabled(true);
  50. }
  51. )
  52. this.viewWillDisappear = this.props.navigation.addListener(//类似OC里的 viewWillDisappear方法
  53. 'willBlur', // 有4个取值 willFocus即将显示、didFocus完成显示、willBlur即将消失、didBlur消失
  54. (obj)=>{
  55. YRRnBridge.gestureEnabled(false);
  56. }
  57. )
  58. }
  59. componentWillUnmount() { // 移除监听
  60. this.viewDidAppear.remove();
  61. this.viewWillDisappear.remove();
  62. }
  63. render() {
  64. const {navigation} = this.props;
  65. NavigationUtil.navigation = navigation;
  66. return (
  67. <View style={{flex: 1, alignItems: "center", justifyContent: "center"}}>
  68. <Text style={{marginBottom: 10}}>Home Screen</Text>
  69. <Button
  70. title="详情页"
  71. onPress={() => {
  72. navigation.navigate('Details', {name: '动态的'});
  73. }}
  74. />
  75. <Text style={{marginBottom: 10}}>{this.props.btnText}</Text>
  76. <Button title="更新文字"
  77. onPress={() => {
  78. this.props.changeText("我的第一个ReactNative项目!");
  79. }}/>
  80. <Button style={{marginBottom: 10}}
  81. title="断点调式" onPress={()=>{
  82. for (let i = 0; i < 10; i++) {
  83. console.log("i*i=",i*i);
  84. }
  85. }}/>
  86. <TouchableHighlight
  87. underlayColor="#FF00FF"
  88. activeOpacity={1}
  89. style={styles.button} onPress={this.loadData.bind(this)}>
  90. <Text style={styles.text} > Touch Here </Text>
  91. </TouchableHighlight>
  92. <Button title="热更新测试"
  93. onPress={() => {
  94. NavigationUtil.goPage({name: '热更新'},'CodePushPage');
  95. // navigation.navigate('CodePushPage', {name: '热更新'});
  96. }}/>
  97. <Button title="图表测试"
  98. onPress={() => {
  99. navigation.navigate('EChartsPage', {name: '图表'});
  100. }}/>
  101. </View>
  102. );
  103. }
  104. }
  105. const styles = StyleSheet.create({
  106. container: {
  107. flex: 1,
  108. justifyContent: 'center',
  109. paddingHorizontal: 10
  110. },
  111. button: {
  112. alignItems: 'center',
  113. backgroundColor: '#DDDDDD',
  114. borderRadius:5,
  115. padding: 10,
  116. margin:10
  117. },
  118. countContainer: {
  119. alignItems: 'center',
  120. padding: 10
  121. },
  122. countText: {
  123. color: '#FF00FF'
  124. },
  125. text:{
  126. fontWeight:'600',
  127. color:'#FFFFFF'
  128. }
  129. })
  130. const mapStateToProps = state => ({
  131. btnText:state.pageMainReducer.btnText
  132. })
  133. const mapDispatchToProps = dispatch => ({
  134. changeText:(text)=>{
  135. dispatch(changeBtnText(text));
  136. }
  137. })
  138. export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen)