-
Notifications
You must be signed in to change notification settings - Fork 306
Week 16 - React Native App by Jenny Fiskaare #294
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
base: master
Are you sure you want to change the base?
Changes from all commits
149b99b
4a1e70a
f6b5e40
eeac6dd
8a42fe6
b7eb611
1952e47
2619986
270e5dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,26 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components/native'; | ||
| import React, { useState, useEffect } from "react"; | ||
| import styled from "styled-components/native"; | ||
| import { SensorComponent } from "./components/SensorComponent"; | ||
|
|
||
|
|
||
|
|
||
| const Container = styled.View` | ||
| flex: 1; | ||
| background-color: papayawhip; | ||
| justify-content: center; | ||
| align-items: center; | ||
| flex: 1; | ||
| background-color: #DD4A48; | ||
| justify-content: center; | ||
| align-items: center; | ||
| `; | ||
|
|
||
| const Title = styled.Text` | ||
| font-size: 24px; | ||
| color: palevioletred; | ||
| `; | ||
|
|
||
| const App = () => { | ||
| return ( | ||
| <Container> | ||
| <Title>This is your cool app!</Title> | ||
| <Title>Go to App.js and start coding</Title> | ||
| <Title>💅💅💅</Title> | ||
| </Container> | ||
| ); | ||
|
|
||
| return ( | ||
| <Container> | ||
|
|
||
| <SensorComponent></SensorComponent> | ||
|
|
||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default App; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| # 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. | ||
| Task to create an app in React Native. Due to stressful week I went very basic and createad a step counter by using sensor "Pedometer". | ||
|
|
||
| ## 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? | ||
| Challenging to understand what libraries and dependencies to use. Had problems in the begining to even start the project due to technical issues. If I would have had more time this week I would have put more energy into styling and make the app a bit more complex. | ||
|
|
||
| ## View it live | ||
| https://expo.dev/@jennyfiskaare/project-react-native-app-step-tracker-jenny-fiskaare?serviceType=classic&distribution=expo-go | ||
|
|
||
|
|
||
|
|
||
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import React, { useState, useEffect } from "react"; | ||
| import { Pedometer } from "expo-sensors"; | ||
| import styled from "styled-components/native"; | ||
| import { watchStepCount } from "expo-sensors/build/Pedometer"; | ||
|
|
||
| // = Styled components | ||
| const StepContainer = styled.View` | ||
| display:flex; | ||
| flex-direction:column; | ||
| margin-top:10px; | ||
| `; | ||
|
|
||
| const StepTitle = styled.Text` | ||
| font-size: 70px; | ||
| color: #97BFB4; | ||
| text-align:left; | ||
| font-style:italic; | ||
| opacity:0.7; | ||
| margin-bottom:-30px; | ||
|
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. This can cause displaying the title text off from the mobile screen :) |
||
| margin-left:20px; | ||
| `; | ||
|
|
||
| const StepTitle2 = styled.Text` | ||
| font-size: 70px; | ||
| color: #97BFB4; | ||
| text-align:center; | ||
| `; | ||
|
|
||
| const StepTitle3 = styled.Text` | ||
| font-size: 42px; | ||
| color: #F5EEDC; | ||
| text-align:left; | ||
| padding:20px; | ||
| margin-left:20px; | ||
| margin-top:-10px; | ||
| `; | ||
|
|
||
| const CountingContainer = styled.View` | ||
| background-color:#F5EEDC; | ||
| opacity:0.5; | ||
| margin-top:20px; | ||
| margin-bottom:20px; | ||
| padding:30px; | ||
| ` | ||
|
|
||
| const StepText = styled.Text` | ||
| font-size: 90px; | ||
| font-weight: bold; | ||
| color: #4F091D; | ||
| text-align:center; | ||
| `; | ||
|
|
||
| const StepText2 = styled.Text` | ||
| font-size: 40px; | ||
| color:#F5EEDC; | ||
| text-align:center; | ||
| `; | ||
|
|
||
| const AvaiabilityOnDevice= styled.Text` | ||
| `; | ||
|
|
||
|
|
||
|
|
||
| // = Functions | ||
|
|
||
| export const SensorComponent= () => { | ||
| const [StepAvailability, setStepAvailability] = | ||
| useState(""); | ||
|
|
||
| const [stepCounter, updateStepCounter] = useState(0) | ||
|
|
||
| useEffect(()=>{ | ||
| subscribe() | ||
|
|
||
|
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. you can unsubscribe function by returning it, for example |
||
| },[]) | ||
|
|
||
| const subscribe = () => { | ||
| const subscription=Pedometer.watchStepCount((result)=>{ | ||
| updateStepCounter(result.steps); | ||
| }) | ||
|
|
||
| const _unsubscribe = () => { | ||
|
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. to unsubscribe Pedometer.watchStepCount method, you can define const _unsubscribe function outside of const subscribe function! (now it is in const subscribe function block) |
||
| subscription && subscription.remove(); | ||
|
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. to be able to use subscription as state variable, you can use 'useState' hook and defined it in the begging of this SensorComponent scope :) then you would need to set the method to update subscription state after line 79, for example |
||
| watchStepCount(null); | ||
| } | ||
|
|
||
| // Checks if pedometer function is available on device | ||
|
|
||
| Pedometer.isAvailableAsync().then( | ||
|
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. I briefly checked the document, https://docs.expo.dev/versions/latest/sdk/pedometer/, maybe this Pedometer.isAvailableAsync().then() method needs to be placed in useEffect method??! |
||
| (result) => { | ||
| setStepAvailability((result)); | ||
| }, | ||
| (error) => { | ||
| setStepAvailability(error); | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
|
|
||
| <StepContainer > | ||
| <StepTitle>STEP</StepTitle> | ||
| <StepTitle2>TRACKER</StepTitle2> | ||
| <StepTitle3>How much have you been walking today???</StepTitle3> | ||
|
|
||
|
|
||
| <CountingContainer> | ||
| <StepText>{stepCounter}</StepText> | ||
| </CountingContainer> | ||
|
|
||
| <StepText2>steps...</StepText2> | ||
| <StepText2>...SO FAR!!</StepText2> | ||
|
|
||
| <AvaiabilityOnDevice> {StepAvailability}</AvaiabilityOnDevice> | ||
|
|
||
| </StepContainer > | ||
| ); | ||
| }; | ||
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.
Maybe this font-size is a little bit too large in mobile screen?