Skip to content

Commit 3c50ab8

Browse files
authored
Merge pull request #32 from amrmelsayed/nativewind-migration
NativeWind migration
2 parents 2a0a233 + 76c2843 commit 3c50ab8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+817
-1853
lines changed

src/app/(app)/_layout.tsx

Lines changed: 22 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { LineIcon, RightArrowIcon } from '@/components/svg'
22
import { useAuth, useScreenInfo } from '@/hooks'
33
import { AppDispatch, RootState, toggleSideMenu } from '@/store'
44
import React from 'react'
5-
import { Dimensions, ImageBackground, KeyboardAvoidingView, Pressable, StyleSheet, View } from 'react-native'
5+
import { Dimensions, ImageBackground, KeyboardAvoidingView, Platform, Pressable, StyleSheet, View } from 'react-native'
66
import { useDispatch, useSelector } from 'react-redux'
77
import Footer from '@/components/Footer'
88
import Header from '@/components/Header'
@@ -11,16 +11,12 @@ import { Redirect, Slot } from 'expo-router'
1111

1212
/**
1313
* AppLayout Component.
14-
* This component defines the layout for the entire application.
15-
* It includes a header, side menu, main content area, and a footer.
16-
* The side menu can be toggled open/closed by clicking a button.
17-
* @returns JSX element representing the AppLayout component.
14+
* This component serves as the main layout for the application.
15+
* It includes the header, side menu, and main content area.
1816
*/
1917
export const AppLayout = () => {
2018
// Hook to get screen information
2119
const { isSmallScreen, isMobile } = useScreenInfo()
22-
// Redux hook to get theme data
23-
const theme = useSelector((state: RootState) => state.theme.theme)
2420
// Redux hook to get side menu state
2521
const { isOpen: isSideMenuOpened } = useSelector((state: RootState) => state.sideMenu)
2622
// Hook to check authentication status
@@ -43,73 +39,28 @@ export const AppLayout = () => {
4339
return <Redirect href='/welcome' />
4440
}
4541

46-
// Styles for the component
47-
const styles = StyleSheet.create({
48-
mainContainer: {
49-
flex: 1,
50-
minHeight: height > 600 ? height : height - 48, // Set minimum height based on screen height
51-
backgroundRepeat: 'repeat',
52-
backgroundSize: 'contain',
53-
overflowY: 'auto',
54-
},
55-
container: {
56-
flexGrow: 1,
57-
fontFamily: 'Inter',
58-
alignItems: 'center', // Center children horizontally
59-
justifyContent: 'space-between',
60-
width: '100%',
61-
},
62-
bodyContainer: {
63-
flex: 1,
64-
width: '100%',
65-
flexDirection: 'row',
66-
fontFamily: 'Inter',
67-
},
68-
mainBody: { width: '100%', flex: 1 },
69-
appContent: {
70-
flexGrow: 1,
71-
justifyContent: 'center',
72-
alignItems: 'center',
73-
alignSelf: 'center', // Center the content area within the parent container
74-
fontFamily: 'Inter',
75-
paddingBottom: isSmallScreen ? 4 : null,
76-
},
77-
closeButton: {
78-
marginTop: 'auto',
79-
marginBottom: 'auto',
80-
marginHorizontal: isSideMenuOpened ? 8 : 16,
81-
},
82-
bodyInnerContainer: {
83-
flexDirection: 'row',
84-
},
85-
})
86-
87-
// Render the component
8842
return (
89-
<ImageBackground style={{ width, height }} source={require('@/assets/images/background.png')}>
43+
<ImageBackground
44+
style={{ width, height }}
45+
className='bg-repeat bg-contain'
46+
source={require('@/assets/images/background.png')}
47+
>
9048
<MenuDrawer>
91-
<KeyboardAvoidingView style={[styles.mainContainer]} behavior='padding' enabled>
92-
<View style={styles.container}>
93-
<View style={styles.bodyContainer}>
94-
{/* Side menu */}
95-
<View style={styles.mainBody}>
96-
{/* Header */}
97-
<Header />
98-
<View style={styles.bodyInnerContainer}>
99-
{/* Toggle button for side menu */}
100-
{isAuthenticated && !isGuest && !isMobile && (
101-
<View style={styles.closeButton}>
102-
<Pressable onPress={togglePopup}>
103-
{isSideMenuOpened ? <LineIcon /> : <RightArrowIcon />}
104-
</Pressable>
105-
</View>
106-
)}
107-
{/* Main content area */}
108-
<View style={styles.appContent}>
109-
<Slot />
110-
</View>
49+
<KeyboardAvoidingView
50+
className='flex-1 overflow-y-auto'
51+
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
52+
enabled
53+
>
54+
<View className='flex-1'>
55+
<Header />
56+
<View className='flex-1'>
57+
{isAuthenticated && !isGuest && !isMobile && (
58+
<View className={`mt-auto mb-auto ${isSideMenuOpened ? 'mx-2' : 'mx-4'}`}>
59+
<Pressable onPress={togglePopup}>{isSideMenuOpened ? <LineIcon /> : <RightArrowIcon />}</Pressable>
11160
</View>
112-
{/* Footer */}
61+
)}
62+
<View className={`flex-grow justify-center items-center self-center ${isSmallScreen ? 'pb-1' : ''}`}>
63+
<Slot />
11364
{showFooter && <Footer />}
11465
</View>
11566
</View>

src/app/(app)/chat/[threadId].tsx

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useChat, useDirection, useScreenInfo } from '@/hooks'
55
import { AppDispatch, RootState, fetchThread, toggleSharePopup } from '@/store'
66
import getEnv from '@/utils/getEnv'
77
import React, { useEffect } from 'react'
8-
import { KeyboardAvoidingView, Platform, Pressable, StyleSheet, View } from 'react-native'
8+
import { KeyboardAvoidingView, Platform, Pressable, View } from 'react-native'
99
import { useDispatch, useSelector } from 'react-redux'
1010
import { useRouter, useLocalSearchParams } from 'expo-router'
1111

@@ -44,33 +44,18 @@ const ChatScreen: React.FC = () => {
4444
}
4545
}, [])
4646

