fix(settings): lazy-load clipboard so the Account screen opens without a native rebuild

This commit is contained in:
Gauvain
2026-06-04 00:16:40 +02:00
parent f6333b49d3
commit 583fac6938
2 changed files with 18 additions and 8 deletions

View File

@@ -1,5 +1,4 @@
import * as Application from "expo-application";
import { setStringAsync } from "expo-clipboard";
import { t } from "i18next";
import { useAtom } from "jotai";
import { useState } from "react";
@@ -18,6 +17,21 @@ export default function AccountPage() {
const token = api?.accessToken ?? "";
const masked = token ? `•••• •••• •••• ${token.slice(-4)}` : "";
const copyToken = async () => {
if (!token) return;
try {
// Lazy import: expo-clipboard is a native module. Importing it at module
// top crashes the screen on a dev client built before it was added; the
// dynamic import defers loading until the user taps copy.
const Clipboard = await import("expo-clipboard");
await Clipboard.setStringAsync(token);
success();
Alert.alert(t("home.settings.account.copied"));
} catch {
Alert.alert(t("home.settings.account.copy_unavailable"));
}
};
return (
<ScrollView contentContainerStyle={{ padding: 16 }}>
<ListGroup title={t("home.settings.user_info.user_info_title")}>
@@ -37,12 +51,7 @@ export default function AccountPage() {
<ListItem
title={t("home.settings.account.copy_token")}
textColor='blue'
onPress={async () => {
if (!token) return;
await setStringAsync(token);
success();
Alert.alert(t("home.settings.account.copied"));
}}
onPress={copyToken}
/>
<ListItem
title={t("home.settings.user_info.app_version")}