您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InputDialog.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // @flow
  2. import React from 'react';
  3. import { View, Text, TextInput, TouchableOpacity } from 'react-native';
  4. import { translate } from '../../../i18n';
  5. import { connect } from '../../../redux';
  6. import { StyleType } from '../../../styles';
  7. import { _abstractMapStateToProps } from '../../functions';
  8. import { type State as AbstractState } from '../AbstractDialog';
  9. import BaseDialog, { type Props as BaseProps } from './BaseDialog';
  10. import {
  11. FIELD_UNDERLINE,
  12. brandedDialog,
  13. inputDialog as styles
  14. } from './styles';
  15. type Props = BaseProps & {
  16. /**
  17. * The color-schemed stylesheet of the feature.
  18. */
  19. _dialogStyles: StyleType,
  20. /**
  21. * The untranslated i18n key for the field label on the dialog.
  22. */
  23. contentKey: string,
  24. t: Function,
  25. textInputProps: ?Object
  26. }
  27. type State = {
  28. ...AbstractState,
  29. /**
  30. * The current value of the field.
  31. */
  32. fieldValue: ?string
  33. };
  34. /**
  35. * Implements a single field input dialog component.
  36. */
  37. class InputDialog extends BaseDialog<Props, State> {
  38. /**
  39. * Instantiates a new {@code InputDialog}.
  40. *
  41. * @inheritdoc
  42. */
  43. constructor(props: Props) {
  44. super(props);
  45. this.state = {
  46. fieldValue: undefined
  47. };
  48. this._onChangeText = this._onChangeText.bind(this);
  49. this._onSubmitValue = this._onSubmitValue.bind(this);
  50. }
  51. /**
  52. * Implements {@code BaseDialog._renderContent}.
  53. *
  54. * @inheritdoc
  55. */
  56. _renderContent() {
  57. const { _dialogStyles, okDisabled, t } = this.props;
  58. return (
  59. <View>
  60. <View
  61. style = { [
  62. brandedDialog.mainWrapper,
  63. styles.fieldWrapper
  64. ] }>
  65. <Text style = { _dialogStyles.fieldLabel }>
  66. { t(this.props.contentKey) }
  67. </Text>
  68. <TextInput
  69. onChangeText = { this._onChangeText }
  70. style = { _dialogStyles.field }
  71. underlineColorAndroid = { FIELD_UNDERLINE }
  72. value = { this.state.fieldValue }
  73. { ...this.props.textInputProps } />
  74. </View>
  75. <View style = { brandedDialog.buttonWrapper }>
  76. <TouchableOpacity
  77. disabled = { okDisabled }
  78. onPress = { this._onSubmitValue }
  79. style = { [
  80. _dialogStyles.button,
  81. brandedDialog.buttonFarLeft,
  82. brandedDialog.buttonFarRight
  83. ] }>
  84. <Text style = { _dialogStyles.buttonLabel }>
  85. { t('dialog.Ok') }
  86. </Text>
  87. </TouchableOpacity>
  88. </View>
  89. </View>
  90. );
  91. }
  92. _onCancel: () => void;
  93. _onChangeText: string => void;
  94. /**
  95. * Callback to be invoked when the text in the field changes.
  96. *
  97. * @param {string} fieldValue - The updated field value.
  98. * @returns {void}
  99. */
  100. _onChangeText(fieldValue) {
  101. this.setState({
  102. fieldValue
  103. });
  104. }
  105. _onSubmit: (?string) => boolean;
  106. _onSubmitValue: () => boolean;
  107. /**
  108. * Callback to be invoked when the value of this dialog is submitted.
  109. *
  110. * @returns {boolean}
  111. */
  112. _onSubmitValue() {
  113. return this._onSubmit(this.state.fieldValue);
  114. }
  115. }
  116. export default translate(connect(_abstractMapStateToProps)(InputDialog));