From 6bfb532e400bc8517152824e3c970d2c6f4259f8 Mon Sep 17 00:00:00 2001 From: Samvel Avanesov Date: Tue, 18 Dec 2018 14:25:05 -0500 Subject: [PATCH] fix: resize autogrowing text input back on clear. resize on paste [ch17995] --- app/components/controls/auto-expanding-textinput.js | 12 +++++++----- app/components/layout/input-main.js | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/components/controls/auto-expanding-textinput.js b/app/components/controls/auto-expanding-textinput.js index 962452c12..3f9ea99c5 100644 --- a/app/components/controls/auto-expanding-textinput.js +++ b/app/components/controls/auto-expanding-textinput.js @@ -2,8 +2,10 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { observer } from 'mobx-react/native'; import { observable } from 'mobx'; +import _ from 'lodash'; import { vars } from '../../styles/styles'; import TextInputUncontrolled from './text-input-uncontrolled'; +import { transitionAnimation } from '../helpers/animations'; @observer export default class AutoExpandingTextInput extends Component { @@ -18,17 +20,17 @@ export default class AutoExpandingTextInput extends Component { } _onContentSizeChange = event => { - const curHeight = event.nativeEvent.contentSize.height; - if (curHeight < this.props.minHeight || curHeight > this.props.maxHeight) return; - this.height = curHeight; + const { maxHeight, minHeight } = this.props; + this.height = _.clamp(event.nativeEvent.contentSize.height, minHeight, maxHeight); }; setRef = ref => { this.textInputRef = ref; }; - clear() { - this.textInputRef.clear(); + resetHeight() { + transitionAnimation(); + this.height = this.props.minHeight; } focus() { diff --git a/app/components/layout/input-main.js b/app/components/layout/input-main.js index a4939e893..20636eba1 100644 --- a/app/components/layout/input-main.js +++ b/app/components/layout/input-main.js @@ -43,6 +43,7 @@ export default class InputMain extends SafeComponent { if (!this.canSend) return; this.hasText ? this.props.send(this.value) : this.props.sendAck(); this.value = ''; + this.textInputRef.resetHeight(); } setFocus() {