Skip to content

Commit

Permalink
feat(client): add forwardRef to button
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocroh committed Feb 8, 2025
1 parent b63ca58 commit 3c620e8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions apps/client/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { PressableProps, Text } from 'react-native'
import { Pressable } from 'react-native'
import { Pressable as BasePressable } from 'react-native'
import Animated, {
interpolate,
useAnimatedStyle,
Expand All @@ -14,9 +15,12 @@ type ButtonProps = {

const DURATION = 300

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
const Pressable = Animated.createAnimatedComponent(BasePressable)

export function Button({ className, title, ...props }: ButtonProps) {
const Button = React.forwardRef<
React.ComponentRef<typeof BasePressable>,
ButtonProps
>(({ className, title, ...props }, ref) => {
const transition = useSharedValue(0)

const animatedStyle = useAnimatedStyle(() => {
Expand All @@ -30,7 +34,8 @@ export function Button({ className, title, ...props }: ButtonProps) {
})

return (
<AnimatedPressable
<Pressable
ref={ref}
{...props}
style={animatedStyle}
onPressIn={() => {
Expand All @@ -47,6 +52,9 @@ export function Button({ className, title, ...props }: ButtonProps) {
<Text className="text-primary-foreground" selectable={false}>
{title}
</Text>
</AnimatedPressable>
</Pressable>
)
}
})
Button.displayName = 'Button'

export { Button }

0 comments on commit 3c620e8

Please sign in to comment.