Skip to content

Commit

Permalink
added safe area view and minor polishes for better compatiablity and …
Browse files Browse the repository at this point in the history
…responsiveness
  • Loading branch information
Brianali-codes committed Oct 23, 2024
1 parent eda4abb commit 4b9f990
Show file tree
Hide file tree
Showing 23 changed files with 1,062 additions and 174 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ web-build/

# macOS
.DS_Store

# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
16 changes: 11 additions & 5 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"slug": "Frapp",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"icon": "./assets/images/FRAPP_ICON.png",
"scheme": "myapp",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./assets/images/splash.png",
"image": "./assets/images/FRAPP_ICON.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
Expand All @@ -17,20 +17,26 @@
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png",
"foregroundImage": "./assets/images/FRAPP_ICON.jpg",
"backgroundColor": "#ffffff"
}
},
"package": "com.brianali.Frapp"
},
"web": {
"bundler": "metro",
"output": "static",
"favicon": "./assets/images/favicon.png"
"favicon": "./assets/images/FRAPP_ICON.jpg"
},
"plugins": [
"expo-router"
],
"experiments": {
"typedRoutes": true
},
"extra": {
"eas": {
"projectId": "5101bc22-4bca-4375-bec7-4e1a4c143d06"
}
}
}
}
32 changes: 24 additions & 8 deletions app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,50 @@
import { Tabs } from 'expo-router';
import React from 'react';

import { TabBarIcon } from '@/components/navigation/TabBarIcon';
import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';

