-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
94 lines (89 loc) · 2.18 KB
/
App.js
File metadata and controls
94 lines (89 loc) · 2.18 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
import React from 'react';
import { StyleSheet, Text, View, Image} from 'react-native';
import moment from 'moment'
import Button from 'react-native-button';
const image ={
sunny: require('./images/sunny.jpg'),
night: require('./images/bg.jpg')
}
export default class App extends React.Component {
constructor () {
super();
this.state = {
backgroundName: 'sunny',
time: moment().format('LTS'),
color: true
};
}
handlePress () {
console.log(this.state.backgroundName);
if (this.state.backgroundName === 'sunny') {
this.setState({backgroundName: 'night', color: false});
} else {
this.setState({backgroundName: 'sunny', color: true});
}
}
componentDidMount(){
setInterval(()=>{
this.setState({ time: moment().format('LTS') })
}),1000
}
render () {
const fontColor = this.state.color == true ? "black" : "white"
const time = moment().format('LTS')
return (
<View style={styles.container}>
<Image
style={styles.imageBackground}
source={image[this.state.backgroundName]}
>
<View style={{flex: 1}}>
<Text style= {styles.timer}>
{this.state.time}
</Text>
</View>
<View style={styles.btnContainer}>
<Button
style={styles.button}
containerStyle={{padding:10, height:45, overflow:'hidden', borderRadius:4, backgroundColor: 'white'}}
onPress={() => this.handlePress()}
>
change background
</Button>
</View>
</Image>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center'
},
imageBackground: {
flex: 1,
width: '100%',
justifyContent: 'space-around',
alignItems: 'center'
},
btnContainer: {
width:200,
flex: 1,
},
timer: {
flex: 1,
backgroundColor: 'transparent',
fontSize: 30,
marginTop: 150,
alignSelf: 'center'
},
botton: {
color: "#841584",
marginTop: 50,
height: 100,
borderRadius: 30
}
});