Skip to content

Commit

Permalink
feat(client): animate button
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocroh committed Feb 8, 2025
1 parent c2b177e commit 8694917
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
4 changes: 4 additions & 0 deletions apps/client/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ module.exports = function (api) {
['babel-preset-expo', { jsxImportSource: 'nativewind' }],
'nativewind/babel',
],
plugins: [
'@babel/plugin-proposal-export-namespace-from',
'react-native-reanimated/plugin',
],
}
}
43 changes: 39 additions & 4 deletions apps/client/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
import { Pressable, PressableProps, Text } from 'react-native'
import { PressableProps, Text } from 'react-native'
import { Pressable } from 'react-native'
import Animated, {
interpolate,
useAnimatedStyle,
useSharedValue,
withDelay,
withSequence,
withSpring,
withTiming,
} from 'react-native-reanimated'
import { cn } from '@/lib/cn'

type ButtonProps = {
title: string
} & PressableProps

const DURATION = 300

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

export function Button({ className, title, ...props }: ButtonProps) {
const transition = useSharedValue(0)

const animatedStyle = useAnimatedStyle(() => {
return {
transform: [
{
scale: interpolate(transition.value, [0, 1], [1, 0.98]),
},
],
}
})

return (
<Pressable
<AnimatedPressable
{...props}
style={animatedStyle}
onPressIn={() => {
transition.value = withTiming(1, { duration: DURATION })
}}
onPressOut={() => {
transition.value = withTiming(0, { duration: DURATION })
}}
className={cn(
'items-center justify-center rounded-md bg-primary p-2',
className
)}
>
<Text className="text-primary-foreground">{title}</Text>
</Pressable>
<Text className="text-primary-foreground" selectable={false}>
{title}
</Text>
</AnimatedPressable>
)
}
1 change: 1 addition & 0 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"preset": "jest-expo"
},
"dependencies": {
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@clerk/clerk-expo": "^2.7.3",
"@clerk/types": "^4.45.0",
"@expo/vector-icons": "^14.0.2",
Expand Down
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8694917

Please sign in to comment.