Added save image feature for posts

This commit is contained in:
Mustafa Buyukcelebi 2019-12-09 23:11:45 +03:00
parent 468e08f849
commit c08f2a52b9
5 changed files with 39 additions and 6 deletions

View File

@ -233,6 +233,8 @@ PODS:
- React-cxxreact (= 0.61.2)
- React-jsi (= 0.61.2)
- React-jsinspector (0.61.2)
- react-native-cameraroll (1.3.0):
- React
- react-native-config (0.11.7):
- React
- react-native-fast-image (4.0.14):
@ -333,6 +335,7 @@ DEPENDENCIES:
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- "react-native-cameraroll (from `../node_modules/@react-native-community/cameraroll`)"
- react-native-config (from `../node_modules/react-native-config`)
- react-native-fast-image (from `../node_modules/react-native-fast-image`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
@ -416,6 +419,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsiexecutor"
React-jsinspector:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
react-native-cameraroll:
:path: "../node_modules/@react-native-community/cameraroll"
react-native-config:
:path: "../node_modules/react-native-config"
react-native-fast-image:
@ -494,6 +499,7 @@ SPEC CHECKSUMS:
React-jsi: 32285a21b1b24c36060493ed3057a34677d58d09
React-jsiexecutor: 8909917ff7d8f21a57e443a866fd8d4560e50c65
React-jsinspector: 111d7d342b07a904c400592e02a2b958f1098b60
react-native-cameraroll: 463aff54e37cff27ea76eb792e6f1fa43b876320
react-native-config: 8f6b2b9e017f6a5e92a97353c768e19e67294bb1
react-native-fast-image: 6d50167ad4d68b59640ceead8c2bc4e58d91d8bd
react-native-netinfo: 6bb847e64f45a2d69c6173741111cfd95c669301

View File

@ -25,6 +25,7 @@
"@babel/runtime": "^7.5.5",
"@esteemapp/esteem-render-helpers": "^1.2.2",
"@ptomasroos/react-native-multi-slider": "^1.0.0",
"@react-native-community/cameraroll": "^1.3.0",
"@react-native-community/netinfo": "^4.1.3",
"appcenter": "^2.6.0",
"appcenter-analytics": "^2.6.0",
@ -127,11 +128,6 @@
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"jest": {
"preset": "react-native"
},

View File

@ -1,5 +1,6 @@
import React, { Fragment, useState } from 'react';
import { Dimensions, Linking, Alert, Modal } from 'react-native';
import CameraRoll from '@react-native-community/cameraroll';
import { withNavigation } from 'react-navigation';
import { useIntl, injectIntl } from 'react-intl';
import AutoHeightWebView from 'react-native-autoheight-webview';
@ -126,6 +127,23 @@ const PostBody = ({
}
};
const _saveImage = uri => {
CameraRoll.saveToCameraRoll(uri)
.then(() => {
Alert.alert(
intl.formatMessage({ id: 'alert.success' }),
intl.formatMessage({ id: 'post.image_saved' }),
[{ text: 'OK' }],
{ cancelable: false },
);
})
.catch(error => {
Alert.alert(intl.formatMessage({ id: 'post.image_saved_error' }), error, [{ text: 'OK' }], {
cancelable: false,
});
});
};
const html = body.replace(/<a/g, '<a target="_blank"');
const customStyle = `
* {
@ -219,6 +237,11 @@ const PostBody = ({
imageUrls={postImages}
enableSwipeDown
onCancel={() => setIsImageModalOpen(false)}
onSave={uri => _saveImage(uri)}
menuContext={{
saveToLocal: intl.formatMessage({ id: 'post.save_to_local' }),
cancel: intl.formatMessage({ id: 'alert.cancel' }),
}}
/>
</Modal>
<AutoHeightWebView

View File

@ -277,7 +277,10 @@
"copy_link": "Copy Link",
"reblogged": "reblogged by",
"sponsored": "SPONSORED",
"open_thread": "Open Thread"
"open_thread": "Open Thread",
"save_to_local": "Save to the album",
"image_saved": "Image Saved to Photo Gallery",
"image_saved_error": "Error Saving Image"
},
"drafts": {
"title": "Drafts",

View File

@ -1314,6 +1314,11 @@
resolved "https://registry.yarnpkg.com/@ptomasroos/react-native-multi-slider/-/react-native-multi-slider-1.0.0.tgz#a4ea27b1320b93a1db9f696c24789695df6c9f30"
integrity sha512-NpX22rQLArg9widwMzGf7XsInTDf6mfY/D1XaDVjglNkVphj3NSN37+nF6MofArCxC++1P+jHv0SGWbmJQwy4g==
"@react-native-community/cameraroll@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@react-native-community/cameraroll/-/cameraroll-1.3.0.tgz#a340334440f4d08280da839130ef51c931b07483"
integrity sha512-QJl9N34euvGU7s/Gn6jhsqi70O4SmxFxuy+yBnW7ehE8qtPYO91gyLLrtiWdTfYvuVCUNvX/G0LKJQLm8SojAA==
"@react-native-community/cli-platform-android@^3.0.0-alpha.1", "@react-native-community/cli-platform-android@^3.0.0-alpha.2":
version "3.0.0-alpha.2"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-platform-android/-/cli-platform-android-3.0.0-alpha.2.tgz#63cb00060c58a87d04b46229ef7140e056551dfa"