Skip to content
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

feat: Replace share text with an image on iOS #242

Merged
merged 17 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added a share screen and share image
  • Loading branch information
James Pearson committed Oct 3, 2019
commit e9dadff18d3724cb31b714083871071ab853f797
64 changes: 64 additions & 0 deletions App/Screens/ShareScreen/ShareImage/ShareImage.tsx
Original file line number Diff line number Diff line change
@@ -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 <http:https://www.gnu.org/licenses/>.

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 (
<View style={styles.container}>
<CigaretteBlock cigarettesPerDay={cigarettesPerDay} frequency={currentFrequency} displayFrequency style={{ paddingHorizontal: 0 }} />
<View>
<CurrentLocation api={api!} currentLocation={currentLocation!} numberOfLines={2} />
</View>

<Text style={styles.urlText}>https://shootismoke.github.io/</Text>

</View>
);
}

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
}
});
17 changes: 17 additions & 0 deletions App/Screens/ShareScreen/ShareImage/index.ts
Original file line number Diff line number Diff line change
@@ -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 <http:https://www.gnu.org/licenses/>.

export * from './ShareImage';
92 changes: 92 additions & 0 deletions App/Screens/ShareScreen/ShareScreen.tsx
Original file line number Diff line number Diff line change
@@ -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 <http:https://www.gnu.org/licenses/>.

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';
jamespearson marked this conversation as resolved.
Show resolved Hide resolved
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 (
<View style={styles.container}>
<View style={styles.imageContainer}>
<View ref={refViewShot} collapsable={false}>
<ShareImage />
</View>
<View style={styles.buttonContainer}>
<Button onPress={handleDismiss} style={styles.button}>{i18n.t('close_button').toUpperCase()}</Button>
</View>
</View>
</View>
);
}

const styles = StyleSheet.create({
container: {
...theme.fullScreen,
...theme.withPadding,
flexGrow: 1,
flexDirection: 'column',
backgroundColor: 'rgba(0,0,0,0.8)'
},

buttonContainer: {
paddingVertical: 20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theme.spacing.normal

},

button: {
paddingHorizontal: 10
},

imageContainer: {
alignItems: 'center',
justifyContent: 'center',
transform: [
{ scale: 0.8 }
]
}
});
17 changes: 17 additions & 0 deletions App/Screens/ShareScreen/index.ts
Original file line number Diff line number Diff line change
@@ -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 <http:https://www.gnu.org/licenses/>.

export * from './ShareScreen';
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==

[email protected]:
[email protected], 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==
Expand Down