Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark Mode #28

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './screens/Home';
Expand All @@ -8,13 +8,22 @@ import AlarmFeatures from './screens/AlarmFeatures';
const Stack = createNativeStackNavigator();

export default function App() {
const [isDarkMode, setIsDarkMode] = useState(false);

const toggleSwitch = () => setIsDarkMode(!isDarkMode);

return (
<NavigationContainer>
<Stack.Navigator initialRouteName="./screens/Home">
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Setting" component={Setting} />
<Stack.Screen name="AlarmFeatures" component={AlarmFeatures} />

<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home">
{props => <HomeScreen {...props} isDarkMode={isDarkMode} />}
</Stack.Screen>
<Stack.Screen name="Setting">
{props => <Setting {...props} isDarkMode={isDarkMode} toggleSwitch={toggleSwitch} />}
</Stack.Screen>
<Stack.Screen name="AlarmFeatures">
{props => <AlarmFeatures {...props} isDarkMode={isDarkMode} />}
</Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
);
Expand Down
20 changes: 11 additions & 9 deletions screens/AlarmFeatures.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React, { useState } from 'react';
import { View, Text, Switch } from 'react-native';
import { styles, textStyles } from '../styles/styles'; // Adjust the path as needed
import React from 'react';
import { View, Text } from 'react-native';
import { styles, textStyles } from '../styles/styles';
import { StatusBar } from 'expo-status-bar';
import FooterTab from '../components/FooterTab';



function AlarmFeatures() {

function AlarmFeatures({ isDarkMode }) { // Accept isDarkMode as a prop
// Define dynamic styles based on isDarkMode
const dynamicStyles = {
backgroundColor: isDarkMode ? 'darkgrey' : 'white',
color: isDarkMode ? 'white' : 'black',
};

return (
<View style={styles.container}>
<Text style={textStyles.titleText}>Alarm Features</Text>
<View style={[styles.container, { backgroundColor: dynamicStyles.backgroundColor }]}>
<Text style={[textStyles.titleText, { color: dynamicStyles.color }]}>Alarm Features</Text>

<StatusBar />
<FooterTab />
Expand Down
18 changes: 13 additions & 5 deletions screens/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AlarmClock from './Alarm';
import { styles, textStyles } from '../styles/styles'; // Adjust the path as needed
import FooterTab from '../components/FooterTab';

export default function Home() {
export default function Home({ isDarkMode }) { // Accept isDarkMode as a prop
const navigation = useNavigation();

const [currentTime, setCurrentTime] = useState(new Date());
Expand All @@ -20,12 +20,20 @@ export default function Home() {
return () => clearInterval(intervalId);
}, []);

// Define dynamic styles based on isDarkMode
const dynamicStyles = {
backgroundColor: isDarkMode ? 'darkgrey' : 'white',
color: isDarkMode ? 'white' : 'black',
};

return (
<ScrollView style={styles.container}>
<Text style={{ ...textStyles.titleText, padding: 20, paddingTop: 100 }}>Alarm Clock</Text>
<ScrollView style={[styles.container, { backgroundColor: dynamicStyles.backgroundColor }]}>
<Text style={{ ...textStyles.titleText, padding: 20, paddingTop: 100, color: dynamicStyles.color }}>
Alarm Clock
</Text>

<View style={styles.box}>
<Text style={styles.time}>{currentTime.toLocaleTimeString()}</Text>
<View style={[styles.box, { backgroundColor: dynamicStyles.backgroundColor }]}>
<Text style={{ ...styles.time, color: dynamicStyles.color }}>{currentTime.toLocaleTimeString()}</Text>
</View>

<AlarmClock style={{ marginTop: 100, padding: 100, paddingTop: 100 }} />
Expand Down
19 changes: 8 additions & 11 deletions screens/Setting.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import React, { useState } from 'react';
import React from 'react';
import { View, Text, Switch } from 'react-native';
import { styles, textStyles } from '../styles/styles'; // Adjust the path as needed
import { styles, textStyles } from '../styles/styles';
import { StatusBar } from 'expo-status-bar';
import FooterTab from '../components/FooterTab';



function Setting() {
const [toggle, setToggle] = useState(false);

const toggleSwitch = () => setToggle((previousState) => !previousState);
function Setting({ isDarkMode, toggleSwitch }) { // Receives isDarkMode and toggleSwitch as props
const backgroundColor = isDarkMode ? 'darkgrey' : 'white';
const textColor = isDarkMode ? 'white' : 'black';

return (
<View style={styles.container}>
<Text style={textStyles.titleText}>Settings</Text>
<Switch onValueChange={toggleSwitch} value={toggle} />
<View style={[styles.container, { backgroundColor }]}>
<Text style={[textStyles.titleText, { color: textColor }]}>Settings</Text>
<Switch onValueChange={toggleSwitch} value={isDarkMode} />

<StatusBar />
<FooterTab />
Expand Down