export default function TabLayout() {
const colorScheme = useColorScheme();

return (
<Tabs
screenOptions={{
tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
tabBarActiveTintColor: Colors[colorScheme ?? 'dark'].tint,
headerShown: false,
}}>
<Tabs.Screen
name="index"
options={{
title: 'Home',
title: 'Giveaways',
tabBarIcon: ({ color, focused }) => (
<TabBarIcon name={focused ? 'gift-sharp' : 'gift-outline'} color={color} />
),
}}
/>
<Tabs.Screen
name="free"
options={{
title: 'Free',
tabBarIcon: ({ color, focused }) => (
<TabBarIcon name={focused ? 'game-controller' : 'game-controller-outline'} color={color} />
),
}}
/>
<Tabs.Screen
name="report"
options={{
title: 'Report bug',
tabBarIcon: ({ color, focused }) => (
<TabBarIcon name={focused ? 'home' : 'home-outline'} color={color} />
<TabBarIcon name={focused ? 'bug' : 'bug-outline'} color={color} />
),
}}
/>
<Tabs.Screen
name="explore"
name="settings"
options={{
title: 'Explore',
title: 'Settings',
tabBarIcon: ({ color, focused }) => (
<TabBarIcon name={focused ? 'code-slash' : 'code-slash-outline'} color={color} />
<TabBarIcon name={focused ? 'settings' : 'settings-outline'} color={color} />
),
}}
/>
Expand Down
102 changes: 0 additions & 102 deletions app/(tabs)/explore.tsx

This file was deleted.

182 changes: 182 additions & 0 deletions app/(tabs)/free.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { ScrollView, StyleSheet, Image } from 'react-native';
import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';
import { useState, useEffect } from 'react';
import { TabBarIcon } from '@/components/navigation/TabBarIcon';
import { Button, Divider } from 'react-native-paper';
import { Linking } from 'react-native';
import { Skeleton } from '@rneui/themed';
import { Alert } from 'react-native';
import React from 'react';
import { SafeAreaView } from 'react-native-safe-area-context';
//initital typescript magic for better error handling.


interface Giveaway {
id: number;
title: string;
thumbnail: string;
image:string;
short_description: string;
open_giveaway_url : string;
open_giveaway:string;
worth:string;
game_url:string;
genre:string;
publisher:string;
}

export default function HomeScreen() {

const [isLoading, setIsLoading] = useState(true);
const [giveaways, setGiveaways] = useState<Giveaway[]>([]); // Define state with type

const url = 'https://corsproxy.io/?https://www.freetogame.com/api/games';

const fetchData = async () => {
try {
const response = await fetch(url);
const finalData: Giveaway[] = await response.json();
setGiveaways(finalData);
setIsLoading(false);
} catch (error) {
console.error('Error fetching data:', error);
setIsLoading(false);
Alert.alert('Unable to fetch games check your connection or relaunch the app.');
}
};

// Use useEffect to fetch the data on component mount
useEffect(() => {
fetchData();
}, []);

return (
<ThemedView style={styles.container}>
<SafeAreaView>
<ThemedText style={styles.text}>
<TabBarIcon name={'game-controller'} style={styles.icons}/>
FREE GAMES
</ThemedText>
</SafeAreaView>

<ScrollView contentContainerStyle={styles.scrollViewContent}>
{isLoading ? (
<>
<Skeleton animation="wave" style={styles.skeletonImage}/>
<Skeleton animation="wave" style={styles.skeletonImage2}/>
<Skeleton animation="wave" style={styles.skeletonImage2}/>
<Skeleton animation="wave" style={styles.skeletonImage2}/>
<Skeleton animation="wave" style={styles.skeletonImage}/>
<Skeleton animation="wave" style={styles.skeletonImage2}/>
</>
) : (
giveaways.map(giveaway => (
<React.Fragment key={giveaway.id}>
<ThemedView style={styles.cards}>
<ThemedText style={styles.text}>
{giveaway.title}
</ThemedText>
<Image source={{ uri: giveaway.thumbnail }} style={styles.cardImage} />
<ThemedText style={styles.giveawayText}>
{giveaway.short_description}
</ThemedText>
<ThemedText style={styles.giveawayText}>Genre: <ThemedText style={styles.themeTexts}>{giveaway.genre}</ThemedText></ThemedText>
<ThemedText style={styles.giveawayText}>Publisher: <ThemedText style={styles.themeTexts}>{giveaway.publisher}</ThemedText></ThemedText>
<Divider style={{ marginVertical: 10, height: 1, backgroundColor: 'transparent' }} />
<Button
mode="contained"
onPress={() => Linking.openURL(giveaway.game_url)}
>
Get Game for free
</Button>
</ThemedView>
</React.Fragment>
))
)}
</ScrollView>
</ThemedView>
);
}

const styles = StyleSheet.create({
container: {
flex: 1, // Takes the full screen height to enable scrolling.
backgroundColor: '#1b2838',
padding: 10,
},
text: {
color: 'white',
fontFamily: 'sans-serif',
fontWeight: 'bold',
fontSize: 13,
marginBottom: 10,
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
padding:5,
gap:5,
},
themeTexts: {
color: '#00FF00',
fontFamily: 'sans-serif',
fontWeight: 'bold',
fontSize: 15,
padding:3,
gap:3,
},
skeletonImage:{
width:'100%',
height:300,
borderRadius:10,
},
skeletonImage2:{
width:'100%',
height:50,
borderRadius:10,
},
cards: {
borderColor: 'white',
backgroundColor: '#2C415A',
marginBottom: 10,
borderRadius: 7,
elevation: 5, // Shadow for Android
shadowColor: '#000', // Shadow for iOS
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.25,
shadowRadius: 3.84,
marginVertical: 5,
marginHorizontal: 5,
padding:20,
},
cardImage: {
width: '100%',
height: 200,
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
},
worth:{
textDecorationLine:'line-through',
color:'white',
},
icons: {
marginBottom: 2,
fontSize:18,
},
scrollViewContent: {
paddingBottom: 20,
gap: 10,
},
giveawayText: {
color: 'white',
fontSize: 16,
marginBottom: 10,
},
thumbnail: {
width: 100,
height: 100,
marginBottom: 10,
},
});

Loading

0 comments on commit 4b9f990

Please sign in to comment.