-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add BETA tag on weekly/monthly cigarettes (#234)
* Rework a lot of padding and margins * Fix warning sign alignment * Add tag * Fix react-native-maps version * Remove margin when no additional text
- Loading branch information
1 parent
99cd5d3
commit 5a6d9b5
Showing
19 changed files
with
337 additions
and
235 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Sh**t! I Smoke | ||
// Copyright (C) 2018-2019 Marcelo S. Coelho, Amaury Martiny | ||
|
||
// Sh**t! I Smoke is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Sh**t! I Smoke is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Sh**t! I Smoke. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import React, { useContext } from 'react'; | ||
import { | ||
StyleSheet, | ||
Text, | ||
TouchableOpacity, | ||
View, | ||
ViewProps | ||
} from 'react-native'; | ||
import { scale } from 'react-native-size-matters'; | ||
import { NavigationInjectedProps } from 'react-navigation'; | ||
|
||
import { aboutSections } from '../../About'; | ||
import { i18n } from '../../../localization'; | ||
import { Frequency } from '../SelectFrequency'; | ||
import { ApiContext, CurrentLocationContext } from '../../../stores'; | ||
import { track } from '../../../util/amplitude'; | ||
import { isStationTooFar } from '../../../util/station'; | ||
import * as theme from '../../../util/theme'; | ||
|
||
interface AdditionalInfoProps extends NavigationInjectedProps, ViewProps { | ||
frequency: Frequency; | ||
} | ||
|
||
export function AdditionalInfo (props: AdditionalInfoProps) { | ||
const { api } = useContext(ApiContext)!; | ||
const { currentLocation } = useContext(CurrentLocationContext); | ||
const { frequency, navigation, style, ...rest } = props; | ||
|
||
const isTooFar = isStationTooFar(currentLocation!, api!); | ||
|
||
function renderBeta () { | ||
return ( | ||
<TouchableOpacity | ||
onPress={() => { | ||
track('HOME_SCREEN_BETA_INACCURATE_CLICK'); | ||
navigation.navigate('About', { | ||
scrollInto: aboutSections.aboutBetaInaccurate | ||
}); | ||
}} | ||
style={styles.linkToAbout} | ||
> | ||
<View style={styles.tag}> | ||
<Text style={styles.tagLabel}>BETA</Text> | ||
</View> | ||
<Text style={theme.text}>{i18n.t('home_beta_not_accurate')}</Text> | ||
</TouchableOpacity> | ||
); | ||
} | ||
|
||
if (frequency === 'daily' && !isTooFar) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<View style={[theme.withPadding, style]} {...rest}> | ||
{frequency !== 'daily' | ||
? renderBeta() | ||
: isTooFar && ( | ||
<Text style={theme.text}> | ||
{i18n.t('home_station_too_far_message')} | ||
</Text> | ||
)} | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
linkToAbout: { | ||
alignItems: 'center', | ||
flexDirection: 'row' | ||
}, | ||
tag: { | ||
backgroundColor: '#C4C4C4', | ||
borderRadius: scale(10), | ||
marginRight: theme.spacing.mini, | ||
paddingHorizontal: scale(6), | ||
paddingVertical: scale(3) | ||
}, | ||
tagLabel: { | ||
color: 'white', | ||
fontSize: scale(10), | ||
letterSpacing: scale(1), | ||
marginLeft: scale(2), | ||
textAlign: 'center' | ||
} | ||
}); |
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,89 @@ | ||
// Sh**t! I Smoke | ||
// Copyright (C) 2018-2019 Marcelo S. Coelho, Amaury Martiny | ||
|
||
// Sh**t! I Smoke is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Sh**t! I Smoke is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Sh**t! I Smoke. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import React, { useContext } from 'react'; | ||
import { StyleSheet, Text, View, ViewProps } from 'react-native'; | ||
|
||
import { Cigarettes } from '../../../components'; | ||
import { i18n } from '../../../localization'; | ||
import { Frequency } from '../SelectFrequency'; | ||
import { CurrentLocationContext } from '../../../stores'; | ||
import swearWords from './swearWords'; | ||
import * as theme from '../../../util/theme'; | ||
|
||
interface CigaretteBlockProps extends ViewProps { | ||
cigaretteCount: number; | ||
frequency: Frequency; | ||
} | ||
|
||
function getSwearWord (cigaretteCount: number) { | ||
if (cigaretteCount <= 1) return i18n.t('home_common_oh'); | ||
|
||
// Return a random swear word | ||
return swearWords[Math.floor(Math.random() * swearWords.length)]; | ||
} | ||
|
||
export function CigaretteBlock (props: CigaretteBlockProps) { | ||
const { isGps } = useContext(CurrentLocationContext)!; | ||
const { cigaretteCount, frequency, style, ...rest } = props; | ||
|
||
const renderCigarettesText = () => { | ||
// Round to 1 decimal | ||
const cigarettes = Math.round(cigaretteCount * 10) / 10; | ||
|
||
const text = i18n.t('home_smoked_cigarette_title', { | ||
swearWord: getSwearWord(cigaretteCount), | ||
presentPast: | ||
isGps && frequency === 'daily' | ||
? i18n.t('home_common_you_smoke') | ||
: i18n.t('home_common_you_d_smoke'), | ||
singularPlural: | ||
cigarettes === 1 | ||
? i18n.t('home_common_cigarette').toLowerCase() | ||
: i18n.t('home_common_cigarettes').toLowerCase(), | ||
cigarettes | ||
}); | ||
|
||
const [firstPartText, secondPartText] = text.split('<'); | ||
|
||
return ( | ||
<Text style={styles.shit}> | ||
{firstPartText} | ||
<Text style={styles.cigarettesCount}> | ||
{secondPartText.split('>')[0]} | ||
</Text> | ||
{secondPartText.split('>')[1]} | ||
</Text> | ||
); | ||
}; | ||
|
||
return ( | ||
<View style={[theme.withPadding, style]} {...rest}> | ||
<Cigarettes cigarettes={cigaretteCount} /> | ||
{renderCigarettesText()} | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
cigarettesCount: { | ||
color: theme.primaryColor | ||
}, | ||
shit: { | ||
...theme.shitText, | ||
marginTop: theme.spacing.normal | ||
} | ||
}); |
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
Oops, something went wrong.