Skip to content

Commit

Permalink
Work around undo bug with custom TextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed Sep 25, 2020
1 parent 1df1960 commit 2dc6a35
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/usecase/buffers/ui/BufferContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,6 +73,7 @@ class BufferContainer extends React.Component<Props, State> {
showTabButton: false
});
}

handleOnLongPress(type, text) {
ActionSheetIOS.showShareActionSheetWithOptions(
{
Expand All @@ -82,6 +84,7 @@ class BufferContainer extends React.Component<Props, State> {
() => null
);
}

handleOnPress(type, text) {
console.log(type, text);
if (type === "channel") {
Expand Down Expand Up @@ -178,7 +181,7 @@ class BufferContainer extends React.Component<Props, State> {
parseArgs={this.parseArgs}
/>
<View style={styles.bottomBox}>
<TextInput
<UndoTextInput
style={styles.inputBox}
value={textValue}
onChangeText={this.handleChangeText}
Expand Down
37 changes: 37 additions & 0 deletions src/usecase/buffers/ui/UndoTextInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from "react";
import { TextInput } from 'react-native';

type Props = React.ComponentProps<typeof TextInput>;

export default class UndoTextInput extends React.PureComponent<Props> {
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 (
<TextInput {...rest}
ref={input => this.textInput = input}
onChangeText={this.handleChangeText}
/>
);
}
}

0 comments on commit 2dc6a35

Please sign in to comment.