Skip to content

Commit

Permalink
replace fast-image with patched version (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkasdorf committed Jul 16, 2023
1 parent fd85bf7 commit 5ba442e
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 111 deletions.
8 changes: 4 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ PODS:
- React-Core
- RNDeviceInfo (10.6.0):
- React-Core
- RNFastImage (8.6.3):
- RNFastImage (8.6.4):
- React-Core
- SDWebImage (~> 5.11.1)
- SDWebImageWebPCoder (~> 0.8.4)
Expand Down Expand Up @@ -740,7 +740,7 @@ DEPENDENCIES:
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- "RNCClipboard (from `../node_modules/@react-native-community/clipboard`)"
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
- RNFastImage (from `../node_modules/react-native-fast-image`)
- "RNFastImage (from `../node_modules/@gkasdorf/react-native-fast-image`)"
- "RNFlashList (from `../node_modules/@shopify/flash-list`)"
- RNFS (from `../node_modules/react-native-fs`)
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
Expand Down Expand Up @@ -927,7 +927,7 @@ EXTERNAL SOURCES:
RNDeviceInfo:
:path: "../node_modules/react-native-device-info"
RNFastImage:
:path: "../node_modules/react-native-fast-image"
:path: "../node_modules/@gkasdorf/react-native-fast-image"
RNFlashList:
:path: "../node_modules/@shopify/flash-list"
RNFS:
Expand Down Expand Up @@ -1041,7 +1041,7 @@ SPEC CHECKSUMS:
RNCAsyncStorage: ddc4ee162bfd41b0d2c68bf2d95acd81dd7f1f93
RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495
RNDeviceInfo: 475a4c447168d0ad4c807e48ef5e0963a0f4eb1b
RNFastImage: 5c9c9fed9c076e521b3f509fe79e790418a544e8
RNFastImage: e583061a26ed90fbab49d526d2ec2d56cfffa465
RNFlashList: ade81b4e928ebd585dd492014d40fb8d0e848aab
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
RNGestureHandler: dec4645026e7401a0899f2846d864403478ff6a5
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
"buildAndSubmit": "rm -rf build.ipa && eas build -p ios --profile production --output build.ipa --local --non-interactive && eas submit -p ios --path build.ipa --non-interactive",
"buildAndSubmitAll": "yarn run buildProd && yarn run buildProdAnd && eas submit -p ios --path build.iap && eas submit -p android build.aab",
"generate-license": "license-report --only=prod,dev,peer --fields=name --fields=licenseType --fields=link --fields=installedVersion --fields=author --output=html > assets/license.html",
"release": "appcenter codepush release-react --app gavink/Memmy -t 0.3",
"release-staging": "appcenter codepush release-react --app gavink/Memmy -t 10.10.11",
"promote": "appcenter codepush promote -d Production -s Staging --app gavink/memmy"
"release": "appcenter codepush release-react --app gavink/Memmy -t 0.3",
"release-staging": "appcenter codepush release-react --app gavink/Memmy -t 10.10.11",
"promote": "appcenter codepush promote -d Production -s Staging --app gavink/memmy"
},
"dependencies": {
"@expo/react-native-action-sheet": "^4.0.1",
"@expo/vector-icons": "^13.0.0",
"@gkasdorf/react-native-fast-image": "^8.6.4",
"@gkasdorf/react-native-tableview-simple": "^4.4.2",
"@pnthach95/react-native-root-view-background": "^1.3.0",
"@react-native-async-storage/async-storage": "^1.18.2",
Expand Down Expand Up @@ -80,7 +81,6 @@
"react-native-device-info": "^10.6.0",
"react-native-dialog": "^9.3.0",
"react-native-elements": "^3.4.3",
"react-native-fast-image": "^8.6.3",
"react-native-flipper": "^0.203.0",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "~2.12.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/AvatarUsername.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { HStack, Text, useTheme, VStack } from "native-base";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { IconUser } from "tabler-icons-react-native";
import { Person } from "lemmy-js-client";
import Link from "./Buttons/Link";
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/Buttons/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
// eslint-disable-next-line import/no-extraneous-dependencies
import { useNavigation } from "@react-navigation/native";
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { IconUnlink } from "tabler-icons-react-native";
import { openLink } from "../../../helpers/LinkHelper";
import { truncateLink } from "../../../helpers/TextHelper";
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/CommunityLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Community } from "lemmy-js-client";
import { HStack, Text, useTheme } from "native-base";
import React from "react";
import { IconPlanet } from "tabler-icons-react-native";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { getBaseUrl } from "../../helpers/LinkHelper";
import Link from "./Buttons/Link";

