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.6KB

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