【发布时间】:2019-11-27 18:11:53
【问题描述】:
我试图让搜索栏右侧的取消按钮在按下时隐藏。我尝试使用 showCancelButton 道具,但它不起作用。 Ant-Design React-Native Docs Link
这是问题复制回购https://github.com/kvnlee777/antd-rn-issue的链接
react-native 版本 0.61.4
ios 模拟器版本 12.4
import React, {useState} from 'react';
import { Alert, View} from 'react-native';
import { SearchBar } from '@ant-design/react-native';
const SearchBarDemo = () => {
const [value, setValue] = useState('');
const [showCancel, setShowCancel] = useState(true);
const onChange = (currentValue) => {
setValue(currentValue);
}
const clear = () => {
setValue('');
setShowCancel(false);
}
return (
<View style={{ marginTop: 30}}>
<SearchBar
value={value}
placeholder="Search products, brands"
onSubmit={value => Alert.alert(value)}
onCancel={clear}
onChange={onChange}
cancelText='Cancel'
showCancelButton={showCancel}
/>
</View>
);
};
export default SearchBarDemo;
【问题讨论】:
-
将 showCancel 的字符串更改为布尔值。
-
您好,感谢您的帮助。不幸的是,取消按钮在更改为 setShowCancel(false) 后仍然无法隐藏;
-
这是问题重现 repo github.com/kvnlee777/antd-rn-issue的链接
标签: reactjs react-native antd ant-design-pro