-
Notifications
You must be signed in to change notification settings - Fork 311
Simple Step counter App in react native #295
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
Open
Sherin-Susan-Thomas
wants to merge
6
commits into
Technigo:master
Choose a base branch
from
Sherin-Susan-Thomas:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
149b99b
initial commit
EmOlsz d33af7e
step counter added
Sherin-Susan-Thomas 498bde9
navigation added
Sherin-Susan-Thomas 64f8f4b
Merge pull request #1 from Sherin-Susan-Thomas/sensors
Sherin-Susan-Thomas 0ee9c9a
useeffct cleanup done
Sherin-Susan-Thomas e1c9f71
Update README.md
Sherin-Susan-Thomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,17 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components/native'; | ||
| import React from "react"; | ||
| import styled from "styled-components/native"; | ||
|
|
||
| import Main from "./components/Main"; | ||
| const Container = styled.View` | ||
| flex: 1; | ||
| background-color: papayawhip; | ||
| justify-content: center; | ||
| align-items: center; | ||
| `; | ||
|
|
||
| const Title = styled.Text` | ||
| font-size: 24px; | ||
| color: palevioletred; | ||
| flex: 1; | ||
| `; | ||
|
|
||
| const App = () => { | ||
| return ( | ||
| <Container> | ||
| <Title>This is your cool app!</Title> | ||
| <Title>Go to App.js and start coding</Title> | ||
| <Title>💅💅💅</Title> | ||
| </Container> | ||
| ); | ||
| return ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice and clean app. |
||
| <Container> | ||
| <Main /> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default App; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,10 @@ | ||
| # Project React Native App 📱 | ||
|
|
||
| Replace this readme with your own information about your project. | ||
|
|
||
| Start by briefly describing the assignment in a sentence or two. Keep it short and to the point. | ||
|
|
||
| ## The problem | ||
|
|
||
| Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next? | ||
| The week's project was to build a mobile app using React Native. | ||
| Built a simple pedometer app that made use of sensors(pedometer) available on phone to track the number of steps. Used Navigation to toggle between home Screen and Pedometer screen | ||
|
|
||
| ## View it live | ||
|
|
||
| Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about. | ||
| https://expo.dev/@sherin11/simple-step-counter-app | ||
|
|
||
| For ios users: https://snack.expo.dev/@sherin11/step-counter-app (Scan the QR code) |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| module.exports = function (api) { | ||
| api.cache(true); | ||
| return { | ||
| presets: ['babel-preset-expo'], | ||
| }; | ||
| api.cache(true); | ||
| return { | ||
| presets: ["babel-preset-expo"], | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import React from "react"; | ||
|
|
||
| import styled from "styled-components/native"; | ||
|
|
||
| const Container = styled.View` | ||
| flex: 1; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| const Image = styled.Image` | ||
| height: 250px; | ||
| width: 250px; | ||
| align-items: center; | ||
| margin: 20px; | ||
| margin-left: auto; | ||
| margin-right: auto; | ||
| `; | ||
|
|
||
| const Text = styled.Text` | ||
| font-size: 30px; | ||
| color: black; | ||
| text-align: center; | ||
| margin: 10px; | ||
| `; | ||
| const HomeScreen = (navigation) => { | ||
| return ( | ||
| <Container> | ||
| <Text>Walking briskly, even for a minute, counts as exercise</Text> | ||
| <Image source={require("../assets/run-img.png")} /> | ||
| <Text>Take your first step today to a healthy lifestyle</Text> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default HomeScreen; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import React, { createRef } from "react"; | ||
| import { NavigationContainer } from "@react-navigation/native"; | ||
| import { createBottomTabNavigator } from "@react-navigation/bottom-tabs"; | ||
| import Ionicons from "@expo/vector-icons/Ionicons"; | ||
| import styled from "styled-components/native"; | ||
| import HomeScreen from "./HomeScreen"; | ||
| import PedometerScreen from "./PedometerScreen"; | ||
|
|
||
| const homescreen = "Home"; | ||
| const pedometerScreen = "Step counter"; | ||
|
|
||
| const Tab = createBottomTabNavigator(); | ||
| const Container = styled.View` | ||
| flex: 1; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| const Title = styled.Text` | ||
| font-size: 40px; | ||
| color: black; | ||
| margin: 50px; | ||
| text-align: center; | ||
| margin-top: 0px; | ||
| `; | ||
|
|
||
| const Text = styled.Text` | ||
| font-size: 30px; | ||
| color: black; | ||
| text-align: center; | ||
| margin: 10px; | ||
| `; | ||
| const Main = () => { | ||
| return ( | ||
| <NavigationContainer> | ||
| <Tab.Navigator | ||
| initialRouteName={homescreen} | ||
| screenOptions={({ route }) => ({ | ||
| tabBarIcon: ({ focused, color, size }) => { | ||
| let iconName; | ||
| let rn = route.name; | ||
| if (rn === homescreen) { | ||
| iconName = focused ? "home" : "home"; | ||
| } else if (rn === pedometerScreen) { | ||
| iconName = focused ? "walk" : "walk"; | ||
| } | ||
| return <Ionicons name={iconName} size={size} color={color} />; | ||
| }, | ||
| })} | ||
| > | ||
| <Tab.Screen name={homescreen} component={HomeScreen} /> | ||
| <Tab.Screen name={pedometerScreen} component={PedometerScreen} /> | ||
| </Tab.Navigator> | ||
| </NavigationContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export default Main; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import React, { useState, useEffect } from "react"; | ||
| import { Pedometer } from "expo-sensors"; | ||
| import styled from "styled-components/native"; | ||
|
|
||
| const Container = styled.View` | ||
| flex: 1; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| const Title = styled.Text` | ||
| font-size: 40px; | ||
| color: palevioletred; | ||
| margin: 10px; | ||
| text-align: center; | ||
| `; | ||
|
|
||
| const Text = styled.Text` | ||
| font-size: 30px; | ||
| color: black; | ||
| text-align: center; | ||
| margin-top: 10px; | ||
| `; | ||
|
|
||
| const PedometerScreen = () => { | ||
| const [pedometer, setpedometer] = useState(""); | ||
| const [stepCount, setStepCount] = useState(0); | ||
|
|
||
| const Distance = (stepCount / 1300).toFixed(3); | ||
|
|
||
| useEffect(() => { | ||
| subscribe(); | ||
| return () => _unsubscribe(); | ||
| }, []); | ||
| const _unsubscribe = () => { | ||
| subscription && _subscription.remove(); | ||
| subscription = null; | ||
| }; | ||
| const subscribe = () => { | ||
| const subscription = Pedometer.watchStepCount((result) => { | ||
Sherin-Susan-Thomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| setStepCount(result.steps); | ||
| }); | ||
| Pedometer.isAvailableAsync().then( | ||
| (result) => { | ||
| setpedometer(String(result)); | ||
| }, | ||
| (error) => { | ||
| setpedometer(error); | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <Container> | ||
| <Title>Track your steps </Title> | ||
|
|
||
| <Text>Steps: {stepCount}</Text> | ||
| <Text> Distance covered: {Distance} </Text> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default PedometerScreen; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Sherin, i have been looking over your app and the functions on and tried it out.
But i had one problem, it did not count my step.