From 2dc6a3551f996ef6bb1762761566c9528865c340 Mon Sep 17 00:00:00 2001 From: Matthew Horan Date: Thu, 24 Sep 2020 21:16:23 -0400 Subject: [PATCH] Work around undo bug with custom TextInput See https://github.com/facebook/react-native/issues/29572. --- src/usecase/buffers/ui/BufferContainer.tsx | 5 ++- src/usecase/buffers/ui/UndoTextInput.tsx | 37 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/usecase/buffers/ui/UndoTextInput.tsx diff --git a/src/usecase/buffers/ui/BufferContainer.tsx b/src/usecase/buffers/ui/BufferContainer.tsx index 517fa92..a9ce1e4 100644 --- a/src/usecase/buffers/ui/BufferContainer.tsx +++ b/src/usecase/buffers/ui/BufferContainer.tsx @@ -21,6 +21,7 @@ import { getParseArgs } from "../../../lib/helpers/parse-text-args"; import { formatUrl } from "../../../lib/helpers/url-formatter"; import { renderWeechatFormat } from "../../../lib/weechat/color-formatter"; import { StoreState } from "../../../store"; +import UndoTextInput from "./UndoTextInput"; interface Props { buffer: WeechatBuffer | null; @@ -72,6 +73,7 @@ class BufferContainer extends React.Component { showTabButton: false }); } + handleOnLongPress(type, text) { ActionSheetIOS.showShareActionSheetWithOptions( { @@ -82,6 +84,7 @@ class BufferContainer extends React.Component { () => null ); } + handleOnPress(type, text) { console.log(type, text); if (type === "channel") { @@ -178,7 +181,7 @@ class BufferContainer extends React.Component { parseArgs={this.parseArgs} /> - ; + +export default class UndoTextInput extends React.PureComponent { + constructor(props: Props) { + super(props) + this.value = props.value; + } + + textInput: TextInput; + value: string; + + componentDidUpdate() { + const { value } = this.props; + if (value !== this.value) { + this.textInput.setNativeProps({ text: value }) + this.value = value; + } + } + + handleChangeText = (textValue: string) => { + this.value = textValue; + this.props.onChangeText(textValue); + } + + render() { + const { value, onChangeText, ...rest } = this.props; + return ( + this.textInput = input} + onChangeText={this.handleChangeText} + /> + ); + } +} \ No newline at end of file