-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
125 lines (111 loc) · 4.57 KB
/
Copy pathApp.js
File metadata and controls
125 lines (111 loc) · 4.57 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
import React, { useEffect, useState } from 'react';
import { Text } from 'react-native';
import { createStackNavigator } from '@react-navigation/stack';
import { NavigationContainer } from '@react-navigation/native';
import TaskManagerScreen from './screens/TaskManagerScreen';
import SettingsScreen from './screens/Settings';
import { themes } from './Styles';
// Global text rendering function and variables for font overrides
let globalFont = 'System';
let forceUpdateCallbacks = [];
// Function to register components that need to re-render when font changes
const registerForceUpdate = (callback) => {
forceUpdateCallbacks.push(callback);
return () => {
forceUpdateCallbacks = forceUpdateCallbacks.filter(cb => cb !== callback);
};
};
// Function to trigger re-render of all registered components
const triggerGlobalUpdate = () => {
forceUpdateCallbacks.forEach(callback => callback());
};
// Rendering of the text components and adding the additional fonts globally for each element
const originalTextRender = Text.render;
Text.render = function(props, ref) {
const fontFamily = globalFont === 'System' ? undefined : globalFont;
const newProps = {
...props,
style: [{ fontFamily }, props.style]
};
return originalTextRender.call(this, newProps, ref);
};
// Export these functions so other screens can use them
export { registerForceUpdate, triggerGlobalUpdate };
export default function App() {
const Stack = createStackNavigator();
const [currentTheme, setTheme] = useState("regular");
const [currentFont, setFont] = useState('System'); // Add font state here
const [, forceUpdate] = useState({});
// Register App component for updates
useEffect(() => {
const unregister = registerForceUpdate(() => {
forceUpdate({});
});
return unregister;
}, []);
// Update global font when changed
useEffect(() => {
globalFont = currentFont;
triggerGlobalUpdate();
}, [currentFont]);
// ------------------------------------------------ JSX BEGINS HERE ------------------------------------------------------------------------
return (
<NavigationContainer>
<Stack.Navigator initialRouteName='Task Manager'>
<Stack.Screen
name='Task Manager'
children={({ navigation }) => (
<TaskManagerScreen
navigation={navigation}
currentTheme={themes[currentTheme]}
currentFont={currentFont}
setFont={setFont}
/>
)}
options={{
headerStyle: {
backgroundColor: 'rgba(171, 151, 234, 0.8)',
elevation: 0,
shadowOpacity: 0,
borderBottomWidth: 0
},
headerTitleStyle: {
fontFamily: globalFont === 'System' ? 'Roboto' : globalFont,
fontSize: 20,
fontWeight: '300',
color: 'white',
},
headerTintColor: 'white',
}}
/>
<Stack.Screen
name='Settings'
children={({ navigation }) => (
<SettingsScreen
navigation={navigation}
currentTheme={currentTheme}
setTheme={setTheme}
currentFont={currentFont}
setFont={setFont}
/>
)}
options={{
headerStyle: {
backgroundColor: 'rgba(45, 27, 105, 0.8)',
elevation: 0,
shadowOpacity: 0,
borderBottomWidth: 0
},
headerTitleStyle: {
fontFamily: globalFont === 'System' ? 'Roboto' : globalFont,
fontSize: 20,
fontWeight: '300',
color: 'white'
},
headerTintColor: 'white'
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
}