-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
166 lines (155 loc) · 4.92 KB
/
App.tsx
File metadata and controls
166 lines (155 loc) · 4.92 KB
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
162
163
164
165
166
/**
* Movie Search App
* Built with React Native, Redux Toolkit, and RTK Query
*
* @format
*/
import React from 'react';
import { StatusBar, View, TouchableOpacity, Text, Platform } from 'react-native';
import { Provider } from 'react-redux';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import ErrorBoundary from './src/components/ErrorBoundary';
import PerformanceOverlay from './src/components/PerformanceOverlay';
import SearchScreen from './src/screens/SearchScreen';
import MovieDetailsScreen from './src/screens/MovieDetailsScreen';
import { store } from './src/store';
import { FontFamilies } from './src/constants/fonts';
import type { RootStackParamList } from './src/types/navigation.types';
import { useDispatch } from 'react-redux';
import { useSelector } from 'react-redux';
import { RootState } from './src/store';
import { clearCurrentMovieTitle } from './src/store/movieSlice';
const linking = {
prefixes: ['myreactnativeapp://', 'https://myreactnativeapp.com'],
config: {
screens: {
Search: 'search',
MovieDetails: 'movie/:movieId',
},
},
};
const Stack = createNativeStackNavigator<RootStackParamList>();
const CustomHeader = ({ title, onGoBack }: { title: string; onGoBack?: () => void }) => {
const dispatch = useDispatch();
const movieTitle = useSelector((state: RootState) => state.movie.currentMovieTitle);
const displayTitle = movieTitle || title;
// Truncate title to maximum 25 characters for better fit
const truncatedDisplayTitle = displayTitle.length > 25
? `${displayTitle.substring(0, 22)}...`
: displayTitle;
const handleGoBack = () => {
dispatch(clearCurrentMovieTitle());
if (onGoBack) {
onGoBack();
}
};
return (
<View style={{
height: 120,
backgroundColor: '#1E1E1E',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
paddingHorizontal: 16,
position: 'relative',
// marginBottom: 60,
}}>
{onGoBack && (
<TouchableOpacity
onPress={handleGoBack}
style={{
position: 'absolute',
left: 16,
padding: 8,
}}
>
<Text style={{
color: '#FFFFFF',
fontSize: 26,
fontFamily: FontFamilies.Gilroy.Heavy,
marginTop: Platform.OS === 'ios' ? 50 : 45,
}}>
←
</Text>
</TouchableOpacity>
)}
<Text
numberOfLines={2}
adjustsFontSizeToFit
style={{
color: '#FFFFFF',
fontSize: 18,
fontFamily: FontFamilies.Gilroy.Heavy,
textAlign: 'center',
// paddingBottom: 6, // 5-7px spacing below title
marginBottom: -50,
lineHeight: 22,
}}>
{truncatedDisplayTitle}
</Text>
</View>
);
};
function App(): JSX.Element {
return (
<ErrorBoundary>
<Provider store={store}>
<SafeAreaProvider
style={{ backgroundColor: '#121212' }} // Ensure consistent background
>
<StatusBar
barStyle="light-content"
backgroundColor="transparent"
translucent={true}
/>
<NavigationContainer linking={linking}>
<Stack.Navigator
screenOptions={{
headerStyle: {
backgroundColor: '#1E1E1E',
},
headerTintColor: '#FFFFFF',
headerTitleStyle: {
fontFamily: FontFamilies.Gilroy.Heavy,
fontSize: 20,
},
contentStyle: {
backgroundColor: '#121212',
},
animation: 'slide_from_right',
animationDuration: 200,
}}>
<Stack.Screen
name="Search"
component={SearchScreen}
options={{
title: 'Movie Search',
headerTitleAlign: 'center',
}}
/>
<Stack.Screen
name="MovieDetails"
component={MovieDetailsScreen}
options={({ navigation }) => ({
headerTitleAlign: 'center',
headerBackTitle: '',
headerBackTitleVisible: false,
header: () => (
<CustomHeader
title="Loading..."
onGoBack={() => navigation.goBack()}
/>
),
})}
/>
</Stack.Navigator>
</NavigationContainer>
{/* Performance monitoring overlay - only visible in DEV mode */}
</SafeAreaProvider>
</Provider>
</ErrorBoundary>
);
}
export default App;