Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/expo-glyphnet/bun.lock

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

2 changes: 2 additions & 0 deletions apps/expo-glyphnet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"expo-font": "~56.0.5",
"expo-glass-effect": "~56.0.4",
"expo-image": "~56.0.9",
"expo-image-manipulator": "~56.0.15",
"expo-linking": "~56.0.12",
"expo-media-library": "~56.0.6",
"expo-navigation-bar": "~56.0.3",
"expo-print": "~56.0.3",
"expo-router": "~56.2.7",
Expand Down
46 changes: 42 additions & 4 deletions apps/expo-glyphnet/src/features/encode/EncodePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import * as FileSystem from "expo-file-system";
import * as MediaLibrary from "expo-media-library";
import * as Print from "expo-print";
import { useMemo, useState } from "react";
import { SvgXml } from "react-native-svg";

import { scannerAdapter } from "@/adapters/scanner";
import { Pressable, Text, TextInput, View } from "@/tw";

function getWritableBaseDir(): string | null {
const fsAny = FileSystem as unknown as {
documentDirectory?: string | null;
cacheDirectory?: string | null;
Paths?: {
document?: { uri?: string };
cache?: { uri?: string };
};
};
return (
fsAny.documentDirectory ??
fsAny.cacheDirectory ??
fsAny.Paths?.document?.uri ??
fsAny.Paths?.cache?.uri ??
null
);
}

export function EncodePanel() {
const [payload, setPayload] = useState("hello glyphnet");
const [svgPreview, setSvgPreview] = useState("");
Expand Down Expand Up @@ -44,7 +63,7 @@ export function EncodePanel() {
return;
}
try {
const dir = FileSystem.documentDirectory ?? FileSystem.cacheDirectory;
const dir = getWritableBaseDir();
if (!dir) {
setActionMessage("Unable to access local storage.");
return;
Expand All @@ -53,6 +72,17 @@ export function EncodePanel() {
await FileSystem.writeAsStringAsync(uri, svgPreview, {
encoding: FileSystem.EncodingType.UTF8,
});
let savedToLibrary = false;
try {
const perm = await MediaLibrary.requestPermissionsAsync();
if (perm.granted) {
await MediaLibrary.saveToLibraryAsync(uri);
savedToLibrary = true;
}
} catch {
// Ignore and fall back to share/export.
}

// Load sharing lazily so Expo Go / unsupported runtimes never fail at import time.
try {
const Sharing = await import("expo-sharing");
Expand All @@ -61,12 +91,20 @@ export function EncodePanel() {
mimeType: "image/svg+xml",
dialogTitle: "Share GlyphNet SVG",
});
setActionMessage("SVG saved and share sheet opened.");
setActionMessage(
savedToLibrary
? "SVG saved to library and share sheet opened."
: "SVG exported and share sheet opened.",
);
} else {
setActionMessage(`SVG saved: ${uri}`);
setActionMessage(
savedToLibrary ? "SVG saved to library." : `SVG saved in app storage: ${uri}`,
);
}
} catch {
setActionMessage(`SVG saved: ${uri}`);
setActionMessage(
savedToLibrary ? "SVG saved to library." : `SVG saved in app storage: ${uri}`,
);
}
} catch (error) {
setActionMessage(
Expand Down
Loading
Loading