react-native:0.53.0
react-native-elements:1.0.0-beta4,
当我使用React Native Elements库中的搜索栏组件时,我无法捕获' onCancel'属性。代码如下。
<SearchBar
lightTheme
clearIcon
platform={Platform.OS === "ios" ? "ios" : "android"}
placeholder="Search..."
returnKeyType='search'
cancelButtonTitle="Cancel"
onCancel ={()=>{this.doSomething();}}
onSubmitEditing ={()=>{this.handleSearch();}}
/>
答案 0 :(得分:1)
答案 1 :(得分:0)
总结一下,这是一个语法错误。 =(
当我打电话时
onCancel={()=>{this.doSomething();}}
我用&#39; {}&#39;包裹它。应该是
onCancel={()=>this.viewHeader()}
我确实想指出那些电话:
onFocus ={()=>{this.hideHeader();}}
onBlur ={()=>{this.viewHeader();}}
是有效的呼叫并且行为正常。我认为这是由于React-Native-Elements的实现。函数onFocus()和onBlur()显式写在docs中。
onFocus = () => {
this.props.onFocus();
UIManager.configureNextLayoutAnimation &&
LayoutAnimation.easeInEaseOut();
this.setState({ hasFocus: true });
};
onBlur = () => {
this.props.onBlur();
UIManager.configureNextLayoutAnimation &&
LayoutAnimation.easeInEaseOut();
this.setState({ hasFocus: false });
};
onChangeText = text => {
this.props.onChangeText(text);
this.setState({ isEmpty: text === '' });
};