【问题标题】:Ant-Design React-Native Search Bar Cancel Button cannot hide itself when pressedAnt-Design React-Native 搜索栏取消按钮在按下时无法隐藏
【发布时间】: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


【解决方案1】:

您正在使用字符串来表示真假。字符串 'false' 的计算结果为 true

'true''false' 替换为truefalse,它应该可以工作

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-12
  • 1970-01-01
相关资源
最近更新 更多