React Native Elements Tooltip(此处的文档)要求您传入工具提示的width和height属性,但我想创建一个通用的工具提示按钮,可以接收任何元素作为其popoverprop。
以下示例是我所拥有的,但它使用 React Native Element 库为工具提示设置的默认大小:
import React from 'react'
import { Tooltip } from 'react-native-elements'
import styled from 'styled-components'
const Container = styled.View`
justify-content: center;
align-items: center;
background-color: #aaf;
height: 25px;
width: 25px;
border-radius: 12.5px;
`
const Icon = styled.Text``
export default function TooltipButton({ tooltip }) {
return (
<Tooltip popover={tooltip}>
<Container>
<Icon>?</Icon>
</Container>
</Tooltip>
)
}
Run Code Online (Sandbox Code Playgroud)
当内容大于默认大小时,它看起来像这样。
我不想将固定大小作为支柱传递给该组件,我希望它有一个取决于其内容的工具提示大小。