Expand Down
26 changes: 4 additions & 22 deletions src/components/common/ImageViewer/ImageViewFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,34 @@
import React, { useState } from "react";
import React from "react";
import { HStack, useTheme, View } from "native-base";
// eslint-disable-next-line import/no-extraneous-dependencies
import { IconDeviceFloppy, IconShare2 } from "tabler-icons-react-native";
import DialogContainer from "react-native-dialog/lib/Container";
import DialogDescription from "react-native-dialog/lib/Description";
import { useTranslation } from "react-i18next";
import IconButtonWithText from "../IconButtonWithText";
import { onGenericHapticFeedback } from "../../../helpers/HapticFeedbackHelpers";
import downloadAndSaveImage from "../../../helpers/ImageHelper";
import { shareLink } from "../../../helpers/ShareHelper";
import { saveImage } from "../../../helpers/ImageHelper";

interface ImageViewFooterProps {
source: string;
visible: boolean;
}

function ImageViewFooter({ source, visible }: ImageViewFooterProps) {
const [downloading, setDownloading] = useState(false);

const { t } = useTranslation();
const theme = useTheme();

const onSave = async () => {
onGenericHapticFeedback();
setDownloading(true);

try {
await downloadAndSaveImage(source);
setDownloading(false);
} catch (e) {
setDownloading(false);
}
await saveImage(source);
};

const onShare = async () => {
setDownloading(true);

try {
await shareLink({
link: source,
isImage: true,
callback: () => setDownloading(false),
});
} catch (e) {
setDownloading(false);
/* Empty */
}
};

Expand Down Expand Up @@ -77,9 +62,6 @@ function ImageViewFooter({ source, visible }: ImageViewFooterProps) {
icon={<IconShare2 size={38} color={theme.colors.app.textSecondary} />}
/>
</HStack>
<DialogContainer visible={downloading}>
<DialogDescription>{t("imageView.dialogDesc")}</DialogDescription>
</DialogContainer>
</View>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/ImageViewer/ImageViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Pressable,
StyleSheet,
} from "react-native";
import FastImage, { OnLoadEvent } from "react-native-fast-image";
import FastImage, { OnLoadEvent } from "@gkasdorf/react-native-fast-image";
import Animated, {
runOnJS,
runOnUI,
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/MemoizedFastImage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef, useState } from "react";
import FastImage, { ResizeMode } from "react-native-fast-image";
import FastImage, { ResizeMode } from "@gkasdorf/react-native-fast-image";
import { Icon, Text, useTheme, View, VStack } from "native-base";
import { BlurView } from "expo-blur";
import { Ionicons } from "@expo/vector-icons";
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/Search/GenericSearchResult.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Box, HStack, Pressable, Text, useTheme, VStack } from "native-base";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { IconUser } from "tabler-icons-react-native";
import { StyleSheet } from "react-native";

