我想手动关闭工具提示,但 react-native-elements 站点上没有文档。
所以我查看了来自 github 的工具提示代码,并注意到它有一个 toggleTooltip 功能来切换。不幸的是,我无法让它工作。
这是工具提示的示例代码
import { Tooltip } from 'react-native-elements';
render() {
return (
<Tooltip
ref="tooltip"
popover={
<ComponentTest
toggle={this.refs.tooltip}
>
>
<Text>Click me</Text>
</Tooltip>
);
}
ComponentTest 的示例代码
import { Button } from 'react-native-elements';
toggleOff = () => {
this.props.toggleTooltip;
}
render() {
return (
<Button
title="hide"
type="outline"
onPress={this.toggleOff}
/>
);
}
这是我正在尝试使用的 tooltip.js 中的功能。工具提示的完整代码可以在这里找到https://github.com/react-native-training/react-native-elements/blob/master/src/tooltip/Tooltip.js
toggleTooltip = () => {
const { onClose } = this.props;
this.getElementPosition();
this.setState(prevState => {
if (prevState.isVisible && !isIOS) {
onClose && onClose();
}
return { isVisible: !prevState.isVisible };
});
};