-
Couldn't load subscription status.
- Fork 311
Project React Native APP - sensors #306
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
f95d433
f669d8b
56d9c7c
1b86912
ee5ec81
54b9986
0bdc196
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,29 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components/native'; | ||
| import * as React from "react"; | ||
| import styled from "styled-components/native"; | ||
|
|
||
| const Container = styled.View` | ||
| flex: 1; | ||
| background-color: papayawhip; | ||
| justify-content: center; | ||
| align-items: center; | ||
| `; | ||
| import { SensorComponent } from "./components/SensorComponent"; | ||
| import { Header } from './components/Header'; | ||
| import { Footer } from './components/Footer' | ||
|
|
||
| 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> | ||
| ); | ||
| export const App = () => { | ||
| return ( | ||
| <Container> | ||
| <Header></Header> | ||
| <SensorComponent></SensorComponent> | ||
| <Footer></Footer> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default App; | ||
|
|
||
|
|
||
| //----------------------------------------------// | ||
|
|
||
| const Container = styled.View` | ||
| flex: 1; | ||
| background-color: papayawhip; | ||
| justify-content: space-around; | ||
| align-items: center; | ||
| `; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,11 @@ | ||
| # 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. | ||
| This week we were to build an app using React Native. We should be using either a phone sensor like the accelerometer, an api-fetch or React Navigation. The app should be published using Expo. | ||
|
|
||
| ## 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? | ||
|
|
||
|
|
||
| ## 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/@mathilda_karlsson/project-react-native-app?serviceType=classic&distribution=expo-go | ||
|
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. Yeay! I managed to open your expo-app. Have tried on others but failed. So I got the opportunity to test your app and the functionality was there and so was the simple styling. You have added different features to your app which gives it a very user friendly approach! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import React from 'react'; | ||
| import styled from "styled-components/native"; | ||
| import { View, Text, Linking } from 'react-native'; | ||
|
|
||
|
|
||
| export const Footer = () => { | ||
| return ( | ||
| <FooterContainer> | ||
| <FooterText>To make someone else's day, please click the link below and write about somehing that made you smile today</FooterText> | ||
| <FooterLink onPress={() => Linking.openURL('https://spring2022-happy-tweets.netlify.app/')}>Happy Tweets</FooterLink> | ||
|
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 link this project into another project of yours is just brilliant. Makes this weeks project a little bit more dynamic and interesting as well as the viewer can get 2 of your built masterpieces:-) 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'm very impressed with this feature in your footer component. You show the user and fellow code reviewers on how to apply and work with linking URL. This is a component with a clean and easy understandable code to follow! |
||
| </FooterContainer> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
| //----------------------------------------------// | ||
|
|
||
| const FooterContainer = styled.View` | ||
|
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 would say this is easier and much more comfortable working with styling rather than using stylesheet. If you want to test yourself, I would encourage you to do so. You're a great learner so with a little more time you can do it. :D |
||
| max-width: 80%; | ||
| `; | ||
|
|
||
| const FooterText = styled.Text` | ||
| font-size: 14px; | ||
| color: palevioletred; | ||
| text-align: center; | ||
| margin-bottom: 0; | ||
| `; | ||
|
|
||
| const FooterLink = styled.Text` | ||
| font-size: 16px; | ||
| font-weight: 700; | ||
| text-align: center; | ||
| color: palevioletred; | ||
| margin-bottom: 0; | ||
| padding: 20px; | ||
| `; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import React from 'react'; | ||
| import styled from "styled-components/native"; | ||
| import { View } from 'react-native'; | ||
|
|
||
|
|
||
| export const Header = () => { | ||
| return ( | ||
| <View> | ||
| <Title>Hi there!</Title> | ||
| <UnderTitle>Hope you're having a wonderful day!</UnderTitle> | ||
| <UnderTitle>If not, please shake your phone gently or click the button below to recieve some puppy love</UnderTitle> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| //----------------------------------------------// | ||
|
|
||
| const Title = styled.Text` | ||
|
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. Structured and well named style components! |
||
| font-size: 28px; | ||
| color: palevioletred; | ||
| text-align: center; | ||
| margin: 80px 0 10px 0; | ||
| font-weight: 700; | ||
| `; | ||
|
|
||
| const UnderTitle = styled.Text` | ||
| font-size: 16px; | ||
| color: palevioletred; | ||
| text-align: center; | ||
| padding: 2px; | ||
| `; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import React, { useState, useEffect } from "react"; | ||
| import { View, Image, StyleSheet } from 'react-native'; | ||
| import { Accelerometer } from "expo-sensors"; | ||
| import styled from "styled-components/native"; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
|
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. Oh I see that you used StyleSheet here and it worked out great for you. Yeay! |
||
|
|
||
| Image: { | ||
| width: 350, | ||
| height: 350, | ||
| borderRadius: 10, | ||
| }, | ||
| }); | ||
|
Comment on lines
+6
to
+13
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. Interesting to see how you added the styling of the Image in an own component. I styled it directly in the Image Style (line 73 below in your component). But was wondering a bit if I wanted to do more styling - how would adress it. Thanks! |
||
|
|
||
|
|
||
| export const SensorComponent = () => { | ||
| const [image, setImage] = useState({}) | ||
|
|
||
| const generateImage = () => { | ||
|
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. The pictures of the dogs are so cute!! This entire component is full with code but you manage to modify and structure it well so it gets easy to follow. I am happy that you found your way to add a new API address and apply that to the fetch. Now you have any problems finding and using API:s in your future projects. Small action but great impact! |
||
| fetch(`https://random.dog/woof.json`) | ||
| .then(response => response.json()) | ||
| .then(data => setImage(data)) | ||
| } | ||
|
|
||
| useEffect(()=> { | ||
| generateImage(); | ||
| }, []); | ||
|
|
||
| const [data, setData] = useState({ | ||
| x: 0, | ||
| y: 0, | ||
| z: 0, | ||
| }); | ||
|
|
||
| const [subscription, setSubscription] = useState(null); | ||
|
|
||
| const { x, y, z} = data; | ||
|
|
||
| const subscribe = () => { | ||
| setSubscription( | ||
| Accelerometer.addListener((accelerometerData) => { | ||
| setData(accelerometerData); | ||
| }) | ||
| ); | ||
| }; | ||
|
|
||
| const unsubscribe = () => { | ||
| subscription && subscription.remove(); | ||
| setSubscription(null); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| subscribe(); | ||
| return () => unsubscribe(); | ||
| }, []); | ||
|
|
||
| const isShaking = (data) => { | ||
| const totalForce = Math.abs(data.x) + Math.abs(data.y) + Math.abs(data.z); | ||
| return totalForce > 1.78; | ||
| }; | ||
|
|
||
| useEffect(()=> { | ||
| if (isShaking(data)) { | ||
| generateImage(); | ||
| } | ||
| }, [data]) | ||
|
|
||
| return ( | ||
| <APIContainer> | ||
| {isShaking(data) && <ShakeAlert>Shaky Shaky</ShakeAlert>} | ||
| <View> | ||
| <Image | ||
| style={styles.Image} | ||
| source={{ | ||
| uri: image.url | ||
| }} | ||
| /> | ||
| <Button onPress={generateImage}> | ||
|
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. Extra plus that you added a button as well as an alternative for the shaking. Makes it more usable if viewed in desktop. |
||
| <ButtonInfo>CLICK ME</ButtonInfo> | ||
| </Button> | ||
| </View> | ||
| </APIContainer> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
| //----------------------------------------------// | ||
|
|
||
|
|
||
| const APIContainer = styled.View` | ||
|
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. It's not easy naming variables but you have done it in a way that suits the purpose. This makes it easy to tell the difference between regular html and styling components. Good job! |
||
| display: flex; | ||
| flex-direction: column; | ||
| `; | ||
|
|
||
| const ShakeAlert = styled.Text` | ||
| font-size: 15px; | ||
| font-weight: bold; | ||
| color: #aa0000; | ||
| text-align: center; | ||
| `; | ||
|
|
||
| const ButtonInfo = styled.Text` | ||
| text-align: center; | ||
| font-weight: 700; | ||
| `; | ||
|
|
||
| const Button = styled.TouchableOpacity` | ||
|
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. TouchableOpacity - you really stretched your React Native knowledge a little bit more by using this type of button:-) |
||
| padding: 15px 10px; | ||
| width: 150px; | ||
| background-color: tomato; | ||
| border-radius: 8; | ||
| margin: 30px; | ||
| align-self: center; | ||
| ` | ||
|
|
||
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.
Good start of ReadMe - its really convenient to adress the goal that you do here - in order for the reviewer to be aware of the basic needs.