mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-25 21:53:04 +03:00
Fixed android save image issue
This commit is contained in:
parent
11eaea86c6
commit
b454609eba
@ -4,6 +4,9 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="com.android.vending.BILLING" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
|
||||
|
||||
|
@ -24,10 +24,10 @@
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"@esteemapp/react-native-autocomplete-input": "^4.2.1",
|
||||
"@esteemapp/react-native-multi-slider": "^1.1.0",
|
||||
"@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",
|
||||
@ -88,6 +88,7 @@
|
||||
"redux-persist": "^6.0.0",
|
||||
"redux-promise": "^0.6.0",
|
||||
"redux-thunk": "^2.3.0",
|
||||
"rn-fetch-blob": "^0.11.2",
|
||||
"rn-placeholder": "^1.3.2",
|
||||
"speakingurl": "^14.0.1",
|
||||
"stacktrace-parser": "0.1.4",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { Fragment, useState } from 'react';
|
||||
import { Dimensions, Linking, Alert, Modal } from 'react-native';
|
||||
import { Dimensions, Linking, Alert, Modal, PermissionsAndroid, Platform } from 'react-native';
|
||||
import CameraRoll from '@react-native-community/cameraroll';
|
||||
import { withNavigation } from 'react-navigation';
|
||||
import { useIntl, injectIntl } from 'react-intl';
|
||||
@ -7,6 +7,7 @@ import AutoHeightWebView from 'react-native-autoheight-webview';
|
||||
import EStyleSheet from 'react-native-extended-stylesheet';
|
||||
import get from 'lodash/get';
|
||||
import ImageViewer from 'react-native-image-zoom-viewer';
|
||||
import RNFetchBlob from 'rn-fetch-blob';
|
||||
|
||||
import script from './config';
|
||||
import { PostPlaceHolder, CommentPlaceHolder } from '../../../basicUIElements';
|
||||
@ -127,23 +128,73 @@ 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 },
|
||||
);
|
||||
const checkAndroidPermission = async () => {
|
||||
try {
|
||||
const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE;
|
||||
await PermissionsAndroid.request(permission);
|
||||
Promise.resolve();
|
||||
} catch (error) {
|
||||
Promise.reject(error);
|
||||
}
|
||||
};
|
||||
|
||||
const _downloadImage = async uri => {
|
||||
return RNFetchBlob.config({
|
||||
fileCache: true,
|
||||
appendExt: 'jpg',
|
||||
})
|
||||
.fetch('GET', uri)
|
||||
.then(res => {
|
||||
let status = res.info().status;
|
||||
|
||||
if (status == 200) {
|
||||
return res.path();
|
||||
} else {
|
||||
Promise.reject();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
Alert.alert(intl.formatMessage({ id: 'post.image_saved_error' }), error, [{ text: 'OK' }], {
|
||||
cancelable: false,
|
||||
});
|
||||
.catch(errorMessage => {
|
||||
Promise.reject(errorMessage);
|
||||
});
|
||||
};
|
||||
|
||||
const _saveImage = async uri => {
|
||||
try {
|
||||
if (Platform.OS === 'android') {
|
||||
await checkAndroidPermission();
|
||||
uri = `file://${await _downloadImage(uri)}`;
|
||||
}
|
||||
CameraRoll.saveToCameraRoll(uri)
|
||||
.then(res => {
|
||||
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.message,
|
||||
[{ text: 'OK' }],
|
||||
{
|
||||
cancelable: false,
|
||||
},
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
Alert.alert(
|
||||
intl.formatMessage({ id: 'post.image_saved_error' }),
|
||||
error.message,
|
||||
[{ text: 'OK' }],
|
||||
{
|
||||
cancelable: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const html = body.replace(/<a/g, '<a target="_blank"');
|
||||
const customStyle = `
|
||||
* {
|
||||
|
35
yarn.lock
35
yarn.lock
@ -1359,6 +1359,16 @@
|
||||
js-yaml "^3.13.1"
|
||||
xcode "^2.0.0"
|
||||
|
||||
"@react-native-community/cli-tools@^2.8.3":
|
||||
version "2.8.3"
|
||||
resolved "https://registry.yarnpkg.com/@react-native-community/cli-tools/-/cli-tools-2.8.3.tgz#0e2249f48cf4603fb8d740a9f0715c31ac131ceb"
|
||||
integrity sha512-N5Pz+pR+GFq3JApjd0SW4jp9KC7kbKsMH65QLRh30JNsxdPvNkYox6/ZZdkvdXaI5ev3EckR7eqlcwi5gpVTYQ==
|
||||
dependencies:
|
||||
chalk "^2.4.2"
|
||||
lodash "^4.17.5"
|
||||
mime "^2.4.1"
|
||||
node-fetch "^2.5.0"
|
||||
|
||||
"@react-native-community/cli-tools@^3.0.0":
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@react-native-community/cli-tools/-/cli-tools-3.0.0.tgz#fe48b80822ed7e49b8af051f9fe41e22a2a710b1"
|
||||
@ -2234,6 +2244,11 @@ balanced-match@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
|
||||
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
|
||||
|
||||
base-64@0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb"
|
||||
integrity sha1-eAqZyE59YAJgNhURxId2E78k9rs=
|
||||
|
||||
base-x@^3.0.2:
|
||||
version "3.0.7"
|
||||
resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.7.tgz#1c5a7fafe8f66b4114063e8da102799d4e7c408f"
|
||||
@ -4364,6 +4379,18 @@ glob@5.0.15, glob@^5.0.15:
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
glob@7.0.6:
|
||||
version "7.0.6"
|
||||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.6.tgz#211bafaf49e525b8cd93260d14ab136152b3f57a"
|
||||
integrity sha1-IRuvr0nlJbjNkyYNFKsTYVKz9Xo=
|
||||
dependencies:
|
||||
fs.realpath "^1.0.0"
|
||||
inflight "^1.0.4"
|
||||
inherits "2"
|
||||
minimatch "^3.0.2"
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
glob@^7.1.1, glob@^7.1.2, glob@^7.1.3:
|
||||
version "7.1.4"
|
||||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
|
||||
@ -8299,6 +8326,14 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
|
||||
hash-base "^3.0.0"
|
||||
inherits "^2.0.1"
|
||||
|
||||
rn-fetch-blob@^0.11.2:
|
||||
version "0.11.2"
|
||||
resolved "https://registry.yarnpkg.com/rn-fetch-blob/-/rn-fetch-blob-0.11.2.tgz#bdc483bf1b0c3810d457983494a11fbada446679"
|
||||
integrity sha512-oKszdNtA7vZ56d0Rfr+RDEUexwlZxu/HOqwULa36PRHhQsTO5ia7uKk+va3WzuwYxzhF9e0bY8n3k+GC6Df14A==
|
||||
dependencies:
|
||||
base-64 "0.1.0"
|
||||
glob "7.0.6"
|
||||
|
||||
rn-placeholder@^1.3.2:
|
||||
version "1.3.3"
|
||||
resolved "https://registry.yarnpkg.com/rn-placeholder/-/rn-placeholder-1.3.3.tgz#205067c1a2f08bcdfe09971b0c48b46afcd9c952"
|
||||
|
Loading…
Reference in New Issue
Block a user