buuing / lucky-canvas

🎖🎖🎖 基于 TS + Canvas 开发的【大转盘 / 九宫格 / 老虎机】抽奖插件,🌈 一套源码适配多端框架 JS / Vue / React / Taro / UniApp / 微信小程序等,🎨 奖品 / 文字 / 图片 / 颜色 / 按钮均可配置,支持同步 / 异步抽奖,🎯 概率前 / 后端可控,🚀 自动根据 dpr 调整清晰度适配移动端
https://100px.net
Apache License 2.0
7.66k stars 928 forks source link

无法动态的修改 activeStyle 的 background 并即时生效 #418

Open NateRobinson opened 1 year ago

NateRobinson commented 1 year ago
// 代码开始, 别再放歪了行吗
<LuckyGrid
    ref={myLucky}
    width="400px"
    height="400px"
    blocks={blocks}
    prizes={prizes.map((item) => ({ ...item, background: blockColor }))}
    buttons={buttons}
    defaultStyle={defaultStyle}
    activeStyle={{ background: activeBlockColor }}
    onStart={() => {
      myLucky.current.play();
      setTimeout(() => {
        // eslint-disable-next-line no-bitwise
        myLucky.current.stop(0);
      }, 1000);
    }}
    onEnd={() => {
      // 抽奖结束会触发end回调
    }}
  />
// 代码结束
buuing commented 1 year ago

代码不对, 自己检查, 不是bug

NateRobinson commented 1 year ago

@buuing 帮忙指正一下?

buuing commented 1 year ago

activeStyle={{ background: activeBlockColor }}不能这么用吧. 这样搞, 你是不是得给抽奖组件加个key, 每次修改之后, 重新渲染一次组件

NateRobinson commented 1 year ago

@buuing 明白,不过上面的 prizes,buttons,defaultStyle 这些这么用是可以实时生效的。我先试试加上 key 让重新渲染试试效果。