47-
const styles = StyleSheet.create({
48-
container: {
49-
flex: 1,
50-
alignItems: 'center', // Ensure content is centered
51-
justifyContent: 'space-between', // Distributes children evenly
52-
width: '100%',
53-
},
54-
shareIcon: {
55-
position: 'absolute',
56-
left: isRTL ? 24 : 'auto',
57-
right: isRTL ? 'auto' : 24,
58-
padding: 8,
59-
borderRadius: 4,
60-
backgroundColor: theme.popupBackgroundColor,
61-
},
62-
})
63-
6447
return (
65-
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={styles.container}>
48+
<KeyboardAvoidingView
49+
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
50+
className='flex-1 items-center justify-between w-full'
51+
>
6652
<ChatContainer isHome={false} />
6753
{getEnv('ENABLE_SHARE') && !isSmallScreen && (
68-
<View style={styles.shareIcon}>
69-
<Pressable
70-
onPress={() => {
71-
dispatch(toggleSharePopup(!isSharePopupVisible))
72-
}}
73-
>
54+
<View
55+
className={`absolute p-2 rounded ${isRTL ? 'left-6' : 'right-6'}`}
56+
style={{ backgroundColor: theme.popupBackgroundColor }}
57+
>
58+
<Pressable onPress={() => dispatch(toggleSharePopup(!isSharePopupVisible))}>
7459
<ShareIcon />
7560
</Pressable>
7661
</View>

src/app/(app)/index.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ChatContainer, Toast } from '@/components'
22
import { useAuth, useScreenInfo } from '@/hooks'
33
import { AppDispatch, setActiveThread, toggleSideMenu } from '@/store'
44
import React, { useEffect, useState } from 'react'
5-
import { SafeAreaView, StyleSheet } from 'react-native'
5+
import { SafeAreaView } from 'react-native'
66
import { useDispatch } from 'react-redux'
77
import { useLocalSearchParams } from 'expo-router'
88

@@ -21,7 +21,7 @@ const HomeScreen: React.FC = () => {
2121
if (isAuthenticated && !isGuest) {
2222
dispatch(setActiveThread(null))
2323
}
24-
if (!isMobile) {
24+
if (!isMobile && !isGuest) {
2525
dispatch(toggleSideMenu(true))
2626
}
2727
}, [])
@@ -34,20 +34,11 @@ const HomeScreen: React.FC = () => {
3434
}, [errorMessage])
3535

3636
return (
37-
<SafeAreaView style={[styles.container]}>
37+
<SafeAreaView className='flex-1 items-center justify-between'>
3838
<ChatContainer isHome={true} />
3939
{toastVisible && <Toast message={errorMessage} duration={3000} onDismiss={() => setToastVisible(false)} />}
4040
</SafeAreaView>
4141
)
4242
}
4343

