Skip to content

Commit 34195c0

Browse files
committed
Dark and light mode
1 parent eda74bc commit 34195c0

File tree

6 files changed

+67
-24
lines changed

6 files changed

+67
-24
lines changed

Components/ChatPage/AiThinking.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ export const AiThinking = () => {
4242
}}>Thinking...</Text>
4343
</View>
4444
<View style={{
45-
color:Style1.color4,
4645
padding:15,
4746
paddingTop:2,
4847
paddingLeft:27,
4948
marginTop:3,
5049
fontSize:17,
5150
}}>
5251
<TypeWriter minDelay={1} maxDelay={1} typing={writing} style={{
53-
color:"rgb(208,208,208)"
52+
color:Style1.color4
5453
}} onTypingEnd={()=>{
5554
if(writing===-1){
5655
setRandom(Math.floor(Math.random() * 7))

Components/Homepage/TopPart.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import {useContext} from "react";
33
import Context from "../../Context/Context";
44

55
export const TopPart = () => {
6-
const {Style1}=useContext(Context)
76
return (
87
<View style={{
9-
height:200,
8+
height:160,
109
alignItems:"center",
1110
justifyContent:"center"
1211
}}>

Context/ContextState.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
import Context from "./Context";
2+
import {useEffect, useState} from "react";
23

34

45

56
const ContextState=(props)=>{
6-
const Style1={
7-
color1:"#dbe4f3",
8-
color2:"#769bea",
9-
color3:"#282828",
10-
color4:"white",
11-
color5:"#1f1f1f",
12-
color6:"gray"
13-
}
14-
// const Style1={
15-
// color1:"#03142a",
16-
// color2:"#4a7feb",
17-
// color3:"#f6f6f6",
18-
// color4:"black",
19-
// color5:"white",
20-
// color6:"gray"
21-
// }
22-
return <Context.Provider value={{Style1}}>
7+
const [darkMode,setDarkmode]=useState(false)
8+
const [Style1,setStyle]=useState({
9+
color1:"#03142a",
10+
color2:"#4a7feb",
11+
color3:"#f6f6f6",
12+
color4:"black",
13+
color5:"white",
14+
color6:"gray"
15+
})
16+
useEffect(() => {
17+
if(darkMode){
18+
setStyle({
19+
color1:"#dbe4f3",
20+
color2:"#769bea",
21+
color3:"#282828",
22+
color4:"white",
23+
color5:"#1f1f1f",
24+
color6:"gray"
25+
})
26+
}else{
27+
setStyle({
28+
color1:"#03142a",
29+
color2:"#4a7feb",
30+
color3:"#f6f6f6",
31+
color4:"black",
32+
color5:"white",
33+
color6:"gray"
34+
})
35+
}
36+
}, [darkMode]);
37+
return <Context.Provider value={{Style1,darkMode,setDarkmode}}>
2338
{props.children}
2439
</Context.Provider>
2540
}

Screens/HomePage.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,32 @@ import {EachFeaturesCard} from "../Components/Homepage/EachFeaturesCard";
55
import {Heading} from "../Components/Global/Heading";
66
import {TopPart} from "../Components/Homepage/TopPart";
77
import {EachHistory} from "../Components/Homepage/EachHistory";
8+
import ToggleSwitch from "toggle-switch-react-native";
89

910
export const HomePage = ({navigation}) => {
10-
const {Style1}=useContext(Context)
11+
const {Style1,setDarkmode,darkMode}=useContext(Context)
1112
return (
1213
<ImageBackground source={require("../Assets/artem-bryzgalov-r2CAjGQ0gSI-unsplash.jpg")} style={{flex:1,height:"100%",width:"100"}}>
1314
<View style={{
1415
flex:1,
1516
backgroundColor:"rgba(0,0,0,0.37)"
1617
}}>
18+
<View style={{
19+
alignItems:"flex-end",
20+
paddingRight:10,
21+
paddingTop:10,
22+
marginTop:6,
23+
}}>
24+
<ToggleSwitch
25+
isOn={darkMode}
26+
onColor="green"
27+
offColor="rgb(45,45,45)"
28+
label={"Dark Mode"}
29+
labelStyle={{ color: "white", fontWeight: "500" }}
30+
size="medium"
31+
onToggle={isOn => setDarkmode(isOn)}
32+
/>
33+
</View>
1734

1835
<TopPart/>
1936
<View style={{

package-lock.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"react-native-svg": "^13.14.0",
2626
"react-native-syntax-highlighter": "^2.1.0",
2727
"react-native-toast-notifications": "^3.4.0",
28-
"react-native-typewriter": "^0.7.0"
28+
"react-native-typewriter": "^0.7.0",
29+
"toggle-switch-react-native": "^3.3.0"
2930
},
3031
"devDependencies": {
3132
"@babel/core": "^7.20.0",

0 commit comments

Comments
 (0)