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
Fix: Issue 30 : fixes the checkbox animation on web export #31
Fix: Issue 30 : fixes the checkbox animation on web export #31
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@the-simian Thank you for contributing! I left some comments for next time. I see you put a good amount of effort. Here's the code I would use to update the component:
You can update this PR or I can add it, up to you
import { Check } from 'lucide-react-native';
import * as React from 'react';
import { Pressable } from 'react-native';
import Animated, { FadeIn } from 'react-native-reanimated';
import { cn } from '~/lib/utils';
interface CheckboxProps {
value: boolean;
onChange: (checked: boolean) => void;
iconClass?: string;
iconSize?: number;
}
const Checkbox = React.forwardRef<
React.ElementRef<typeof Pressable>,
Omit<React.ComponentPropsWithoutRef<typeof Pressable>, 'onPress'> &
CheckboxProps
>(({ className, value, onChange, iconClass, iconSize = 16, ...props }, ref) => {
return (
<Pressable
ref={ref}
role='checkbox'
accessibilityState={{ checked: value }}
className={cn(
'peer h-7 w-7 shrink-0 flex items-center bg-card justify-center rounded-md border border-primary web:ring-offset-background web:disabled:cursor-not-allowed web:disabled:opacity-50',
className
)}
onPress={() => {
onChange(!value);
}}
{...props}
>
{value && (
<Animated.View entering={FadeIn.duration(200)}>
<Check size={iconSize} className={cn('text-foreground', iconClass)} />
</Animated.View>
)}
</Pressable>
);
});
Checkbox.displayName = 'Checkbox';
export { Checkbox };
@mrzachnugent I tried your solution, but it seems to have a different issue than the original one I posted. Basically it doesn't actually "fade in" consistently. I noticed this in the existing version as well when I was working on it. This is why I did not use Animated.View with the entering and exiting props. They just weren't working as I'd expect If you add an exit tween, it also does something very strange, where it slides off to the lower right corner. I've increased the times so that what I am seeing is more easy to catch with the naked eye:
using these speeds (which like I said are far too long and just you can see the problem in a gif) In this gif I click the moment I enter the box. instead of a fade there's a wait and then a 'pop'. the exit animation (like it is in main) sometimes causes the checkbox to slide off to the side. I think that the fact that its using I don't think that the Animated.View itself is the issue, and I agree the way you're using it in your proposed changed is a better way forward than the I am going to try to adapt the version you have so that it uses opacity like in my proposed solution. I think that will solve the issue in the original ticket as well as play the tween correctly. |
I've updated your solution in three ways
const opacity = useSharedValue(0);
opacity.value = withTiming(value === true ? 1.0 : 0.0, {
duration: 800, //I'm lowering this for the PR, but I made it long so you can see if the animation is really playing in the gif below
}); I believe the way I am using these hooks is now how they are intended to be used, by updating the you can see the useTiming example here function App() {
sv.value = withTiming(0);
// ...
} function App() {
const sv = useSharedValue(100);
// read a shared value
console.log(sv.value);
// and modify it
sv.value += 50;
} As for your other comments this PR avoids all your other concerns. Thank you for all your feedback. I feel much more confident about this approach. Its the best of all the above, and I think this one should be good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've resolved all your line item review concerns and am ready for you to re-review this version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing!
This updates the Checkbox to do 3 small things:
useSharedValue
andwithTiming
hooksopacity
via theuseSharedValue
This resolves #30
I also added a prettierrc.json at the root of the project that should match the existing code style (I noticed you favored single quotes over double, so this enforces that)