HomeScreen.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. import YRSearchBar from "../common/YRSearchBar";
  8. class HomeScreen extends React.Component {
  9. static navigationOptions = {
  10. title: '主页面',
  11. headerStyle: Platform.OS === 'android' ? {
  12. paddingTop: StatusBar.currentHeight,
  13. height: StatusBar.currentHeight + 56,
  14. } : {}
  15. }
  16. constructor(props){
  17. super(props);
  18. this.state={
  19. name:'YRSearchBar',
  20. inputValue:""
  21. };
  22. }
  23. loadData=()=>{
  24. //fetch请求
  25. console.log("loadData():",API.TEST_GET);
  26. YRHttpRequest.get(API.TEST_GET).then(res=>{
  27. console.log("res.data=",res);
  28. }).catch(err=>{
  29. console.log("res.data=",err);
  30. })
  31. //axios请求
  32. // console.log("loadData():",API.TEST_GET);
  33. // sendGet({url:API.TEST_GET,params:{
  34. // name:'arison'
  35. // }}).then(res=>{
  36. // console.log("res.data=",res);
  37. // }).catch(err=>{
  38. // console.log("res.data=",err);
  39. // })
  40. }
  41. onSearchChangeText=(text)=>{
  42. console.log("onSearchChangeText() text:",text);
  43. if (text) {
  44. this.setState({ inputValue: text })
  45. clearTimeout(this.settimeId);
  46. this.settimeId = setTimeout(() => {
  47. }, 1000);
  48. } else {
  49. this.setState({inputValue: ''})
  50. }
  51. }
  52. onSearch=(inputValue)=>{
  53. console.log("onSearch()",inputValue);
  54. }
  55. render() {
  56. const {navigation} = this.props;
  57. return (<View>
  58. <YRSearchBar
  59. value={this.state.inputValue}
  60. placeholder="搜索"
  61. onSearch={this.onSearch}
  62. onSearchChangeText={this.onSearchChangeText}/>
  63. <View style={{ alignItems: "center", justifyContent: "center"}}>
  64. <Text style={{marginBottom: 10}}>Home Screen</Text>
  65. <Button
  66. title="详情页"
  67. onPress={() => {
  68. navigation.navigate('Details', {name: '动态的'});
  69. }}
  70. />
  71. <Button
  72. title="异步进度条"
  73. onPress={() => {
  74. navigation.navigate('YRSearchBar', {name: '进度条'});
  75. }}
  76. />
  77. <Button
  78. title="自定义对话框"
  79. onPress={() => {
  80. navigation.navigate('YRModel', {name: '进度条'});
  81. }}
  82. />
  83. <Text style={{marginBottom: 10}}>{this.props.btnText}</Text>
  84. <Button title="更新文字"
  85. onPress={() => {
  86. this.props.changeText("我的第一个ReactNative项目!");
  87. }}/>
  88. <Button style={{marginBottom: 10}}
  89. title="断点调式" onPress={()=>{
  90. for (let i = 0; i < 10; i++) {
  91. console.log("i*i=",i*i);
  92. }
  93. }}/>
  94. <TouchableHighlight
  95. underlayColor="#FF00FF"
  96. activeOpacity={1}
  97. style={styles.button} onPress={this.loadData.bind(this)}>
  98. <Text style={styles.text} > Touch Here </Text>
  99. </TouchableHighlight>
  100. </View>
  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)