You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This Flipper component is responsible for the QR Code’s spinning gesture (see video demo).
Some physics and maths tricks are employed to deliver a fluid user experience. When spinning the QR code, it calculates the gesture’s intensity and adjust the rotation speed to match. Some damping is added to give a bouncy feeling. And we have to handle a handful of edge cases as well, e.g. what if the user changes the ID while this thing is spinning.
// If you are up for a challenge, please help clean up this code!
// Current rotation to be rendered (degrees)
letcurrent=0
// Target rotation (degrees)
lettarget=0
// Current rotation speed (degrees/frame)
letcurrentSpeed=0
// Spring strength
constspringK=1/15
// Rotation acceleration (degrees/frame^2)
constacceleration=0.7
// Animation parameters...
letanimationActive=false
letanimationStartTime=Date.now()
letlastFrameNumber=0
// State of dragging
letpointerIsDown=false
lethistory=[]
As you can see there are about 8 mutable variables. It’s about 100 lines of impure, imperative code. I would appreciate it if someone could make this code more functional and clean. So, hence this clean code challenge.
The text was updated successfully, but these errors were encountered:
This Flipper component is responsible for the QR Code’s spinning gesture (see video demo).
Some physics and maths tricks are employed to deliver a fluid user experience. When spinning the QR code, it calculates the gesture’s intensity and adjust the rotation speed to match. Some damping is added to give a bouncy feeling. And we have to handle a handful of edge cases as well, e.g. what if the user changes the ID while this thing is spinning.
Here’s the code:
promptpay-qr/webapp/src/Flipper.js
Lines 75 to 102 in 623118c
As you can see there are about 8 mutable variables. It’s about 100 lines of impure, imperative code. I would appreciate it if someone could make this code more functional and clean. So, hence this clean code challenge.
The text was updated successfully, but these errors were encountered: