Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x | import React, { useCallback } from 'react';
import Animated, {
useAnimatedStyle,
useSharedValue,
withDelay,
withSpring,
withTiming,
} from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { StyleSheet, Text, View } from 'react-native';
import { RouteProp, useFocusEffect, useRoute } from '@react-navigation/native';
import LottieView from 'lottie-react-native';
import { Button } from '@repo/ui/components/Button';
import { GoogleIcon } from '@repo/ui/icons/Google';
import { makeStyles } from '@repo/ui/themes/makeStyles';
import { useTheme } from '@repo/ui/themes/ThemeContext';
import { SCREENS } from '@repo/constants/screens';
import { useGoogleLogin } from '@/hooks/useGoogleLogin';
import { SCREEN_HEIGHT } from '@/utils/dimensions';
import { ASSETS } from '@/constants/assets';
import type { AppStackParamList } from '@/types/navigation';
const ANIMATION_CONFIG = {
spring: { damping: 12, stiffness: 120, mass: 1, overshootClamping: false },
timing: { duration: 500 },
initialTranslateX: -400,
animationDelay: 5000,
} as const;
const ICON_SIZE = 40;
const GoogleIconLarge = () => <GoogleIcon width={ICON_SIZE} height={ICON_SIZE} />;
export const LoginScreen = () => {
const { theme } = useTheme();
const styles = useStyles();
const insets = useSafeAreaInsets();
const { login, loading, error, isSuccess } = useGoogleLogin();
const route = useRoute<RouteProp<AppStackParamList, typeof SCREENS.LOGIN>>();
const { isLoggedOut } = route.params || {};
const translateX = useSharedValue<number>(ANIMATION_CONFIG.initialTranslateX);
const opacity = useSharedValue(0);
useFocusEffect(
useCallback(() => {
if (isLoggedOut) {
translateX.value = 0;
opacity.value = 1;
} else {
translateX.value = ANIMATION_CONFIG.initialTranslateX;
opacity.value = 0;
translateX.value = withDelay(
ANIMATION_CONFIG.animationDelay,
withSpring(0, ANIMATION_CONFIG.spring),
);
opacity.value = withDelay(
ANIMATION_CONFIG.animationDelay,
withTiming(1, ANIMATION_CONFIG.timing),
);
}
return () => {
translateX.value = ANIMATION_CONFIG.initialTranslateX;
opacity.value = 0;
};
}, [translateX, opacity, isLoggedOut]),
);
const animatedStyle = useAnimatedStyle(() => ({
transform: [{ translateX: translateX.value }],
opacity: opacity.value,
}));
return (
<View
style={[
styles.container,
{
backgroundColor: theme.colors.background.secondary,
paddingTop: insets.top,
paddingBottom: insets.bottom,
},
]}
>
<LottieView
source={ASSETS.ANIMATIONS.SIGNIN}
autoPlay={!isLoggedOut}
loop={false}
resizeMode="cover"
progress={isLoggedOut ? 1 : 0.8}
style={[styles.lottie, { height: SCREEN_HEIGHT }]}
/>
<Animated.View style={[styles.contentContainer, animatedStyle]}>
<Button
rightIcon={GoogleIconLarge}
isLoading={loading}
disabled={isSuccess}
onPress={login}
accessibilityRole="button"
accessibilityLabel="Sign in with Google"
accessibilityHint="Signs you in with your Google account"
style={styles.button}
textStyle={styles.buttonText}
>
Sign in with
</Button>
<View style={styles.errorContainer}>
{error && (
<Text style={[styles.errorText, { color: theme.colors.text.error }]}>
{error.message}
</Text>
)}
</View>
</Animated.View>
</View>
);
};
const useStyles = makeStyles(theme => ({
container: {
...StyleSheet.absoluteFillObject,
justifyContent: 'center',
alignItems: 'center',
},
lottie: {
position: 'absolute',
width: theme.metrics.sizing.full,
},
contentContainer: {
position: 'absolute',
bottom: '10%',
width: theme.metrics.sizing.full,
zIndex: 5,
alignItems: 'center',
},
button: {
width: theme.metrics.sizing.auto,
textAlign: 'center',
justifyContent: 'center',
alignItems: 'center',
borderRadius: theme.metrics.borderRadius[12.5],
paddingLeft: theme.metrics.spacing[8.75],
},
buttonText: { paddingHorizontal: theme.metrics.spacing[2.5] },
errorContainer: {
height: theme.metrics.spacing[7.5],
marginTop: theme.metrics.spacing[1.25],
justifyContent: 'center',
},
errorText: { textAlign: 'center' },
}));
|