No Description

AnswerCreateViewController.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * Created by zack on 2018/4/29.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. TextInput,
  9. TouchableOpacity
  10. } from 'react-native'
  11. import React, {Component} from 'react'
  12. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  13. import BaseNavigationBarStyle from '../../base/BaseNavigationBarStyle'
  14. import HttpTools from '../../../network/HttpTools'
  15. import {auth, question, comment} from '../../../network/API'
  16. export default class AnswerCreateViewController extends Component {
  17. static navigatorButtons = {
  18. leftButtons: [
  19. {
  20. title: '取消', // for a textual button, provide the button title (label)
  21. id: 'cancel', // id for this button, given in onNavigatorEvent(event) to help understand which button was clicked
  22. buttonColor: '#000000', // Optional, iOS only. Set color for the button (can also be used in setButtons function to set different button style programatically)
  23. buttonFontSize: 14, // Set font size for the button (can also be used in setButtons function to set different button style programatically)
  24. },
  25. ],
  26. rightButtons: [
  27. {
  28. title: '发布', // for a textual button, provide the button title (label)
  29. id: 'submit', // id for this button, given in onNavigatorEvent(event) to help understand which button was clicked
  30. buttonColor: '#000000', // Optional, iOS only. Set color for the button (can also be used in setButtons function to set different button style programatically)
  31. buttonFontSize: 14, // Set font size for the button (can also be used in setButtons function to set different button style programatically)
  32. },
  33. ]
  34. };
  35. constructor(props) {
  36. super(props)
  37. this.state = {
  38. questionId: props.questionId,
  39. title: props.title,
  40. comment: ''
  41. }
  42. }
  43. componentDidMount() {
  44. this.props.navigator.setOnNavigatorEvent((event) => {
  45. if (event.type === 'NavBarButtonPress') { // this is the event type for button presses
  46. if (event.id === 'cancel') { // this is the same id field from the static navigatorButtons definition
  47. this.props.navigator.dismissModal()
  48. }else if (event.id === 'submit') {
  49. this.submitComment()
  50. }
  51. }
  52. })
  53. }
  54. submitComment() {
  55. if (!this.state.comment.length) {
  56. alert("请输入你的回答内容")
  57. return
  58. }
  59. const param = JSON.stringify({
  60. content: this.state.comment,
  61. model_id: this.state.questionId,
  62. model_type: "question",
  63. related_id: "" //回答这个问题,不需要传递
  64. })
  65. HttpTools.post(comment, param, (response) => {
  66. }, (error) => {
  67. })
  68. this.props.navigator.dismissModal()
  69. }
  70. render() {
  71. return(
  72. <View style={styles.View}>
  73. <View style={styles.BottomTextView}>
  74. <Text style={styles.BottomText}>{this.state.title}</Text>>
  75. </View>
  76. <TextInput onChangeText={(text) => {
  77. this.setState({comment: text})
  78. }} style={styles.TextInput} multiline={true} placeholderTextColor={'#9c9c9c'} placeholder={'分享你的真是观点和经验'}/>
  79. </View>
  80. )
  81. }
  82. }
  83. const styles = StyleSheet.create({
  84. View: {
  85. width: ScreenDimensions.width,
  86. height: ScreenDimensions.height - NavigationBarHeight.height,
  87. backgroundColor: 'white'
  88. },
  89. BottomTextView: {
  90. width: ScreenDimensions.width,
  91. marginTop: NavigationBarHeight.height,
  92. borderBottomWidth: 0.5,
  93. borderBottomColor: '#efeff4',
  94. justifyContent: 'center',
  95. alignItems: 'center'
  96. },
  97. BottomText: {
  98. color: "#505050",
  99. fontSize: 17,
  100. textAlign: 'center',
  101. paddingLeft: 28,
  102. paddingRight: 28,
  103. paddingTop: 30,
  104. paddingBottom: 30,
  105. },
  106. TextInput: {
  107. paddingTop: 14,
  108. width: ScreenDimensions.width,
  109. color: "#000000",
  110. fontSize: 17,
  111. paddingLeft: 28,
  112. paddingRight: 28,
  113. height: 200,
  114. textAlignVertical: 'top'
  115. }
  116. })