Made some good progress.

This commit is contained in:
2024-09-10 00:59:55 -05:00
parent f65633c069
commit 5dfbc98035
7 changed files with 320 additions and 125 deletions

View File

@ -1,37 +0,0 @@
import { StyleSheet } from 'react-native';
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming,
withRepeat,
withSequence,
} from 'react-native-reanimated';
import { ThemedText } from '@/components/ThemedText';
export function HelloWave() {
const rotationAnimation = useSharedValue(0);
rotationAnimation.value = withRepeat(
withSequence(withTiming(25, { duration: 150 }), withTiming(0, { duration: 150 })),
4 // Run the animation 4 times
);
const animatedStyle = useAnimatedStyle(() => ({
transform: [{ rotate: `${rotationAnimation.value}deg` }],
}));
return (
<Animated.View style={animatedStyle}>
<ThemedText style={styles.text}>👋</ThemedText>
</Animated.View>
);
}
const styles = StyleSheet.create({
text: {
fontSize: 28,
lineHeight: 32,
marginTop: -6,
},
});

View File

@ -1,76 +0,0 @@
import type { PropsWithChildren, ReactElement } from 'react';
import { StyleSheet, useColorScheme } from 'react-native';
import Animated, {
interpolate,
useAnimatedRef,
useAnimatedStyle,
useScrollViewOffset,
} from 'react-native-reanimated';
import { ThemedView } from '@/components/ThemedView';
const HEADER_HEIGHT = 250;
type Props = PropsWithChildren<{
headerImage: ReactElement;
headerBackgroundColor: { dark: string; light: string };
}>;
export default function ParallaxScrollView({
children,
headerImage,
headerBackgroundColor,
}: Props) {
const colorScheme = useColorScheme() ?? 'light';
const scrollRef = useAnimatedRef<Animated.ScrollView>();
const scrollOffset = useScrollViewOffset(scrollRef);
const headerAnimatedStyle = useAnimatedStyle(() => {
return {
transform: [
{
translateY: interpolate(
scrollOffset.value,
[-HEADER_HEIGHT, 0, HEADER_HEIGHT],
[-HEADER_HEIGHT / 2, 0, HEADER_HEIGHT * 0.75]
),
},
{
scale: interpolate(scrollOffset.value, [-HEADER_HEIGHT, 0, HEADER_HEIGHT], [2, 1, 1]),
},
],
};
});
return (
<ThemedView style={styles.container}>
<Animated.ScrollView ref={scrollRef} scrollEventThrottle={16}>
<Animated.View
style={[
styles.header,
{ backgroundColor: headerBackgroundColor[colorScheme] },
headerAnimatedStyle,
]}>
{headerImage}
</Animated.View>
<ThemedView style={styles.content}>{children}</ThemedView>
</Animated.ScrollView>
</ThemedView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
header: {
height: 250,
overflow: 'hidden',
},
content: {
flex: 1,
padding: 32,
gap: 16,
overflow: 'hidden',
},
});

View File

@ -0,0 +1,116 @@
import React, { useState, useEffect } from 'react';
import { TouchableOpacity, StyleSheet, ActivityIndicator } from 'react-native';
import { ThemedView } from '@/components/ThemedView';
import { ThemedText } from '@/components/ThemedText';
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios from 'axios';
interface User {
id: number;
name: string;
message: string;
}
interface UserSelectionProps {
onUserSelected: (user: User) => void;
}
const API_KEY = 'I_Love_Madeline';
//const BASE_URL = 'https://ismadelinethecutest.gibbyb.com/api';
const BASE_URL = 'http://192.168.0.39:3000/api';
const UserSelection: React.FC<UserSelectionProps> = ({ onUserSelected }) => {
const [users, setUsers] = useState<User[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
checkStoredUser();
}, []);
const checkStoredUser = async () => {
try {
const storedUser = await AsyncStorage.getItem('@user');
if (storedUser) {
onUserSelected(JSON.parse(storedUser));
} else {
fetchUsers();
}
} catch (e) {
console.error('Failed to load user', e);
fetchUsers();
}
};
const fetchUsers = async () => {
try {
const response = await axios.get(`${BASE_URL}/getUsers`, {
params: { apiKey: API_KEY }
});
setUsers(response.data);
} catch (e) {
console.error('Failed to fetch users', e);
} finally {
setLoading(false);
}
};
const selectUser = async (user: User) => {
try {
await AsyncStorage.setItem('@user', JSON.stringify(user));
onUserSelected(user);
} catch (e) {
console.error('Failed to save user', e);
}
};
if (loading) {
return (
<ThemedView style={styles.container}>
<ActivityIndicator size="large" color="#0000ff" />
</ThemedView>
);
}
return (
<ThemedView style={styles.container}>
<ThemedText style={styles.title}>Who are you?</ThemedText>
{users.map((user) => (
<TouchableOpacity
key={user.id}
style={styles.button}
onPress={() => selectUser(user)}
>
<ThemedText style={styles.buttonText}>{user.name}</ThemedText>
</TouchableOpacity>
))}
</ThemedView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 20,
},
button: {
backgroundColor: '#007AFF',
padding: 15,
borderRadius: 5,
marginVertical: 10,
width: 200,
alignItems: 'center',
},
buttonText: {
color: 'white',
fontSize: 18,
fontWeight: 'bold',
},
});
export default UserSelection;