From 7dbbef64cb9495a6752a66be11380b67b7666eb5 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 12:05:54 +0100 Subject: [PATCH 01/17] Moved Cigarette in to a common component --- .../CigaretteBlock/CigaretteBlock.tsx | 32 +++++++++---------- .../CigaretteBlock/index.ts | 0 .../CigaretteBlock/swearWords.ts | 2 +- App/components/index.ts | 1 + 4 files changed, 18 insertions(+), 17 deletions(-) rename App/{Screens/Home => components}/CigaretteBlock/CigaretteBlock.tsx (75%) rename App/{Screens/Home => components}/CigaretteBlock/index.ts (100%) rename App/{Screens/Home => components}/CigaretteBlock/swearWords.ts (95%) diff --git a/App/Screens/Home/CigaretteBlock/CigaretteBlock.tsx b/App/components/CigaretteBlock/CigaretteBlock.tsx similarity index 75% rename from App/Screens/Home/CigaretteBlock/CigaretteBlock.tsx rename to App/components/CigaretteBlock/CigaretteBlock.tsx index fd5f57a7..671ddc1f 100644 --- a/App/Screens/Home/CigaretteBlock/CigaretteBlock.tsx +++ b/App/components/CigaretteBlock/CigaretteBlock.tsx @@ -17,12 +17,12 @@ 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 { Cigarettes } from '..'; +import { i18n } from '../../localization'; +import { Frequency } from '../../Screens/Home/SelectFrequency'; +import { CurrentLocationContext } from '../../stores'; import swearWords from './swearWords'; -import * as theme from '../../../util/theme'; +import * as theme from '../../util/theme'; interface CigaretteBlockProps extends ViewProps { cigaretteCount: number; @@ -47,13 +47,13 @@ export function CigaretteBlock (props: CigaretteBlockProps) { 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'), + 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 === 1 + ? i18n.t('home_common_cigarette').toLowerCase() + : i18n.t('home_common_cigarettes').toLowerCase(), cigarettes }); @@ -61,11 +61,11 @@ export function CigaretteBlock (props: CigaretteBlockProps) { return ( - {firstPartText} - - {secondPartText.split('>')[0]} - - {secondPartText.split('>')[1]} + {firstPartText} + + {secondPartText.split('>')[0]} + + {secondPartText.split('>')[1]} ); }; diff --git a/App/Screens/Home/CigaretteBlock/index.ts b/App/components/CigaretteBlock/index.ts similarity index 100% rename from App/Screens/Home/CigaretteBlock/index.ts rename to App/components/CigaretteBlock/index.ts diff --git a/App/Screens/Home/CigaretteBlock/swearWords.ts b/App/components/CigaretteBlock/swearWords.ts similarity index 95% rename from App/Screens/Home/CigaretteBlock/swearWords.ts rename to App/components/CigaretteBlock/swearWords.ts index 27060dd5..7a0d2959 100644 --- a/App/Screens/Home/CigaretteBlock/swearWords.ts +++ b/App/components/CigaretteBlock/swearWords.ts @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Sh**t! I Smoke. If not, see . -import { i18n } from '../../../localization'; +import { i18n } from '../../localization'; export default [ i18n.t('home_swear_word_shoot'), diff --git a/App/components/index.ts b/App/components/index.ts index 6962280e..0447253a 100644 --- a/App/components/index.ts +++ b/App/components/index.ts @@ -19,6 +19,7 @@ export * from './Banner'; export * from './BoxButton'; export * from './Button'; export * from './Cigarettes'; +export * from './CigaretteBlock'; export * from './ChangeLocation'; export * from './CurrentLocation'; export * from './ListItem'; From 27b107db866f75bab95630c64ac6ba0413ce5331 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 12:33:48 +0100 Subject: [PATCH 02/17] Made frequency terms global (not screen specific) --- App/Screens/Home/SelectFrequency/SelectFrequency.tsx | 10 +++++----- App/localization/languages/en-us.json | 8 ++++---- App/localization/languages/en.json | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/App/Screens/Home/SelectFrequency/SelectFrequency.tsx b/App/Screens/Home/SelectFrequency/SelectFrequency.tsx index 31f696cf..9b7e95c1 100644 --- a/App/Screens/Home/SelectFrequency/SelectFrequency.tsx +++ b/App/Screens/Home/SelectFrequency/SelectFrequency.tsx @@ -28,13 +28,13 @@ interface SelectFrequencyProps extends ScrollViewProps { onChangeFrequency: (frequency: Frequency) => void; } -export function SelectFrequency (props: SelectFrequencyProps) { +export function SelectFrequency(props: SelectFrequencyProps) { const scroll = useRef(null); const [dailyWidth, setDailyWidth] = useState(0); // Width of the daily button const { frequency, onChangeFrequency, style, ...rest } = props; - function handleChangeFrequency (f: Frequency) { + function handleChangeFrequency(f: Frequency) { setTimeout(() => { onChangeFrequency(f); }, 400); @@ -62,7 +62,7 @@ export function SelectFrequency (props: SelectFrequencyProps) { }} style={styles.boxButton} > - {i18n.t('home_frequency_daily')} + {i18n.t('frequency_daily')} - {i18n.t('home_frequency_weekly')} + {i18n.t('frequency_weekly')} - {i18n.t('home_frequency_monthly')} + {i18n.t('frequency_monthly')} ); diff --git a/App/localization/languages/en-us.json b/App/localization/languages/en-us.json index e9009618..805dee6a 100644 --- a/App/localization/languages/en-us.json +++ b/App/localization/languages/en-us.json @@ -4,6 +4,9 @@ "error_screen_choose_other_location": "Choose other location", "error_screen_error_description": "There's either a problem with our databases, or you don't have any Air Monitoring Stations near you. Try again later!", "error_screen_error_message": "Error: {{errorText}}", + "frequency_daily": "daily", + "frequency_weekly": "weekly", + "frequency_monthly": "monthly", "home_station_too_far_message": "We couldn’t find a closer station to you.\nResults may be inaccurate at this distance.", "home_beta_not_accurate": "Numbers may not be 100% accurate.", "home_share_title": "Did you know that you may be smoking up to 20 cigarettes per day, just for living in a big city?", @@ -17,9 +20,6 @@ "home_btn_more_details": "More details", "home_btn_faq_about": "Faq/About", "home_btn_share": "Share", - "home_frequency_daily": "daily", - "home_frequency_weekly": "weekly", - "home_frequency_monthly": "monthly", "home_common_you_smoke": "You smoke", "home_common_you_d_smoke": "You'd smoke", "home_common_you_ll_smoke": "You'll smoke", @@ -83,4 +83,4 @@ "about_credits_available_github": "available on Github", "about_language": "Language", "current_location_unknown_station": "Unknown AQI station" -} +} \ No newline at end of file diff --git a/App/localization/languages/en.json b/App/localization/languages/en.json index 0f518e90..097aae75 100644 --- a/App/localization/languages/en.json +++ b/App/localization/languages/en.json @@ -4,6 +4,9 @@ "error_screen_choose_other_location": "Choose other location", "error_screen_error_description": "There's either a problem with our databases, or you don't have any Air Monitoring Stations near you. Try again later!", "error_screen_error_message": "Error: {{errorText}}", + "frequency_daily": "daily", + "frequency_weekly": "weekly", + "frequency_monthly": "monthly", "home_station_too_far_message": "We couldn’t find a closer station to you.\nResults may be inaccurate at this distance.", "home_beta_not_accurate": "Numbers may not be 100% accurate.", "home_share_title": "Did you know that you may be smoking up to 20 cigarettes per day, just for living in a big city?", @@ -17,9 +20,6 @@ "home_btn_more_details": "More details", "home_btn_faq_about": "Faq/About", "home_btn_share": "Share", - "home_frequency_daily": "daily", - "home_frequency_weekly": "weekly", - "home_frequency_monthly": "monthly", "home_common_you_smoke": "You smoke", "home_common_you_d_smoke": "You'd smoke", "home_common_you_ll_smoke": "You'll smoke", @@ -83,4 +83,4 @@ "about_credits_available_github": "available on Github", "about_language": "Language", "current_location_unknown_station": "Unknown AQI station" -} +} \ No newline at end of file From f6451d6d1a488ce26d4eb0219d1f30851725076d Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 13:22:08 +0100 Subject: [PATCH 03/17] Moved the cigarette count calculation to the cigarette block --- App/Screens/Home/Home.tsx | 26 ++++----------- .../CigaretteBlock/CigaretteBlock.tsx | 32 ++++++++++++++++--- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/App/Screens/Home/Home.tsx b/App/Screens/Home/Home.tsx index c38590a3..a0af74e7 100644 --- a/App/Screens/Home/Home.tsx +++ b/App/Screens/Home/Home.tsx @@ -19,7 +19,7 @@ import { ScrollView, StyleSheet, View } from 'react-native'; import { NavigationInjectedProps } from 'react-navigation'; import { AdditionalInfo } from './AdditionalInfo'; -import { CigaretteBlock } from './CigaretteBlock'; +import { CigaretteBlock, getCigaretteCount } from '../../components'; import { Footer } from './Footer'; import { Header } from './Header'; import { Frequency, SelectFrequency } from './SelectFrequency'; @@ -31,22 +31,6 @@ import * as theme from '../../util/theme'; interface HomeProps extends NavigationInjectedProps {} -/** - * Compute the number of cigarettes to show - */ -function getCigaretteCount (frequency: Frequency, api: Api) { - switch (frequency) { - case 'daily': { - return api.shootISmoke.cigarettes; - } - case 'weekly': - return api.shootISmoke.cigarettes * 7; - case 'monthly': { - return api.shootISmoke.cigarettes * 30; - } - } -} - export function Home (props: HomeProps) { const { api } = useContext(ApiContext); const [frequency, setFrenquency] = useState('daily'); @@ -55,9 +39,11 @@ export function Home (props: HomeProps) { trackScreen('HOME'); + const cigarettesPerDay = api!.shootISmoke.cigarettes + return ( - +
{ track('HOME_SCREEN_CHANGE_LOCATION_CLICK'); @@ -66,7 +52,7 @@ export function Home (props: HomeProps) { /> @@ -81,7 +67,7 @@ export function Home (props: HomeProps) { track('HOME_SCREEN_MONTHLY_CLICK'); } - setFrenquency(freq); + setFrequency(freq); }} style={styles.withMargin} /> diff --git a/App/components/CigaretteBlock/CigaretteBlock.tsx b/App/components/CigaretteBlock/CigaretteBlock.tsx index 671ddc1f..c9f6078c 100644 --- a/App/components/CigaretteBlock/CigaretteBlock.tsx +++ b/App/components/CigaretteBlock/CigaretteBlock.tsx @@ -25,20 +25,39 @@ import swearWords from './swearWords'; import * as theme from '../../util/theme'; interface CigaretteBlockProps extends ViewProps { - cigaretteCount: number; + cigarettesPerDay: number; frequency: Frequency; + displayFrequency?: boolean } -function getSwearWord (cigaretteCount: number) { +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) { +/** + * Compute the number of cigarettes to show + */ +export function getCigaretteCount(frequency: Frequency, cigarettePerDay: number) { + switch (frequency) { + case 'daily': { + return cigarettePerDay; + } + case 'weekly': + return cigarettePerDay * 7; + case 'monthly': { + return cigarettePerDay * 30; + } + } +} + +export function CigaretteBlock(props: CigaretteBlockProps) { const { isGps } = useContext(CurrentLocationContext)!; - const { cigaretteCount, frequency, style, ...rest } = props; + const { cigarettesPerDay, frequency, style, displayFrequency, ...rest } = props; + + const cigaretteCount = getCigaretteCount(frequency, cigarettesPerDay) const renderCigarettesText = () => { // Round to 1 decimal @@ -57,15 +76,18 @@ export function CigaretteBlock (props: CigaretteBlockProps) { cigarettes }); + console.log('text :', text); const [firstPartText, secondPartText] = text.split('<'); + const frequencyText = displayFrequency ? ({i18n.t(`frequency_${frequency}`)}) : null + return ( {firstPartText} {secondPartText.split('>')[0]} - {secondPartText.split('>')[1]} + {secondPartText.split('>')[1]} {frequencyText} ); }; From acf6590dc3f15bb675818138cdb49acab007187f Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 13:26:14 +0100 Subject: [PATCH 04/17] Moved frequency from Home state to global context --- App/App.tsx | 5 ++++- App/Screens/Home/Home.tsx | 15 ++++++--------- App/stores/frequency.tsx | 39 +++++++++++++++++++++++++++++++++++++++ App/stores/index.ts | 1 + 4 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 App/stores/frequency.tsx diff --git a/App/App.tsx b/App/App.tsx index fd1547d3..30898029 100644 --- a/App/App.tsx +++ b/App/App.tsx @@ -25,6 +25,7 @@ import { Background as LoadingBackground } from './Screens/Loading/Background'; import { ApiContextProvider, ErrorContextProvider, + FrequencyContextProvider, LocationContextProvider } from './stores'; import { setupAmplitude, track } from './util/amplitude'; @@ -71,7 +72,9 @@ export function App () { - + + + diff --git a/App/Screens/Home/Home.tsx b/App/Screens/Home/Home.tsx index a0af74e7..c9e54a2f 100644 --- a/App/Screens/Home/Home.tsx +++ b/App/Screens/Home/Home.tsx @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Sh**t! I Smoke. If not, see . -import React, { useContext, useState } from 'react'; +import React, { useContext } from 'react'; import { ScrollView, StyleSheet, View } from 'react-native'; import { NavigationInjectedProps } from 'react-navigation'; @@ -22,24 +22,21 @@ import { AdditionalInfo } from './AdditionalInfo'; import { CigaretteBlock, getCigaretteCount } from '../../components'; import { Footer } from './Footer'; import { Header } from './Header'; -import { Frequency, SelectFrequency } from './SelectFrequency'; +import { SelectFrequency } from './SelectFrequency'; import { SmokeVideo } from './SmokeVideo'; -import { ApiContext } from '../../stores'; -import { Api } from '../../stores/fetchApi'; +import { ApiContext, FrequencyContext } from '../../stores'; import { track, trackScreen } from '../../util/amplitude'; import * as theme from '../../util/theme'; -interface HomeProps extends NavigationInjectedProps {} +interface HomeProps extends NavigationInjectedProps { } export function Home (props: HomeProps) { const { api } = useContext(ApiContext); - const [frequency, setFrenquency] = useState('daily'); - - const cigaretteCount = getCigaretteCount(frequency, api!); + const { currentFrequency: frequency, setFrequency } = useContext(FrequencyContext); trackScreen('HOME'); - const cigarettesPerDay = api!.shootISmoke.cigarettes + const cigarettesPerDay = api!.shootISmoke.cigarettes; return ( diff --git a/App/stores/frequency.tsx b/App/stores/frequency.tsx new file mode 100644 index 00000000..31613d00 --- /dev/null +++ b/App/stores/frequency.tsx @@ -0,0 +1,39 @@ +// 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 . + +import React, { createContext, useState } from 'react'; +import { Frequency } from '../Screens/Home/SelectFrequency'; + +export const FrequencyContext = createContext(); + +export function FrequencyContextProvider ({ + children +}: { + children: JSX.Element; +}) { + const [currentFrequency, setFrequency] = useState('daily'); + + return ( + + {children} + + ); +} diff --git a/App/stores/index.ts b/App/stores/index.ts index ea165d38..49c36226 100644 --- a/App/stores/index.ts +++ b/App/stores/index.ts @@ -16,4 +16,5 @@ export * from './api'; export * from './error'; +export * from './frequency'; export * from './location'; From ca4762b63906c1dd3068eff567e36b9084b547f4 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 13:27:37 +0100 Subject: [PATCH 05/17] Linting --- App/Screens/Home/SelectFrequency/SelectFrequency.tsx | 4 ++-- App/components/CigaretteBlock/CigaretteBlock.tsx | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/App/Screens/Home/SelectFrequency/SelectFrequency.tsx b/App/Screens/Home/SelectFrequency/SelectFrequency.tsx index 9b7e95c1..d373f0e9 100644 --- a/App/Screens/Home/SelectFrequency/SelectFrequency.tsx +++ b/App/Screens/Home/SelectFrequency/SelectFrequency.tsx @@ -28,13 +28,13 @@ interface SelectFrequencyProps extends ScrollViewProps { onChangeFrequency: (frequency: Frequency) => void; } -export function SelectFrequency(props: SelectFrequencyProps) { +export function SelectFrequency (props: SelectFrequencyProps) { const scroll = useRef(null); const [dailyWidth, setDailyWidth] = useState(0); // Width of the daily button const { frequency, onChangeFrequency, style, ...rest } = props; - function handleChangeFrequency(f: Frequency) { + function handleChangeFrequency (f: Frequency) { setTimeout(() => { onChangeFrequency(f); }, 400); diff --git a/App/components/CigaretteBlock/CigaretteBlock.tsx b/App/components/CigaretteBlock/CigaretteBlock.tsx index c9f6078c..486dc2f7 100644 --- a/App/components/CigaretteBlock/CigaretteBlock.tsx +++ b/App/components/CigaretteBlock/CigaretteBlock.tsx @@ -30,7 +30,7 @@ interface CigaretteBlockProps extends ViewProps { displayFrequency?: boolean } -function getSwearWord(cigaretteCount: number) { +function getSwearWord (cigaretteCount: number) { if (cigaretteCount <= 1) return i18n.t('home_common_oh'); // Return a random swear word @@ -40,7 +40,7 @@ function getSwearWord(cigaretteCount: number) { /** * Compute the number of cigarettes to show */ -export function getCigaretteCount(frequency: Frequency, cigarettePerDay: number) { +export function getCigaretteCount (frequency: Frequency, cigarettePerDay: number) { switch (frequency) { case 'daily': { return cigarettePerDay; @@ -53,11 +53,11 @@ export function getCigaretteCount(frequency: Frequency, cigarettePerDay: number) } } -export function CigaretteBlock(props: CigaretteBlockProps) { +export function CigaretteBlock (props: CigaretteBlockProps) { const { isGps } = useContext(CurrentLocationContext)!; const { cigarettesPerDay, frequency, style, displayFrequency, ...rest } = props; - const cigaretteCount = getCigaretteCount(frequency, cigarettesPerDay) + const cigaretteCount = getCigaretteCount(frequency, cigarettesPerDay); const renderCigarettesText = () => { // Round to 1 decimal @@ -79,7 +79,7 @@ export function CigaretteBlock(props: CigaretteBlockProps) { console.log('text :', text); const [firstPartText, secondPartText] = text.split('<'); - const frequencyText = displayFrequency ? ({i18n.t(`frequency_${frequency}`)}) : null + const frequencyText = displayFrequency ? ({i18n.t(`frequency_${frequency}`)}) : null; return ( From e9dadff18d3724cb31b714083871071ab853f797 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 18:54:16 +0100 Subject: [PATCH 06/17] Added a share screen and share image --- .../ShareScreen/ShareImage/ShareImage.tsx | 64 +++++++++++++ App/Screens/ShareScreen/ShareImage/index.ts | 17 ++++ App/Screens/ShareScreen/ShareScreen.tsx | 92 +++++++++++++++++++ App/Screens/ShareScreen/index.ts | 17 ++++ package.json | 1 + yarn.lock | 2 +- 6 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 App/Screens/ShareScreen/ShareImage/ShareImage.tsx create mode 100644 App/Screens/ShareScreen/ShareImage/index.ts create mode 100644 App/Screens/ShareScreen/ShareScreen.tsx create mode 100644 App/Screens/ShareScreen/index.ts diff --git a/App/Screens/ShareScreen/ShareImage/ShareImage.tsx b/App/Screens/ShareScreen/ShareImage/ShareImage.tsx new file mode 100644 index 00000000..938c7bfe --- /dev/null +++ b/App/Screens/ShareScreen/ShareImage/ShareImage.tsx @@ -0,0 +1,64 @@ +// 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 . + +import React, { useContext } from 'react'; +import { + StyleSheet, + Text, + View +} from 'react-native'; + +import { CigaretteBlock, CurrentLocation } from '../../../components'; +import { ApiContext, CurrentLocationContext, FrequencyContext } from '../../../stores'; +import * as theme from '../../../util/theme'; + +export function ShareImage () { + const { api } = useContext(ApiContext)!; + const { currentLocation } = useContext(CurrentLocationContext); + const { currentFrequency } = useContext(FrequencyContext); + + const cigarettesPerDay = api!.shootISmoke.cigarettes; + + return ( + + + + + + + https://shootismoke.github.io/ + + + ); +} + +const styles = StyleSheet.create({ + container: { + ...theme.withPadding, + alignItems: 'flex-start', + flexDirection: 'column', + paddingTop: theme.spacing.normal, + paddingBottom: theme.spacing.normal, + width: 400, + backgroundColor: 'white' + }, + + urlText: { + ...theme.text, + alignSelf: 'center', + marginTop: theme.spacing.mini + } +}); diff --git a/App/Screens/ShareScreen/ShareImage/index.ts b/App/Screens/ShareScreen/ShareImage/index.ts new file mode 100644 index 00000000..58130df3 --- /dev/null +++ b/App/Screens/ShareScreen/ShareImage/index.ts @@ -0,0 +1,17 @@ +// 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 . + +export * from './ShareImage'; diff --git a/App/Screens/ShareScreen/ShareScreen.tsx b/App/Screens/ShareScreen/ShareScreen.tsx new file mode 100644 index 00000000..460b419b --- /dev/null +++ b/App/Screens/ShareScreen/ShareScreen.tsx @@ -0,0 +1,92 @@ +// 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 . + +import React, { useEffect, createRef } from 'react'; +import { Share, StyleSheet, View } from 'react-native'; +import { NavigationInjectedProps } from 'react-navigation'; +import { captureRef } from 'react-native-view-shot'; +import { ShareImage } from './ShareImage'; +import { i18n } from '../../localization'; +import { Button } from '../../components'; +import * as theme from '../../util/theme'; + +interface ShareScreenProps extends NavigationInjectedProps { } + +export function ShareScreen (props: ShareScreenProps) { + const refViewShot = createRef(); + + useEffect(() => { + setTimeout(async () => { + try { + const uri = await captureRef(refViewShot, { + format: 'png', + quality: 1 + }); + + await Share.share({ + title: 'Text title', + message: 'Text message', + url: uri + }); + } catch (error) { + } + + handleDismiss(); + }, 750); + }); + + const handleDismiss = () => { + props.navigation.goBack(); + }; + return ( + + + + + + + + + + + ); +} + +const styles = StyleSheet.create({ + container: { + ...theme.fullScreen, + ...theme.withPadding, + flexGrow: 1, + flexDirection: 'column', + backgroundColor: 'rgba(0,0,0,0.8)' + }, + + buttonContainer: { + paddingVertical: 20 + }, + + button: { + paddingHorizontal: 10 + }, + + imageContainer: { + alignItems: 'center', + justifyContent: 'center', + transform: [ + { scale: 0.8 } + ] + } +}); diff --git a/App/Screens/ShareScreen/index.ts b/App/Screens/ShareScreen/index.ts new file mode 100644 index 00000000..f3a9496e --- /dev/null +++ b/App/Screens/ShareScreen/index.ts @@ -0,0 +1,17 @@ +// 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 . + +export * from './ShareScreen'; diff --git a/package.json b/package.json index 2566a843..8cf6aa2d 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "react-native-reanimated": "~1.2.0", "react-native-scroll-into-view": "^1.0.3", "react-native-size-matters": "^0.2.1", + "react-native-view-shot": "~2.6.0", "react-navigation": "^4.0.10", "react-navigation-stack": "^1.8.1", "retry-ts": "^0.1.0", diff --git a/yarn.lock b/yarn.lock index 3a3790b0..d218c621 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6496,7 +6496,7 @@ react-native-svg@*: resolved "https://registry.yarnpkg.com/react-native-svg/-/react-native-svg-9.5.3.tgz#2389f3ffd700c6441166496a1aeade31ead89c59" integrity sha512-VUOe4TLz7RFdmm/XT9EH87VSwlRykx49qbwJMA+dh9eFM7KPY1qH3kEyN7uRCqJD2eE8toxt9NpjR6ByvtPNlA== -react-native-view-shot@2.6.0: +react-native-view-shot@2.6.0, react-native-view-shot@~2.6.0: version "2.6.0" resolved "https://registry.yarnpkg.com/react-native-view-shot/-/react-native-view-shot-2.6.0.tgz#3b23675826f67658366352c4b97b59a6aded2f43" integrity sha512-yO9vWi/11m2hEJl8FrW1SMeVzFfPtMKh20MUInGqlsL0H8Ya2JGGlFfrBzx1KiFR2hFb5OdsTLYNtcVZtJ6pLQ== From 9edc6bbab874f4adb0fb8b268e43887febd7e2cb Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 18:55:24 +0100 Subject: [PATCH 07/17] Added a ShareScreen modal overlay --- App/Screens/Screens.tsx | 21 ++++++++++++++++++++- package.json | 2 ++ yarn.lock | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/App/Screens/Screens.tsx b/App/Screens/Screens.tsx index 1e0c16b2..9b51d9ae 100644 --- a/App/Screens/Screens.tsx +++ b/App/Screens/Screens.tsx @@ -28,6 +28,7 @@ import { NavigationStackOptions, NavigationStackProp } from 'react-navigation-stack'; +import { fadeIn } from 'react-navigation-transitions'; import { About } from './About'; import { Details } from './Details'; @@ -35,6 +36,7 @@ import { ErrorScreen } from './ErrorScreen'; import { Home } from './Home'; import { Loading } from './Loading'; import { Search } from './Search'; +import { ShareScreen } from './ShareScreen'; import { ApiContext, ErrorContext } from '../stores'; import { Api } from '../stores/fetchApi'; import * as theme from '../util/theme'; @@ -60,7 +62,7 @@ function stackNavigatorOptions (initialRouteName: string) { /** * The main stack navigator, for the app. */ -const RootStack = createAppContainer( +const MainStack = createAppContainer( createStackNavigator( { About: { @@ -80,6 +82,23 @@ const RootStack = createAppContainer( ) ); +const RootStack = createAppContainer( + createStackNavigator( + { + Main: { + screen: MainStack + }, + ShareModal: { + screen: ShareScreen + } + }, + { + mode: 'modal', + headerMode: 'none', + transitionConfig: () => fadeIn() + } + ) +); /** * A stack navigator for the error case. */ diff --git a/package.json b/package.json index 8cf6aa2d..a0b94d4d 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "expo-localization": "^7.0.0", "expo-location": "^7.0.0", "expo-permissions": "^7.0.0", + "expo-sharing": "~7.0.0", "fp-ts": "^2.0.5", "haversine": "^1.1.1", "i18n-js": "^3.3.0", @@ -43,6 +44,7 @@ "react-native-view-shot": "~2.6.0", "react-navigation": "^4.0.10", "react-navigation-stack": "^1.8.1", + "react-navigation-transitions": "^1.0.12", "retry-ts": "^0.1.0", "sentry-expo": "~2.0.1", "truncate": "^2.1.0" diff --git a/yarn.lock b/yarn.lock index d218c621..8adc22c2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6563,6 +6563,11 @@ react-navigation-stack@^1.8.1: dependencies: prop-types "^15.7.2" +react-navigation-transitions@^1.0.12: + version "1.0.12" + resolved "https://registry.yarnpkg.com/react-navigation-transitions/-/react-navigation-transitions-1.0.12.tgz#7307668bc7d5fdbdc1954224e7891f7fe6cb5f74" + integrity sha512-Hp0wX9KoXwsFch6Fgiz9HpGjQZDhnyucLbCai0LcaOC3VpmgYmvkbeAg/mQ5Z5exuY6PPrh/+FXU00yMPDHkcw== + react-navigation@^4.0.10: version "4.0.10" resolved "https://registry.yarnpkg.com/react-navigation/-/react-navigation-4.0.10.tgz#ddf41134600689d6ba99e35dd22ba1f664f91e5c" From 828cc35bcbab6d0aa5cef84939cc4f980aa69d0e Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 18:55:37 +0100 Subject: [PATCH 08/17] i18n for the close button --- App/localization/languages/en-us.json | 1 + App/localization/languages/en.json | 1 + 2 files changed, 2 insertions(+) diff --git a/App/localization/languages/en-us.json b/App/localization/languages/en-us.json index 805dee6a..d569872a 100644 --- a/App/localization/languages/en-us.json +++ b/App/localization/languages/en-us.json @@ -1,4 +1,5 @@ { + "close_button": "Close", "error_screen_common_sorry": "Sorry!\n", "error_screen_error_cannot_load_cigarettes": "We cannot load your cigarettes.", "error_screen_choose_other_location": "Choose other location", diff --git a/App/localization/languages/en.json b/App/localization/languages/en.json index 097aae75..5ffbe8f2 100644 --- a/App/localization/languages/en.json +++ b/App/localization/languages/en.json @@ -1,4 +1,5 @@ { + "close_button": "Close", "error_screen_common_sorry": "Sorry!\n", "error_screen_error_cannot_load_cigarettes": "We cannot load your cigarettes.", "error_screen_choose_other_location": "Choose other location", From c87921ceb093903c889ca73f10a61a63d4b907c0 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 18:55:47 +0100 Subject: [PATCH 09/17] Fixed a circular import --- App/components/CigaretteBlock/CigaretteBlock.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/App/components/CigaretteBlock/CigaretteBlock.tsx b/App/components/CigaretteBlock/CigaretteBlock.tsx index 486dc2f7..ce35b2c5 100644 --- a/App/components/CigaretteBlock/CigaretteBlock.tsx +++ b/App/components/CigaretteBlock/CigaretteBlock.tsx @@ -17,7 +17,7 @@ import React, { useContext } from 'react'; import { StyleSheet, Text, View, ViewProps } from 'react-native'; -import { Cigarettes } from '..'; +import { Cigarettes } from '../Cigarettes'; import { i18n } from '../../localization'; import { Frequency } from '../../Screens/Home/SelectFrequency'; import { CurrentLocationContext } from '../../stores'; From a9d54f571ba9274e1f1bd45369aca1b1d69053c7 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Wed, 2 Oct 2019 18:56:07 +0100 Subject: [PATCH 10/17] Replaced previous share with the image --- App/Screens/Home/Footer/Footer.tsx | 11 +++-------- App/Screens/ShareScreen/ShareScreen.tsx | 4 +--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/App/Screens/Home/Footer/Footer.tsx b/App/Screens/Home/Footer/Footer.tsx index 4a21b81e..d93152c8 100644 --- a/App/Screens/Home/Footer/Footer.tsx +++ b/App/Screens/Home/Footer/Footer.tsx @@ -15,7 +15,7 @@ // along with Sh**t! I Smoke. If not, see . import React, { useContext } from 'react'; -import { Share, StyleSheet, View, ViewProps } from 'react-native'; +import { StyleSheet, View, ViewProps } from 'react-native'; import { NavigationInjectedProps } from 'react-navigation'; import { aboutSections } from '../../About'; @@ -26,7 +26,7 @@ import { track } from '../../../util/amplitude'; import { isStationTooFar } from '../../../util/station'; import * as theme from '../../../util/theme'; -interface FooterProps extends NavigationInjectedProps, ViewProps {} +interface FooterProps extends NavigationInjectedProps, ViewProps { } export function Footer (props: FooterProps) { const { api } = useContext(ApiContext)!; @@ -55,12 +55,7 @@ export function Footer (props: FooterProps) { function handleShare () { track('HOME_SCREEN_SHARE_CLICK'); - Share.share({ - title: i18n.t('home_share_title'), - message: i18n.t('home_share_message', { - cigarettes: parseFloat(api!.shootISmoke.cigarettes).toFixed(2) - }) - }); + props.navigation.navigate('ShareModal'); } const renderBigButton = () => { diff --git a/App/Screens/ShareScreen/ShareScreen.tsx b/App/Screens/ShareScreen/ShareScreen.tsx index 460b419b..37e5857b 100644 --- a/App/Screens/ShareScreen/ShareScreen.tsx +++ b/App/Screens/ShareScreen/ShareScreen.tsx @@ -25,7 +25,7 @@ import * as theme from '../../util/theme'; interface ShareScreenProps extends NavigationInjectedProps { } -export function ShareScreen (props: ShareScreenProps) { +export function ShareScreen(props: ShareScreenProps) { const refViewShot = createRef(); useEffect(() => { @@ -37,8 +37,6 @@ export function ShareScreen (props: ShareScreenProps) { }); await Share.share({ - title: 'Text title', - message: 'Text message', url: uri }); } catch (error) { From 3fae7d4c5cf8d65f9b7e4c8a2379f559382c2a0c Mon Sep 17 00:00:00 2001 From: James Pearson Date: Thu, 3 Oct 2019 09:11:27 +0100 Subject: [PATCH 11/17] Keep the existing text notification on Android --- App/Screens/Home/Footer/Footer.tsx | 41 +++++++++++++++++++----------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/App/Screens/Home/Footer/Footer.tsx b/App/Screens/Home/Footer/Footer.tsx index d93152c8..45772ffd 100644 --- a/App/Screens/Home/Footer/Footer.tsx +++ b/App/Screens/Home/Footer/Footer.tsx @@ -15,7 +15,7 @@ // along with Sh**t! I Smoke. If not, see . import React, { useContext } from 'react'; -import { StyleSheet, View, ViewProps } from 'react-native'; +import { Platform, Share, StyleSheet, View, ViewProps } from 'react-native'; import { NavigationInjectedProps } from 'react-navigation'; import { aboutSections } from '../../About'; @@ -28,7 +28,7 @@ import * as theme from '../../../util/theme'; interface FooterProps extends NavigationInjectedProps, ViewProps { } -export function Footer (props: FooterProps) { +export function Footer(props: FooterProps) { const { api } = useContext(ApiContext)!; const { currentLocation } = useContext(CurrentLocationContext); // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -36,26 +36,37 @@ export function Footer (props: FooterProps) { const isTooFar = isStationTooFar(currentLocation!, api!); - function goToAbout () { + function goToAbout() { track('HOME_SCREEN_ABOUT_CLICK'); navigation.navigate('About'); } - function goToAboutWhySoFar () { + function goToAboutWhySoFar() { track('HOME_SCREEN_ABOUT_WHY_SO_FAR_CLICK'); navigation.navigate('About', { scrollInto: aboutSections.aboutWhyIsTheStationSoFarTitle }); } - function goToDetails () { + function goToDetails() { track('HOME_SCREEN_DETAILS_CLICK'); navigation.navigate('Details'); } - function handleShare () { + function handleShare() { track('HOME_SCREEN_SHARE_CLICK'); - props.navigation.navigate('ShareModal'); + + // Share doesn't currently support images on Android, so the text version + if (Platform.OS === 'ios') { + props.navigation.navigate('ShareModal'); + } else { + Share.share({ + title: i18n.t('home_share_title'), + message: i18n.t('home_share_message', { + cigarettes: api!.shootISmoke.cigarettes + }) + }); + } } const renderBigButton = () => { @@ -64,10 +75,10 @@ export function Footer (props: FooterProps) { {i18n.t('home_btn_why_is_station_so_far').toUpperCase()} ) : ( - - ); + + ); }; const renderSmallButtons = () => { @@ -78,10 +89,10 @@ export function Footer (props: FooterProps) { {i18n.t('home_btn_more_details').toUpperCase()} ) : ( - - )} + + )} From 58c8cc3f16b81bb44dfc745a1b30647eb6f25721 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Thu, 3 Oct 2019 09:12:09 +0100 Subject: [PATCH 12/17] Linting --- App/Screens/Home/Footer/Footer.tsx | 40 +++++++++---------- App/Screens/ShareScreen/ShareScreen.tsx | 2 +- .../CigaretteBlock/CigaretteBlock.tsx | 1 - 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/App/Screens/Home/Footer/Footer.tsx b/App/Screens/Home/Footer/Footer.tsx index 45772ffd..a9ebda1a 100644 --- a/App/Screens/Home/Footer/Footer.tsx +++ b/App/Screens/Home/Footer/Footer.tsx @@ -28,7 +28,7 @@ import * as theme from '../../../util/theme'; interface FooterProps extends NavigationInjectedProps, ViewProps { } -export function Footer(props: FooterProps) { +export function Footer (props: FooterProps) { const { api } = useContext(ApiContext)!; const { currentLocation } = useContext(CurrentLocationContext); // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -36,24 +36,24 @@ export function Footer(props: FooterProps) { const isTooFar = isStationTooFar(currentLocation!, api!); - function goToAbout() { + function goToAbout () { track('HOME_SCREEN_ABOUT_CLICK'); navigation.navigate('About'); } - function goToAboutWhySoFar() { + function goToAboutWhySoFar () { track('HOME_SCREEN_ABOUT_WHY_SO_FAR_CLICK'); navigation.navigate('About', { scrollInto: aboutSections.aboutWhyIsTheStationSoFarTitle }); } - function goToDetails() { + function goToDetails () { track('HOME_SCREEN_DETAILS_CLICK'); navigation.navigate('Details'); } - function handleShare() { + function handleShare () { track('HOME_SCREEN_SHARE_CLICK'); // Share doesn't currently support images on Android, so the text version @@ -72,13 +72,13 @@ export function Footer(props: FooterProps) { const renderBigButton = () => { return isTooFar ? ( ) : ( - - ); + + ); }; const renderSmallButtons = () => { @@ -86,16 +86,16 @@ export function Footer(props: FooterProps) { {isTooFar ? ( - ) : ( - - )} - + {i18n.t('home_btn_more_details').toUpperCase()} + + ) : ( + + )} + ); }; diff --git a/App/Screens/ShareScreen/ShareScreen.tsx b/App/Screens/ShareScreen/ShareScreen.tsx index 37e5857b..aaa51e04 100644 --- a/App/Screens/ShareScreen/ShareScreen.tsx +++ b/App/Screens/ShareScreen/ShareScreen.tsx @@ -25,7 +25,7 @@ import * as theme from '../../util/theme'; interface ShareScreenProps extends NavigationInjectedProps { } -export function ShareScreen(props: ShareScreenProps) { +export function ShareScreen (props: ShareScreenProps) { const refViewShot = createRef(); useEffect(() => { diff --git a/App/components/CigaretteBlock/CigaretteBlock.tsx b/App/components/CigaretteBlock/CigaretteBlock.tsx index ce35b2c5..672693d0 100644 --- a/App/components/CigaretteBlock/CigaretteBlock.tsx +++ b/App/components/CigaretteBlock/CigaretteBlock.tsx @@ -76,7 +76,6 @@ export function CigaretteBlock (props: CigaretteBlockProps) { cigarettes }); - console.log('text :', text); const [firstPartText, secondPartText] = text.split('<'); const frequencyText = displayFrequency ? ({i18n.t(`frequency_${frequency}`)}) : null; From f2157b213a9c7da22f5cef31f4deaad8764f69b5 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Thu, 3 Oct 2019 11:07:32 +0100 Subject: [PATCH 13/17] Resolved Merge Conflict --- App/App.tsx | 6 ++-- App/Screens/Home/Footer/Footer.tsx | 32 +++++++++---------- App/Screens/Home/Home.tsx | 4 +-- .../Home/SelectFrequency/SelectFrequency.tsx | 6 ++-- App/Screens/Screens.tsx | 4 +-- .../ShareScreen/ShareImage/ShareImage.tsx | 2 +- App/Screens/ShareScreen/ShareScreen.tsx | 26 +++++++-------- .../CigaretteBlock/CigaretteBlock.tsx | 22 ++++++------- App/stores/frequency.tsx | 4 +-- 9 files changed, 53 insertions(+), 53 deletions(-) diff --git a/App/App.tsx b/App/App.tsx index 30898029..65238869 100644 --- a/App/App.tsx +++ b/App/App.tsx @@ -72,9 +72,9 @@ export function App () { - - - + + + diff --git a/App/Screens/Home/Footer/Footer.tsx b/App/Screens/Home/Footer/Footer.tsx index a9ebda1a..e79d31d7 100644 --- a/App/Screens/Home/Footer/Footer.tsx +++ b/App/Screens/Home/Footer/Footer.tsx @@ -61,10 +61,10 @@ export function Footer (props: FooterProps) { props.navigation.navigate('ShareModal'); } else { Share.share({ - title: i18n.t('home_share_title'), - message: i18n.t('home_share_message', { - cigarettes: api!.shootISmoke.cigarettes - }) + title: i18n.t('home_share_title'), + message: i18n.t('home_share_message', { + cigarettes: parseFloat(api!.shootISmoke.cigarettes).toFixed(2) + }) }); } } @@ -72,11 +72,11 @@ export function Footer (props: FooterProps) { const renderBigButton = () => { return isTooFar ? ( ) : ( ); }; @@ -86,16 +86,16 @@ export function Footer (props: FooterProps) { {isTooFar ? ( - ) : ( - - )} - + {i18n.t('home_btn_more_details').toUpperCase()} + + ) : ( + + )} + ); }; diff --git a/App/Screens/Home/Home.tsx b/App/Screens/Home/Home.tsx index c9e54a2f..ab629039 100644 --- a/App/Screens/Home/Home.tsx +++ b/App/Screens/Home/Home.tsx @@ -49,7 +49,7 @@ export function Home (props: HomeProps) { /> @@ -64,7 +64,7 @@ export function Home (props: HomeProps) { track('HOME_SCREEN_MONTHLY_CLICK'); } - setFrequency(freq); + setFrequency(freq); }} style={styles.withMargin} /> diff --git a/App/Screens/Home/SelectFrequency/SelectFrequency.tsx b/App/Screens/Home/SelectFrequency/SelectFrequency.tsx index d373f0e9..a10731d5 100644 --- a/App/Screens/Home/SelectFrequency/SelectFrequency.tsx +++ b/App/Screens/Home/SelectFrequency/SelectFrequency.tsx @@ -62,7 +62,7 @@ export function SelectFrequency (props: SelectFrequencyProps) { }} style={styles.boxButton} > - {i18n.t('frequency_daily')} + {i18n.t('frequency_daily')} - {i18n.t('frequency_weekly')} + {i18n.t('frequency_weekly')} - {i18n.t('frequency_monthly')} + {i18n.t('frequency_monthly')} ); diff --git a/App/Screens/Screens.tsx b/App/Screens/Screens.tsx index 9b51d9ae..e284d93e 100644 --- a/App/Screens/Screens.tsx +++ b/App/Screens/Screens.tsx @@ -86,10 +86,10 @@ const RootStack = createAppContainer( createStackNavigator( { Main: { - screen: MainStack + screen: MainStack }, ShareModal: { - screen: ShareScreen + screen: ShareScreen } }, { diff --git a/App/Screens/ShareScreen/ShareImage/ShareImage.tsx b/App/Screens/ShareScreen/ShareImage/ShareImage.tsx index 938c7bfe..6feeb6c2 100644 --- a/App/Screens/ShareScreen/ShareImage/ShareImage.tsx +++ b/App/Screens/ShareScreen/ShareImage/ShareImage.tsx @@ -36,7 +36,7 @@ export function ShareImage () { - + https://shootismoke.github.io/ diff --git a/App/Screens/ShareScreen/ShareScreen.tsx b/App/Screens/ShareScreen/ShareScreen.tsx index aaa51e04..96cd990d 100644 --- a/App/Screens/ShareScreen/ShareScreen.tsx +++ b/App/Screens/ShareScreen/ShareScreen.tsx @@ -31,14 +31,14 @@ export function ShareScreen (props: ShareScreenProps) { useEffect(() => { setTimeout(async () => { try { - const uri = await captureRef(refViewShot, { - format: 'png', - quality: 1 - }); + const uri = await captureRef(refViewShot, { + format: 'png', + quality: 1 + }); - await Share.share({ - url: uri - }); + await Share.share({ + url: uri + }); } catch (error) { } @@ -52,12 +52,12 @@ export function ShareScreen (props: ShareScreenProps) { return ( - - - - - - + + + + + + ); diff --git a/App/components/CigaretteBlock/CigaretteBlock.tsx b/App/components/CigaretteBlock/CigaretteBlock.tsx index 672693d0..b4b1b382 100644 --- a/App/components/CigaretteBlock/CigaretteBlock.tsx +++ b/App/components/CigaretteBlock/CigaretteBlock.tsx @@ -66,13 +66,13 @@ export function CigaretteBlock (props: CigaretteBlockProps) { 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'), + 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 === 1 + ? i18n.t('home_common_cigarette').toLowerCase() + : i18n.t('home_common_cigarettes').toLowerCase(), cigarettes }); @@ -82,11 +82,11 @@ export function CigaretteBlock (props: CigaretteBlockProps) { return ( - {firstPartText} - - {secondPartText.split('>')[0]} - - {secondPartText.split('>')[1]} {frequencyText} + {firstPartText} + + {secondPartText.split('>')[0]} + + {secondPartText.split('>')[1]} {frequencyText} ); }; diff --git a/App/stores/frequency.tsx b/App/stores/frequency.tsx index 31613d00..68d4a116 100644 --- a/App/stores/frequency.tsx +++ b/App/stores/frequency.tsx @@ -29,8 +29,8 @@ export function FrequencyContextProvider ({ return ( {children} From 77ed78705636843895ab391fdd3f8d06574290eb Mon Sep 17 00:00:00 2001 From: James Pearson Date: Thu, 3 Oct 2019 16:28:37 +0100 Subject: [PATCH 14/17] =?UTF-8?q?=F0=9F=91=8C=F0=9F=8F=BB=20Renamed=20curr?= =?UTF-8?q?entFrequency=20as=20frequency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/App.tsx | 6 +++--- App/Screens/Home/Home.tsx | 4 ++-- App/Screens/ShareScreen/ShareImage/ShareImage.tsx | 6 +++--- App/stores/frequency.tsx | 15 +++++++++++---- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/App/App.tsx b/App/App.tsx index 65238869..0adef80d 100644 --- a/App/App.tsx +++ b/App/App.tsx @@ -42,7 +42,7 @@ if (Constants.manifest.extra.sentryPublicDsn) { } } -export function App () { +export function App() { const [ready, setReady] = useState(false); useEffect(() => { Promise.all([ @@ -79,6 +79,6 @@ export function App () { ) : ( - - ); + + ); } diff --git a/App/Screens/Home/Home.tsx b/App/Screens/Home/Home.tsx index ab629039..617934af 100644 --- a/App/Screens/Home/Home.tsx +++ b/App/Screens/Home/Home.tsx @@ -30,9 +30,9 @@ import * as theme from '../../util/theme'; interface HomeProps extends NavigationInjectedProps { } -export function Home (props: HomeProps) { +export function Home(props: HomeProps) { const { api } = useContext(ApiContext); - const { currentFrequency: frequency, setFrequency } = useContext(FrequencyContext); + const { frequency, setFrequency } = useContext(FrequencyContext); trackScreen('HOME'); diff --git a/App/Screens/ShareScreen/ShareImage/ShareImage.tsx b/App/Screens/ShareScreen/ShareImage/ShareImage.tsx index 6feeb6c2..a1d4bbb4 100644 --- a/App/Screens/ShareScreen/ShareImage/ShareImage.tsx +++ b/App/Screens/ShareScreen/ShareImage/ShareImage.tsx @@ -25,16 +25,16 @@ import { CigaretteBlock, CurrentLocation } from '../../../components'; import { ApiContext, CurrentLocationContext, FrequencyContext } from '../../../stores'; import * as theme from '../../../util/theme'; -export function ShareImage () { +export function ShareImage() { const { api } = useContext(ApiContext)!; const { currentLocation } = useContext(CurrentLocationContext); - const { currentFrequency } = useContext(FrequencyContext); + const { frequency } = useContext(FrequencyContext); const cigarettesPerDay = api!.shootISmoke.cigarettes; return ( - + diff --git a/App/stores/frequency.tsx b/App/stores/frequency.tsx index 68d4a116..4fc05651 100644 --- a/App/stores/frequency.tsx +++ b/App/stores/frequency.tsx @@ -17,19 +17,26 @@ import React, { createContext, useState } from 'react'; import { Frequency } from '../Screens/Home/SelectFrequency'; -export const FrequencyContext = createContext(); +import { noop } from '../util/noop'; -export function FrequencyContextProvider ({ +interface Context { + frequency: Frequency + setFrequency: (newFrequency: Frequency) => void; +} + +export const FrequencyContext = createContext({ frequency: "daily", setFrequency: noop }); + +export function FrequencyContextProvider({ children }: { children: JSX.Element; }) { - const [currentFrequency, setFrequency] = useState('daily'); + const [frequency, setFrequency] = useState('daily'); return ( From 2bf5212fab43be50e330adcc3250fcbd9c218560 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Thu, 3 Oct 2019 16:30:10 +0100 Subject: [PATCH 15/17] =?UTF-8?q?=F0=9F=91=8C=F0=9F=8F=BB=20Added=20a=20bl?= =?UTF-8?q?ank=20line=20between=20relative=20and=20absolute=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Screens/ShareScreen/ShareScreen.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/App/Screens/ShareScreen/ShareScreen.tsx b/App/Screens/ShareScreen/ShareScreen.tsx index 96cd990d..42881e86 100644 --- a/App/Screens/ShareScreen/ShareScreen.tsx +++ b/App/Screens/ShareScreen/ShareScreen.tsx @@ -18,6 +18,7 @@ import React, { useEffect, createRef } from 'react'; import { Share, StyleSheet, View } from 'react-native'; import { NavigationInjectedProps } from 'react-navigation'; import { captureRef } from 'react-native-view-shot'; + import { ShareImage } from './ShareImage'; import { i18n } from '../../localization'; import { Button } from '../../components'; @@ -25,7 +26,7 @@ import * as theme from '../../util/theme'; interface ShareScreenProps extends NavigationInjectedProps { } -export function ShareScreen (props: ShareScreenProps) { +export function ShareScreen(props: ShareScreenProps) { const refViewShot = createRef(); useEffect(() => { From 71a526ae31bd6be74b1e3804d35db9019146b80f Mon Sep 17 00:00:00 2001 From: James Pearson Date: Thu, 3 Oct 2019 16:31:33 +0100 Subject: [PATCH 16/17] =?UTF-8?q?=F0=9F=91=8C=F0=9F=8F=BB=20Removed=20the?= =?UTF-8?q?=20hard=20coded=20values=20(replaced=20with=20theme=20values)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Screens/ShareScreen/ShareScreen.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/App/Screens/ShareScreen/ShareScreen.tsx b/App/Screens/ShareScreen/ShareScreen.tsx index 42881e86..0eeb31bc 100644 --- a/App/Screens/ShareScreen/ShareScreen.tsx +++ b/App/Screens/ShareScreen/ShareScreen.tsx @@ -74,11 +74,11 @@ const styles = StyleSheet.create({ }, buttonContainer: { - paddingVertical: 20 + paddingVertical: theme.spacing.normal }, button: { - paddingHorizontal: 10 + paddingHorizontal: theme.spacing.mini }, imageContainer: { From 7c01b696a1399f3c7e92f5b64543714269725c16 Mon Sep 17 00:00:00 2001 From: James Pearson Date: Thu, 3 Oct 2019 16:36:23 +0100 Subject: [PATCH 17/17] =?UTF-8?q?=F0=9F=91=8C=F0=9F=8F=BB=20Linting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/App.tsx | 7 ++++--- App/Screens/Home/Home.tsx | 2 +- App/Screens/ShareScreen/ShareImage/ShareImage.tsx | 2 +- App/Screens/ShareScreen/ShareScreen.tsx | 2 +- App/stores/frequency.tsx | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/App/App.tsx b/App/App.tsx index 0adef80d..614260e8 100644 --- a/App/App.tsx +++ b/App/App.tsx @@ -42,10 +42,11 @@ if (Constants.manifest.extra.sentryPublicDsn) { } } -export function App() { +export function App () { const [ready, setReady] = useState(false); useEffect(() => { Promise.all([ + Font.loadAsync({ 'gotham-black': require('../assets/fonts/Gotham-Black.ttf'), 'gotham-book': require('../assets/fonts/Gotham-Book.ttf') @@ -79,6 +80,6 @@ export function App() { ) : ( - - ); + + ); } diff --git a/App/Screens/Home/Home.tsx b/App/Screens/Home/Home.tsx index 617934af..9ea2d3ef 100644 --- a/App/Screens/Home/Home.tsx +++ b/App/Screens/Home/Home.tsx @@ -30,7 +30,7 @@ import * as theme from '../../util/theme'; interface HomeProps extends NavigationInjectedProps { } -export function Home(props: HomeProps) { +export function Home (props: HomeProps) { const { api } = useContext(ApiContext); const { frequency, setFrequency } = useContext(FrequencyContext); diff --git a/App/Screens/ShareScreen/ShareImage/ShareImage.tsx b/App/Screens/ShareScreen/ShareImage/ShareImage.tsx index a1d4bbb4..1556f23f 100644 --- a/App/Screens/ShareScreen/ShareImage/ShareImage.tsx +++ b/App/Screens/ShareScreen/ShareImage/ShareImage.tsx @@ -25,7 +25,7 @@ import { CigaretteBlock, CurrentLocation } from '../../../components'; import { ApiContext, CurrentLocationContext, FrequencyContext } from '../../../stores'; import * as theme from '../../../util/theme'; -export function ShareImage() { +export function ShareImage () { const { api } = useContext(ApiContext)!; const { currentLocation } = useContext(CurrentLocationContext); const { frequency } = useContext(FrequencyContext); diff --git a/App/Screens/ShareScreen/ShareScreen.tsx b/App/Screens/ShareScreen/ShareScreen.tsx index 0eeb31bc..d8d66ea0 100644 --- a/App/Screens/ShareScreen/ShareScreen.tsx +++ b/App/Screens/ShareScreen/ShareScreen.tsx @@ -26,7 +26,7 @@ import * as theme from '../../util/theme'; interface ShareScreenProps extends NavigationInjectedProps { } -export function ShareScreen(props: ShareScreenProps) { +export function ShareScreen (props: ShareScreenProps) { const refViewShot = createRef(); useEffect(() => { diff --git a/App/stores/frequency.tsx b/App/stores/frequency.tsx index 4fc05651..d431fa3e 100644 --- a/App/stores/frequency.tsx +++ b/App/stores/frequency.tsx @@ -24,9 +24,9 @@ interface Context { setFrequency: (newFrequency: Frequency) => void; } -export const FrequencyContext = createContext({ frequency: "daily", setFrequency: noop }); +export const FrequencyContext = createContext({ frequency: 'daily', setFrequency: noop }); -export function FrequencyContextProvider({ +export function FrequencyContextProvider ({ children }: { children: JSX.Element;