Expand Down
2 changes: 1 addition & 1 deletion src/components/common/Search/SearchCommunityItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import { CommunityView } from "lemmy-js-client";
import { useTheme } from "native-base";
import React from "react";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { IconPlanet } from "tabler-icons-react-native";
import { getCommunityFullName } from "../../../helpers/LemmyHelpers";
import { getBaseUrl } from "../../../helpers/LinkHelper";
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/Search/SearchUserItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { PersonView } from "lemmy-js-client";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { useNavigation } from "@react-navigation/native";
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import { IconUser } from "tabler-icons-react-native";
Expand Down
2 changes: 1 addition & 1 deletion src/components/screens/Feed/CommunityAboutScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { ScrollView, Text, useTheme, VStack } from "native-base";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { IconPlanet } from "tabler-icons-react-native";
import { useTranslation } from "react-i18next";
import RenderMarkdown from "../../common/Markdown/RenderMarkdown";
Expand Down
2 changes: 1 addition & 1 deletion src/components/screens/Feed/CommunityFeedScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import { HStack, Text, useTheme, VStack } from "native-base";
import React, { useEffect } from "react";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import {
IconEye,
IconHeart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Box, Icon, useTheme, View, VStack } from "native-base";
import { PostView } from "lemmy-js-client";
import { BlurView } from "expo-blur";
import { Ionicons } from "@expo/vector-icons";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { IconLink, IconMessages } from "tabler-icons-react-native";
import { ExtensionType, LinkInfo } from "../../../../../helpers/LinkHelper";
import { useAppSelector } from "../../../../../../store";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StyleSheet } from "react-native";
// eslint-disable-next-line import/no-extraneous-dependencies
import { useNavigation } from "@react-navigation/native";
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import useFeedItem from "../../../../../hooks/feeds/useFeedItem";
import { useAppDispatch } from "../../../../../../store";
import { setResponseTo } from "../../../../../slices/comments/newCommentSlice";
Expand Down
2 changes: 1 addition & 1 deletion src/components/screens/HubDiscovery/InstanceScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useTheme,
VStack,
} from "native-base";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import {
IconArrowDown,
IconCheck,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { GetSiteResponse } from "lemmy-js-client";
import { HStack, Pressable, Text, useTheme, View, VStack } from "native-base";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { StyleSheet } from "react-native";
import {
IconChevronRight,
Expand Down
2 changes: 1 addition & 1 deletion src/components/screens/Settings/SettingsIndexScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NativeStackNavigationProp } from "@react-navigation/native-stack";
import { Box, HStack, ScrollView, Text, useTheme } from "native-base";
import React, { useMemo } from "react";
import { Alert, StyleSheet } from "react-native";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import {
IconAt,
IconBrush,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { CommunityView } from "lemmy-js-client";
import { HStack, Pressable, Text, useTheme, VStack } from "native-base";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { StyleSheet } from "react-native";
import {
IconChevronRight,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Box, HStack, Text, useTheme, View, VStack } from "native-base";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import {
IconCake,
IconCalendarStar,
Expand Down
51 changes: 10 additions & 41 deletions src/helpers/ImageHelper.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,21 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import * as FileSystem from "expo-file-system";
// eslint-disable-next-line import/no-extraneous-dependencies
import * as Permissions from "expo-permissions";
// eslint-disable-next-line import/no-extraneous-dependencies
import * as MediaLibrary from "expo-media-library";
// eslint-disable-next-line import/no-extraneous-dependencies
import * as ImagePicker from "expo-image-picker";
import { PostView } from "lemmy-js-client";
import FastImage from "react-native-fast-image";
import FastImage from "@gkasdorf/react-native-fast-image";
import { Alert, Dimensions } from "react-native";
import i18n from "../plugins/i18n/i18n";
import { writeToLog } from "./LogHelper";
import { ExtensionType, getLinkInfo } from "./LinkHelper";

export const downloadImage = async (src: string): Promise<string | boolean> => {
const fileName = src.split("/").pop();
const filePath = FileSystem.documentDirectory + fileName;

try {
const res = await FileSystem.downloadAsync(src, filePath);
return res.uri;
} catch (e) {
writeToLog("Error downloading image.");
writeToLog(e.toString());
return false;
}
};

export const deleteImage = async (uri: string): Promise<boolean> => {
try {
await FileSystem.deleteAsync(uri);
return true;
} catch (e) {
writeToLog("Error deleting file.");
writeToLog(e.toString());
return false;
}
};

const downloadAndSaveImage = async (src: string): Promise<boolean> => {
export const saveImage = async (src: string): Promise<boolean> => {
// Get the status of permissions
const { status } = await Permissions.askAsync(Permissions.MEDIA_LIBRARY);

// If we don't have permission, tell the user
if (status !== "granted") {
Alert.alert(
i18n.t("alert.title.permissionsError"),
Expand All @@ -49,22 +24,18 @@ const downloadAndSaveImage = async (src: string): Promise<boolean> => {
return false;
}

const uri = await downloadImage(src);

if (!uri) return false;
// Get the URI of the cached image
const uri = await FastImage.getCachePath({ uri: src });

await saveImage(uri as string);
return true;
};

const saveImage = async (filePath: string) => {
// Save the image
try {
await MediaLibrary.createAssetAsync(filePath);
deleteImage(filePath).then();
await MediaLibrary.createAssetAsync(uri);
} catch (e) {
writeToLog("Error saving image.");
writeToLog(e.toString());
}

return true;
};

export const selectImage = async (): Promise<string> => {
Expand Down Expand Up @@ -131,5 +102,3 @@ export const getRatio = (
imageWidth,
};
};

export default downloadAndSaveImage;
15 changes: 2 additions & 13 deletions src/helpers/ShareHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Share, { ShareOptions } from "react-native-share";
import { Alert } from "react-native";
import { deleteImage, downloadImage } from "./ImageHelper";
import FastImage from "@gkasdorf/react-native-fast-image";
import { onGenericHapticFeedback } from "./HapticFeedbackHelpers";

interface ShareLinkOptions {
Expand All @@ -24,17 +23,8 @@ export const shareLink = async ({
title,
};

let uri: string;

if (isImage) {
const res = await downloadImage(link);

if (!res) {
Alert.alert("Failed to save image.");
return;
}

uri = res as string;
const uri = await FastImage.getCachePath({ uri: link });

options = {
filename: uri.split("/").pop(),
Expand All @@ -55,7 +45,6 @@ export const shareLink = async ({

const after = () => {
if (callback) callback();
if (isImage) deleteImage(uri);
};

try {
Expand Down
Loading

0 comments on commit 5ba442e

Please sign in to comment.