Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blink in mobile #162

Open
Jose-DR21 opened this issue Jun 12, 2024 · 0 comments
Open

blink in mobile #162

Jose-DR21 opened this issue Jun 12, 2024 · 0 comments

Comments

@Jose-DR21
Copy link

Jose-DR21 commented Jun 12, 2024

I am trying to implement the component and it works fine but in mobile view it has unwanted flickering. i tried to integrate it in my nextjs project and also in a separate project in react vanilla and in both cases it gives the same flickering.

Code react vanilla

import { useState } from "react";
import { Wheel } from "react-custom-roulette";

import "./App.css";

const data = {
ruleta: [
{
id: 0,
option: "5%",
probabilidad: [1, 5],
message: "Congratulations0",
}, //5%
{
id: 1,
option: "10%",
probabilidad: [6, 15],
message: "Congratulations1",
}, // 10%
{
id: 2,
option: "15%",
style: { textColor: "#000" },
probabilidad: [16, 30],
message: "Congratulations2",
}, //15%
{
id: 3,
option: "30%",
probabilidad: [31, 60],
message: "Congratulations3",
}, //30%
{
id: 4,
option: "40%",
style: { textColor: "#000" },
probabilidad: [61, 100],
message: "Congratulations4",
}, //40%
],
};
const ruletaStart = async () => {
let min = 1;
let max = 100;

const numero = Math.floor(Math.random() * (max - min + 1) + min);

const respuesta = data?.ruleta?.filter((x) => {
if (numero >= x.probabilidad[0] && numero <= x.probabilidad[1]) {
return x;
}
});
return respuesta[0].id;
};

function App() {
const [mustSpin, setMustSpin] = useState(false);
const [prizeNumber, setPrizeNumber] = useState(0);
const [message, setMessage] = useState("");
const backgroundColors = ["red", "blue", "white", "blue", "white"];

const handleSpinClick = async () => {
if (!mustSpin) {
let resp = await ruletaStart();

  setPrizeNumber(resp);
  setMustSpin(true);
}

};

return (




{data && (
<Wheel
outerBorderWidth={5}
spinDuration={[0.3]}
mustStartSpinning={mustSpin}
prizeNumber={prizeNumber}
data={data?.ruleta}
backgroundColors={backgroundColors}
radiusLineWidth={0}
radiusLineColor="transparent"
innerBorderColor="black"
outerBorderColor="yellow"
disableInitialAnimation={false}
onStopSpinning={() => {
setMustSpin(false);
setMessage(data?.ruleta[prizeNumber].message);
}}
/>
)}

<button
className={"btn-registro animate-pulse"}
onClick={() => {handleSpinClick()}}
disabled={mustSpin}
>
{mustSpin ? "Suerte" : "Girar"}

    </div>
  
  </div>

</div>

);
}

export default App;

deploy in vercel : https://ruleta-vite.vercel.app/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant