Styles from stylesheet is not applied.

huangapple go评论52阅读模式
英文:

Styles from stylesheet is not applied

问题

I'm trying to style a component but it doesn't look like the styles that I'm using is getting applied.

toolTipStyle gets prop-drilled down to the component, but I can see that they exist if I console.log them.

The component LinkCopiedToolTip gets rendered depending on the state hasCopiedInvitationLink like this in a parent component:

{hasCopiedInvitationLink && (
  <LinkCopiedToolTip
    disclaimerText={disclaimerText}
    isDesktop={isDesktop}
    tooltipStyle={{ ...tooltipContainer, ...fadeOut }}
    setHasCopiedInvitationLink={setHasCopiedInvitationLink}
  />
)}

Any takes? I'm at my wits' end here. Thanks!

Tried a bunch of stuff. If I just hardcode the styles directly it works.

英文:

I'm trying to style a component but it doesn't look like the styles that I'm using is getting applied.

toolTipStyle gets prop-drilled down to the component but and I can see that they exist if I console.log them.

export const LinkCopiedToolTip = ({
  disclaimerText,
  isDesktop,
  tooltipStyle,
  setHasCopiedInvitationLink,
}) =&gt; {
  const [fadeOutTooltip, setFadeOutTooltip] = useState&lt;boolean&gt;(false)

...
...
...

  return (
    &lt;View style={{ ...tooltipStyle.tooltipContainer, ...(fadeOutTooltip &amp;&amp; tooltipStyle.fadeOut) }}&gt;
      &lt;Tooltip hasFluidWidth arrow={isDesktop ? &#39;left&#39; : &#39;top&#39;}&gt;
        {disclaimerText}
      &lt;/Tooltip&gt;
    &lt;/View&gt;
  )
}

The component LinkCopiedToolTip gets rendered depending on the state hasCopiedInvitationLink like this in a parent component:

{hasCopiedInvitationLink &amp;&amp; (
          &lt;LinkCopiedToolTip
            disclaimerText={disclaimerText}
            isDesktop={isDesktop}
            tooltipStyle={{ ...tooltipContainer, ...fadeOut }}
            setHasCopiedInvitationLink={setHasCopiedInvitationLink}
          /&gt;
        )}

Any takes :)? I'm at my wits end here. Thanks!

Tried a bunch of stuff. If I just hardcode the styles directly it works.

答案1

得分: 1

以下是翻译好的部分:

"看起来你试图访问 tooltipStyle 上不存在的属性:"

<View style={{ ...tooltipStyle.tooltipContainer, ...(fadeOutTooltip && tooltipStyle.fadeOut) }}>

要让它工作,你需要更新传递给 LinkCopiedToolTip 的样式的语法,并移除展开 (...) 运算符:

tooltipStyle={{ tooltipContainer, fadeOut }}

英文:

It looks like you are trying to access properties that do not exist on tooltipStyle:

&lt;View style={{ ...tooltipStyle.tooltipContainer, ...(fadeOutTooltip &amp;&amp; tooltipStyle.fadeOut) }}&gt;

To get this to work you need to update the syntax where the styles are fed to LinkCopiedToolTip and remove the spread (...) operator:

tooltipStyle={{ tooltipContainer, fadeOut }}

huangapple
  • 本文由 发表于 2023年2月14日 00:01:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438326.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定