No Description

QuestionCreateViewController.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * Created by zack on 2018/4/29.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. TextInput,
  9. TouchableOpacity,
  10. Platform
  11. } from 'react-native'
  12. import React, {Component} from 'react'
  13. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  14. import BaseNavigationBarStyle from '../../base/BaseNavigationBarStyle'
  15. import ToastMsg from '../../../utils/ToastMsg'
  16. export default class QuestionCreateViewController 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: 'next', // 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. questionName: props.questionName,
  39. questionTitle: ''
  40. }
  41. }
  42. hideTabBar() {
  43. this.props.navigator.toggleTabs({
  44. to:'hidden',
  45. animated: true
  46. })
  47. }
  48. componentDidMount() {
  49. this.props.navigator.setOnNavigatorEvent((event) => {
  50. if (event.type === 'NavBarButtonPress') { // this is the event type for button presses
  51. if (event.id === 'cancel') { // this is the same id field from the static navigatorButtons definition
  52. if (Platform.OS === 'ios') {
  53. this.props.navigator.dismissModal()
  54. }else {
  55. this.props.navigator.pop()
  56. }
  57. }
  58. if (event.id === 'next') {
  59. if (!this.state.questionTitle.length) {
  60. ToastMsg.show('请先输入您的问题')
  61. return;
  62. }
  63. this.props.navigator.push({
  64. screen: 'QuestionCreateAddImageViewController',
  65. title: '提问',
  66. backButtonTitle: '',
  67. passProps: {
  68. questionTitle: this.state.questionTitle
  69. },
  70. navigatorStyle: BaseNavigationBarStyle
  71. })
  72. }
  73. }
  74. })
  75. }
  76. render() {
  77. return(
  78. <View style={styles.View}>
  79. <TextInput underlineColorAndroid={'transparent'} onChangeText={(text) => {
  80. this.setState({questionTitle: text})
  81. }} defaultValue={this.state.questionName} placeholderTextColor={'#9c9c9c'} placeholder={'请输入问题'} style={styles.TextInput} />
  82. <TouchableOpacity>
  83. <Text style={styles.BottomText}>{'什么是一个好问题?'}</Text>
  84. </TouchableOpacity>
  85. </View>
  86. )
  87. }
  88. }
  89. const styles = StyleSheet.create({
  90. View: {
  91. width: ScreenDimensions.width,
  92. height: ScreenDimensions.height - NavigationBarHeight.height,
  93. backgroundColor: 'white'
  94. },
  95. TextInput: {
  96. marginTop: NavigationBarHeight.height,
  97. width: ScreenDimensions.width,
  98. height: 61,
  99. color: '#000000',
  100. fontSize: 16,
  101. textAlign: 'center',
  102. borderBottomWidth: 0.5,
  103. borderBottomColor: '#efeff4'
  104. },
  105. BottomText: {
  106. marginTop: 30,
  107. width: ScreenDimensions.width,
  108. textAlign: 'center',
  109. color: '#4396d7',
  110. fontSize: 12
  111. }
  112. })