setNativeProps({ text: '' })
を使用してテキスト入力をクリアしようとしていますが、これは一般的な方法です - 状態の変化がちらつくため - setNativeProps
が呼び出されたときにonChange
が呼び出されないことに気付きました。私にとっては、サイズ変更可能なTextAreaを使用しているため、これは問題です。高さをリセットするにはTextAreaが必要ですが、現在行われているのはonChange
です。React Native - TextInput.setNativePropsがonChangeをトリガーしていません
誰かが私の問題について光を当てることができれば、それは非常に感謝しています。ここで
は私の他のコンポーネントからコンポーネント
import React, { Component } from 'react';
import {
TextInput,
} from 'react-native';
export default class Input extends Component {
constructor() {
super();
this.state = {
height: 35,
};
this.handleChange = this.handleChange.bind(this);
}
componentWillMount() {
const { defaultHeight } = this.props;
if (defaultHeight) {
this.setState({
height: defaultHeight,
});
}
}
handleChange(event) {
console.log(event);
if (this.state.height !== event.nativeEvent.contentSize.height) {
this.setState({
height: Math.max(this.props.defaultHeight, event.nativeEvent.contentSize.height),
});
}
if (this.props.onChange) {
this.props.onChange(event);
}
}
render() {
const { style, ...props } = this.props;
return (
<TextInput
ref="input"
style={[{ height:this.state.height }, style]}
multiline
{...props}
onChange={this.handleChange}
/>);
}
}
Input.propTypes = {
style: React.PropTypes.number,
onChange: React.PropTypes.func,
defaultHeight: React.PropTypes.number,
};
で、私は
this.refs.input.refs.input.setNativeProps({ text: '' });
プラグインを使用していますか?はいの場合はどちらですか?コンポーネントのコードを投稿できますか? –
@AdamTerlson私はちょうどコードを持つ質問を更新しました –