44-
const styles = StyleSheet.create({
45-
container: {
46-
flex: 1,
47-
alignItems: 'center', // Ensure content is centered
48-
justifyContent: 'space-between', // Distributes children evenly
49-
},
50-
// Additional styles as needed
51-
})
52-
5344
export default HomeScreen

src/app/(public)/404.tsx

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useAuth, useDirection } from '@/hooks'
55
import { AppDispatch, RootState, setActiveThread } from '@/store'
66
import React, { useEffect, useState } from 'react'
77
import { useTranslation } from 'react-i18next'
8-
import { Pressable, SafeAreaView, StyleSheet, Text, View } from 'react-native'
8+
import { Pressable, SafeAreaView, Text, View } from 'react-native'
99
import { useDispatch, useSelector } from 'react-redux'
1010
import { useRouter, useLocalSearchParams } from 'expo-router'
1111

@@ -47,51 +47,19 @@ const NotFoundScreen: React.FC = () => {
4747
return () => setToastVisible(false)
4848
}, [errorMessage])
4949

50-
// Define component styles
51-
const styles = StyleSheet.create({
52-
container: {
53-
flex: 1,
54-
alignItems: 'center', // Ensure content is centered
55-
justifyContent: 'space-between', // Distributes children evenly
56-
height: '100vh',
57-
width: '100%',
58-
},
59-
body: {
60-
margin: 'auto',
61-
flexDirection: isRTL ? 'row-reverse' : 'row',
62-
alignItems: 'center',
63-
},
64-
text: {
65-
color: theme.textColor,
66-
fontFamily: 'Inter',
67-
fontSize: 24,
68-
lineHeight: 28,
69-
},
70-
textSmall: {
71-
color: theme.textColor,
72-
fontFamily: 'Inter',
73-
fontSize: 16,
74-
lineHeight: 21,
75-
},
76-
logo: {
77-
cursor: 'pointer',
78-
},
79-
// Additional styles as needed
80-
})
81-
82-
// Render the component
8350
return (
84-
<SafeAreaView style={[styles.container]}>
85-
{/* Pressable logo to navigate back to home screen */}
86-
<Pressable style={styles.logo} onPress={() => router.push('/')}>
51+
<SafeAreaView className='flex-1 items-center justify-between h-screen w-full'>
52+
<Pressable className='cursor-pointer' onPress={() => router.push('/')}>
8753
<LogoIcon fill={theme.iconFill} />
8854
</Pressable>
89-
{/* Body text indicating 404 error */}
90-
<View style={styles.body}>
91-
<Text style={styles.text}>404 | </Text>
92-
<Text style={styles.textSmall}>{t('notfoundMessage')}</Text>
55+
<View className={`flex ${isRTL ? 'flex-row-reverse' : 'flex-row'} items-center m-auto`}>
56+
<Text style={{ color: theme.textColor, fontFamily: 'Inter' }} className='text-2xl leading-7'>
57+
404 |{' '}
58+
</Text>
59+
<Text style={{ color: theme.textColor, fontFamily: 'Inter' }} className='text-base leading-[21px]'>
60+
{t('notfoundMessage')}
61+
</Text>
9362
</View>
94-
{/* Toast component to display error message if present */}
9563
{toastVisible && <Toast message={errorMessage} duration={3000} onDismiss={() => setToastVisible(false)} />}
9664
</SafeAreaView>
9765
)

