Skip to content

Commit

Permalink
feature(mobile): Allow interacting with images in the app. Fixes #352
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Aug 26, 2024
1 parent 7593982 commit 2fb8559
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
4 changes: 2 additions & 2 deletions apps/mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"NSAllowsLocalNetworking": true
}
},
"buildNumber": "8"
"buildNumber": "9"
},
"android": {
"adaptiveIcon": {
Expand All @@ -48,7 +48,7 @@
}
},
"package": "app.hoarder.hoardermobile",
"versionCode": 8
"versionCode": 9
},
"plugins": [
"expo-router",
Expand Down
17 changes: 4 additions & 13 deletions apps/mobile/components/bookmarks/BookmarkAssetImage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Image } from "react-native";
import useAppSettings from "@/lib/settings";
import { useAssetUrl } from "@/lib/hooks";

export default function BookmarkAssetImage({
assetId,
Expand All @@ -8,16 +8,7 @@ export default function BookmarkAssetImage({
assetId: string;
className: string;
}) {
const { settings } = useAppSettings();
return (
<Image
source={{
uri: `${settings.address}/api/assets/${assetId}`,
headers: {
Authorization: `Bearer ${settings.apiKey}`,
},
}}
className={className}
/>
);
const assetSource = useAssetUrl(assetId);

return <Image source={assetSource} className={className} />;
}
20 changes: 17 additions & 3 deletions apps/mobile/components/bookmarks/ViewBookmarkModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useState } from "react";
import { Keyboard, Pressable, Text } from "react-native";
import ImageView from "react-native-image-viewing";
import { useAssetUrl } from "@/lib/hooks";
import {
BottomSheetBackdrop,
BottomSheetModal,
Expand Down Expand Up @@ -122,15 +124,27 @@ function BookmarkTextView({ bookmark }: { bookmark: ZBookmark }) {
}

function BookmarkAssetView({ bookmark }: { bookmark: ZBookmark }) {
const [imageZoom, setImageZoom] = useState(false);
if (bookmark.content.type !== BookmarkTypes.ASSET) {
throw new Error("Wrong content type rendered");
}
const assetSource = useAssetUrl(bookmark.content.assetId);
return (
<BottomSheetView className="flex gap-2">
<BookmarkAssetImage
assetId={bookmark.content.assetId}
className="h-56 min-h-56 w-full object-cover"
<ImageView
visible={imageZoom}
imageIndex={0}
onRequestClose={() => setImageZoom(false)}
doubleTapToZoomEnabled={true}
images={[assetSource]}
/>

<Pressable onPress={() => setImageZoom(true)}>
<BookmarkAssetImage
assetId={bookmark.content.assetId}
className="h-56 min-h-56 w-full object-cover"
/>
</Pressable>
</BottomSheetView>
);
}
Expand Down
13 changes: 13 additions & 0 deletions apps/mobile/lib/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ImageURISource } from "react-native";

import useAppSettings from "./settings";

export function useAssetUrl(assetId: string): ImageURISource {
const { settings } = useAppSettings();
return {
uri: `${settings.address}/api/assets/${assetId}`,
headers: {
Authorization: `Bearer ${settings.apiKey}`,
},
};
}
1 change: 1 addition & 0 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"react-native": "0.73.4",
"react-native-awesome-slider": "^2.5.3",
"react-native-gesture-handler": "~2.14.0",
"react-native-image-viewing": "^0.2.2",
"react-native-markdown-display": "^7.0.2",
"react-native-reanimated": "^3.8.0",
"react-native-safe-area-context": "4.8.2",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2fb8559

Please sign in to comment.