You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InputDialog.js 3.3KB

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