src/app/(public)/_layout.tsx

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useAuth, useScreenInfo } from '@/hooks'
22
import { RootState } from '@/store'
33
import React from 'react'
4-
import { ImageBackground, KeyboardAvoidingView, StyleSheet, View } from 'react-native'
4+
import { ImageBackground, KeyboardAvoidingView, Platform, View } from 'react-native'
55
import { useSelector } from 'react-redux'
66
import ActionButtons from '@/components/ActionButtons'
77
import Footer from '@/components/Footer'
@@ -24,64 +24,26 @@ export const PublicLayout = () => {
2424
return <Redirect href='/' />
2525
}
2626

27-
// Styles for the component
28-
const styles = StyleSheet.create({
29-
mainContainer: {
30-
flex: 1,
31-
minHeight: height > 600 ? height : height - 48, // Set minimum height based on screen height
32-
backgroundRepeat: 'repeat',
33-
backgroundSize: 'contain',
34-
width: '100%',
35-
},
36-
container: {
37-
flexGrow: 1,
38-
fontFamily: 'Inter',
39-
alignItems: 'center', // Center children horizontally
40-
justifyContent: 'space-between',
41-
width: '100%',
42-
},
43-
bodyContainer: {
44-
flex: 1,
45-
width: '100%',
46-
},
47-
pageContainer: {
48-
flex: 1,
49-
width: '100%',
50-
},
51-
main: { flex: 1, flexGrow: 1, width: '100%' },
52-
appContent: {
53-
flexGrow: 1,
54-
justifyContent: 'center',
55-
alignItems: 'center',
56-
width: '100%', // Ensure it spans the full width
57-
alignSelf: 'center', // Center the content area within the parent container
58-
fontFamily: 'Inter',
59-
paddingBottom: isSmallScreen ? 4 : null,
60-
},
61-
header: {
62-
flexDirection: 'row',
63-
justifyContent: 'flex-end',
64-
width: '100%',
65-
alignItems: 'center',
66-
padding: isSmallScreen ? 8 : 16,
67-
},
68-
})
69-
70-
// Render the component
7127
return (
72-
<ImageBackground style={{ width, height }} source={require('@/assets/images/background.png')}>
73-
<KeyboardAvoidingView style={[styles.mainContainer]} behavior='padding' enabled>
74-
<View style={[styles.container]}>
75-
<View style={styles.pageContainer}>
28+
<ImageBackground
29+
style={{ width, height }}
30+
className='bg-repeat bg-contain'
31+
source={require('@/assets/images/background.png')}
32+
>
33+
<KeyboardAvoidingView className='flex-1 w-full' behavior={Platform.OS === 'ios' ? 'padding' : undefined} enabled>
34+
<View className='flex-grow w-full items-center justify-between font-inter'>
35+
<View className='flex-1 w-full'>
7636
{isMobile && (
77-
<View style={styles.header}>
37+
<View className={`flex-row justify-end w-full items-center p-${isSmallScreen ? '2' : '4'}`}>
7838
<ActionButtons isTop={true} />
7939
</View>
8040
)}
8141

82-
<View style={styles.main}>
83-
<View style={styles.bodyContainer}>
84-
<View style={styles.appContent}>
42+
<View className='flex-1 flex-grow w-full'>
43+
<View className='flex-1 w-full'>
44+
<View
45+
className={`flex-grow justify-center items-center w-full self-center font-inter ${isSmallScreen ? 'pb-1' : ''}`}
46+
>
8547
<Slot />
8648
</View>
8749
</View>

0 commit comments

Comments
 (0)