Skip to content

Commit b75f16f

Browse files
authored
Merge pull request #258 from palaksinghania05/live_clock_new
Live clock new
2 parents 2165921 + 121b25c commit b75f16f

15 files changed

+8853
-0
lines changed

Live Clock/App.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as React from 'react';
2+
import { Text, View, StyleSheet} from 'react-native';
3+
import Constants from 'expo-constants';
4+
5+
import LiveClock from './components/Function';
6+
7+
import {Card} from 'react-native-paper';
8+
9+
export default class App extends React.Component {
10+
11+
render(){
12+
return (
13+
<View style={styles.container}>
14+
<Text style={styles.paragraph}>
15+
Live Clock
16+
</Text>
17+
<Card style={{height:100, width:500}}>
18+
<Text style={styles.timer}>
19+
<LiveClock />
20+
</Text>
21+
</Card>
22+
</View>
23+
);
24+
}
25+
}
26+
27+
const styles = StyleSheet.create({
28+
container: {
29+
justifyContent:"center",
30+
alignItems:"center",
31+
flex: 1,
32+
paddingTop: Constants.statusBarHeight,
33+
backgroundColor: '#ecf0f1',
34+
padding: 8,
35+
color:"red"
36+
},
37+
paragraph: {
38+
margin: 24,
39+
fontSize: 50,
40+
fontWeight: 'bold',
41+
textAlign: 'center',
42+
color:"red"
43+
},
44+
timer:{
45+
padding:20,
46+
textAlign:"center",
47+
fontSize:20,
48+
fontWeight:"bold"
49+
}
50+
});

Live Clock/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Live Clock
2+
A Live Clock Project which shows current time always with appropriate abbreviations AM or PM.
3+
4+
# Use of Project
5+
A beginner-friendly project to get started with web development, especially React-Native.
6+
7+
# Stack Used
8+
- JavaScript
9+
- React-Native
10+
11+
# Set up required to run
12+
- Pre-requisite -> Install node in your system and add it to environment path variable.
13+
- Install expo-cli using command:
14+
```
15+
npm install -g expo-cli
16+
```
17+
- Now, clone this repo.
18+
```
19+
git clone https://github.com/Ayushparikh-code/Web-dev-mini-projects
20+
```
21+
- Move to project directory.
22+
- In your IDE terminal, run command:
23+
```
24+
npm start
25+
```
26+
- On the new window that will open in the browser, click on the preferred option like web browser, android emulator, etc.
27+
- Wait for sometime, the project will open and run in another tab of browser.
28+
29+
# Screenshots
30+
- On running "npm start" command, a "Expo Developer Tools" window will open in the browser.
31+
![](./screenshots/developer_tools.png)
32+
33+
- On clicking "Run in Web Browser", project will start initializing.
34+
![](./screenshots/run_in_web_browser.png)
35+
![](./screenshots/project_initialize.png)
36+
37+
- A new tab will open which will show the live clock.
38+
![](./screenshots/live_clock.png)

Live Clock/app.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"expo": {
3+
"name": "liveClockProject",
4+
"slug": "liveClockProject",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"splash": {
9+
"image": "./assets/splash.png",
10+
"resizeMode": "contain",
11+
"backgroundColor": "#ffffff"
12+
},
13+
"updates": {
14+
"fallbackToCacheTimeout": 0
15+
},
16+
"assetBundlePatterns": [
17+
"**/*"
18+
],
19+
"ios": {
20+
"supportsTablet": true
21+
},
22+
"android": {
23+
"adaptiveIcon": {
24+
"foregroundImage": "./assets/adaptive-icon.png",
25+
"backgroundColor": "#FFFFFF"
26+
}
27+
},
28+
"web": {
29+
"favicon": "./assets/favicon.png"
30+
}
31+
}
32+
}

Live Clock/assets/adaptive-icon.png

17.1 KB
Loading

Live Clock/assets/favicon.png

1.43 KB
Loading

Live Clock/assets/icon.png

21.9 KB
Loading

Live Clock/assets/splash.png

47.3 KB
Loading

Live Clock/babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
};
6+
};

Live Clock/components/Function.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from 'react';
2+
import { Text, View, StyleSheet, Image } from 'react-native';
3+
4+
export default class LiveClock extends React.Component {
5+
constructor(){
6+
super();
7+
this.state = {currentTime : new Date()}
8+
}
9+
10+
componentDidMount(){
11+
setInterval(()=> this.tick(), 1000) //tick() is called after every 1 sec or 1000ms
12+
}
13+
14+
tick=()=>{
15+
this.setState({currentTime:new Date()})
16+
}
17+
18+
render() {
19+
return (
20+
<View style={styles.container}>
21+
<Text style={styles.paragraph}>
22+
{this.state.currentTime.toLocaleTimeString('en-US')}
23+
</Text>
24+
</View>
25+
);
26+
}
27+
}
28+
29+
const styles = StyleSheet.create({
30+
container: {
31+
alignItems: 'center',
32+
justifyContent: 'center',
33+
padding: 15,
34+
},
35+
paragraph: {
36+
fontSize: 25,
37+
fontWeight: 'bold',
38+
textAlign: 'center',
39+
}
40+
});

0 commit comments

Comments
 (0)