-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
377a9e4
commit 749aaff
Showing
12 changed files
with
369 additions
and
128 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,136 @@ | ||
import React, { useContext } from 'react'; | ||
|
||
import styled from 'styled-components/native'; | ||
import { RFValue } from 'react-native-responsive-fontsize'; | ||
import Ionicons from 'react-native-vector-icons/Ionicons'; | ||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; | ||
import Fontisto from 'react-native-vector-icons/Fontisto'; | ||
import { ThemeContext } from 'styled-components'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
const Card = ({ heading, sunHeading, icon }) => { | ||
return ( | ||
<StyledCard> | ||
<CardContent> | ||
<CardHeading>{heading}</CardHeading> | ||
<CardSubHeading>{sunHeading}</CardSubHeading> | ||
</CardContent> | ||
{icon} | ||
</StyledCard> | ||
); | ||
}; | ||
|
||
export default ({ forecast }) => { | ||
const units = useSelector((state) => state.units); | ||
const themeContext = useContext(ThemeContext); | ||
const iconSize = RFValue(30); | ||
return ( | ||
<> | ||
<BoxRow> | ||
<Card | ||
heading="UVI" | ||
sunHeading={forecast.uvi} | ||
icon={ | ||
<Fontisto | ||
name="day-sunny" | ||
size={iconSize} | ||
color={themeContext.colors.icon} | ||
/> | ||
} | ||
/> | ||
<Card | ||
heading="Wind speed" | ||
sunHeading={`${forecast.wind_speed} ${ | ||
units === 'metric' ? 'm/s' : 'mi/h' | ||
}`} | ||
icon={ | ||
<MaterialCommunityIcons | ||
name="weather-windy" | ||
size={iconSize} | ||
color={themeContext.colors.icon} | ||
/> | ||
} | ||
/> | ||
</BoxRow> | ||
<BoxRow> | ||
<Card | ||
heading="Humidity" | ||
sunHeading={`${forecast.humidity}%`} | ||
icon={ | ||
<MaterialCommunityIcons | ||
name="water-percent" | ||
size={RFValue(30)} | ||
color={themeContext.colors.icon} | ||
/> | ||
} | ||
/> | ||
<Card | ||
heading="Pressure" | ||
sunHeading={`${forecast.pressure} hPa`} | ||
icon={ | ||
<Ionicons | ||
name="speedometer-outline" | ||
size={RFValue(30)} | ||
color={themeContext.colors.icon} | ||
/> | ||
} | ||
/> | ||
</BoxRow> | ||
<BoxRow> | ||
<Card | ||
heading="Cloud cover" | ||
sunHeading={`${forecast.clouds}%`} | ||
icon={ | ||
<Ionicons | ||
name="cloud-outline" | ||
size={RFValue(30)} | ||
color={themeContext.colors.icon} | ||
/> | ||
} | ||
/> | ||
<Card | ||
heading="Dew point" | ||
sunHeading={`${forecast.dew_point} ${ | ||
units === 'metric' ? '⁰C' : '⁰F' | ||
}`} | ||
icon={ | ||
<Ionicons | ||
name="water-outline" | ||
size={RFValue(30)} | ||
color={themeContext.colors.icon} | ||
/> | ||
} | ||
/> | ||
</BoxRow> | ||
</> | ||
); | ||
}; | ||
|
||
const BoxRow = styled.View` | ||
flex-direction: row; | ||
height: ${RFValue(60)}px; | ||
`; | ||
|
||
const StyledCard = styled.View` | ||
flex: 1; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin: ${RFValue(2)}px; | ||
border-radius: ${RFValue(10)}px; | ||
border: 1px ${({ theme }) => theme.colors.border}; | ||
padding-horizontal: ${RFValue(15)}px; | ||
background-color: ${({ theme }) => theme.colors.backgroundAlt}; | ||
`; | ||
|
||
const CardContent = styled.View``; | ||
|
||
const CardHeading = styled.Text` | ||
color: ${({ theme }) => theme.colors.text}; | ||
font-size: ${RFValue(16)}px; | ||
`; | ||
|
||
const CardSubHeading = styled.Text` | ||
color: ${({ theme }) => theme.colors.primary}; | ||
font-size: ${RFValue(12)}px; | ||
`; |
This file contains 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
This file contains 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,109 @@ | ||
import React from 'react'; | ||
import { Dimensions } from 'react-native'; | ||
|
||
import styled from 'styled-components/native'; | ||
import { LineChart } from 'react-native-chart-kit'; | ||
import { RFValue } from 'react-native-responsive-fontsize'; | ||
import { useSelector } from 'react-redux'; | ||
import moment from 'moment'; | ||
import { Svg, Text as TextSVG } from 'react-native-svg'; | ||
|
||
import { round, weatherIcons, rootNavigation } from '../utils'; | ||
|
||
export default () => { | ||
const timeFormat = useSelector((state) => state.timeFormat); | ||
const hourly = useSelector((state) => state.forecast.hourly); | ||
|
||
const timeString = (sec) => { | ||
if (timeFormat === '24') return moment(sec * 1000).format('HH:mm'); | ||
return moment(sec * 1000).format('hh:mm a'); | ||
}; | ||
const chartData = { | ||
labels: hourly.map((item) => timeString(item.dt)), | ||
datasets: [ | ||
{ | ||
data: hourly.map((item) => round(item.temp)), | ||
color: (opacity = 0.5) => `rgba(255, 255, 255, ${opacity})`, | ||
}, | ||
], | ||
legend: [], | ||
}; | ||
const chartConfig = { | ||
backgroundColor: '#005aae', | ||
backgroundGradientFrom: '#006ace', | ||
backgroundGradientTo: '#40a1fc', | ||
decimalPlaces: 2, | ||
color: (opacity = 0) => `rgba(255, 255, 255, ${opacity})`, | ||
labelColor: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`, | ||
style: {}, | ||
propsForDots: { | ||
r: '4', | ||
strokeWidth: '2', | ||
stroke: '#40a1fc', | ||
}, | ||
propsForLabels: { fontSize: RFValue(9) }, | ||
propsForVerticalLabels: { fontWeight: 'bold', fontSize: RFValue(8) }, | ||
}; | ||
return ( | ||
<Container> | ||
{/* <HeadingText>Hourly forecast</HeadingText> */} | ||
<ScrollView horizontal={true}> | ||
<LineChart | ||
data={chartData} | ||
width={4000} | ||
height={RFValue(150)} | ||
yAxisSuffix="°" | ||
yAxisInterval={6} | ||
yLabelsOffset={20} | ||
chartConfig={chartConfig} | ||
// bezier | ||
withHorizontalLines={false} | ||
withInnerLines={false} | ||
withOuterLines={false} | ||
withHorizontalLabels={false} | ||
fromZero | ||
renderDotContent={({ x, y, index, indexData }) => { | ||
return ( | ||
<TextSVG | ||
key={index} | ||
x={x} | ||
y={y - 10} | ||
fill="white" | ||
fontSize={RFValue(9)} | ||
fontWeight="bold" | ||
textAnchor="middle" | ||
> | ||
{indexData}° | ||
</TextSVG> | ||
); | ||
}} | ||
formatYLabel={(label) => round(label)} | ||
style={{}} | ||
/> | ||
</ScrollView> | ||
</Container> | ||
); | ||
}; | ||
|
||
const Container = styled.View` | ||
margin: ${RFValue(10)}px; | ||
margin-top: 0px; | ||
border-radius: ${RFValue(10)}px; | ||
overflow: hidden; | ||
`; | ||
|
||
const ScrollView = styled.ScrollView.attrs(() => ({ | ||
contentContainerStyle: { | ||
justifyContent: 'space-between', | ||
}, | ||
}))``; | ||
|
||
const HeadingText = styled.Text` | ||
z-index: 1000; | ||
position: absolute; | ||
color: white; | ||
font-size: ${RFValue(15)}px; | ||
padding: ${RFValue(10)}px; | ||
padding-top: ${RFValue(5)}px; | ||
font-weight: bold; | ||
`; |
This file contains 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
This file contains 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
Oops, something went wrong.