From c08f2a52b950613b04922d2cfc5a7ad582202638 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Mon, 9 Dec 2019 23:11:45 +0300 Subject: [PATCH] Added save image feature for posts --- ios/Podfile.lock | 6 +++++ package.json | 6 +---- .../postElements/body/view/postBodyView.js | 23 +++++++++++++++++++ src/config/locales/en-US.json | 5 +++- yarn.lock | 5 ++++ 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index f7c31df2a..021c5059a 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -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 diff --git a/package.json b/package.json index 301621938..a604a832d 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/components/postElements/body/view/postBodyView.js b/src/components/postElements/body/view/postBodyView.js index 9f9b51646..8001a55d8 100644 --- a/src/components/postElements/body/view/postBodyView.js +++ b/src/components/postElements/body/view/postBodyView.js @@ -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(/ setIsImageModalOpen(false)} + onSave={uri => _saveImage(uri)} + menuContext={{ + saveToLocal: intl.formatMessage({ id: 'post.save_to_local' }), + cancel: intl.formatMessage({ id: 'alert.cancel' }), + }} />