From 509dfe554289c64d760cb020558646cc8cee3fc2 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 3 Jul 2018 19:04:04 -0400 Subject: [PATCH] MM-11116 Re-added QuickTextInput and added another hack on top of it (#1871) * MM-11116 Re-added updated QuickTextInput component to work around RN issue * MM-11116 Work around setNativeProps not working for TextInputs * Add isFocused method to QuickTextInput --- app/components/post_textbox/post_textbox.js | 5 +- app/components/quick_text_input.js | 120 ++++++++++++++++++ .../search_bar/search_bar.android.js | 4 +- .../text_input_with_localized_placeholder.js | 4 +- app/screens/edit_profile/edit_profile_item.js | 4 +- app/screens/login/login.js | 6 +- app/screens/select_server/select_server.js | 4 +- .../android/extension_post/extension_post.js | 4 +- share_extension/ios/extension_post.js | 4 +- 9 files changed, 139 insertions(+), 16 deletions(-) create mode 100644 app/components/quick_text_input.js diff --git a/app/components/post_textbox/post_textbox.js b/app/components/post_textbox/post_textbox.js index a6f5cddc6d..38c4253558 100644 --- a/app/components/post_textbox/post_textbox.js +++ b/app/components/post_textbox/post_textbox.js @@ -3,7 +3,7 @@ import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; -import {Alert, BackHandler, Keyboard, Platform, Text, TextInput, TouchableOpacity, View} from 'react-native'; +import {Alert, BackHandler, Keyboard, Platform, Text, TouchableOpacity, View} from 'react-native'; import {intlShape} from 'react-intl'; import {RequestStatus} from 'mattermost-redux/constants'; import EventEmitter from 'mattermost-redux/utils/event_emitter'; @@ -11,6 +11,7 @@ import EventEmitter from 'mattermost-redux/utils/event_emitter'; import AttachmentButton from 'app/components/attachment_button'; import Autocomplete from 'app/components/autocomplete'; import FileUploadPreview from 'app/components/file_upload_preview'; +import QuickTextInput from 'app/components/quick_text_input'; import {INITIAL_HEIGHT, INSERT_TO_COMMENT, INSERT_TO_DRAFT, IS_REACTION_REGEX, MAX_CONTENT_HEIGHT, MAX_FILE_COUNT} from 'app/constants/post_textbox'; import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme'; @@ -494,7 +495,7 @@ export default class PostTextbox extends PureComponent { {!channelIsReadOnly && attachmentButton} - { + if (!this.input) { + return; + } + + this.input.setNativeProps({text: this.props.value}); + this.storedValue = this.props.value; + } + + focus() { + this.input.focus(); + } + + blur() { + this.input.blur(); + } + + isFocused() { + return this.input.isFocused(); + } + + handleChangeText = (value) => { + this.storedValue = value; + + if (this.props.onChangeText) { + this.props.onChangeText(value); + } + } + + setInput = (input) => { + this.input = input; + } + + render() { + const props = {...this.props}; + + // Specifying a value or defaultValue cause the issues noted above + Reflect.deleteProperty(props, 'value'); + Reflect.deleteProperty(props, 'defaultValue'); + + return ( + + ); + } +} diff --git a/app/components/search_bar/search_bar.android.js b/app/components/search_bar/search_bar.android.js index 47b40b9482..778bd9c53a 100644 --- a/app/components/search_bar/search_bar.android.js +++ b/app/components/search_bar/search_bar.android.js @@ -5,13 +5,13 @@ import PropTypes from 'prop-types'; import { InteractionManager, Keyboard, - TextInput, StyleSheet, View, TouchableWithoutFeedback, } from 'react-native'; import Icon from 'react-native-vector-icons/MaterialIcons'; +import QuickTextInput from 'app/components/quick_text_input'; import CustomPropTypes from 'app/constants/custom_prop_types'; import {changeOpacity} from 'app/utils/theme'; @@ -208,7 +208,7 @@ export default class SearchBarAndroid extends PureComponent { color={tintColorSearch || placeholderTextColor} /> } - - - - - - -