import React from "react";
import { FlexWidget, TextWidget } from "react-native-android-widget";
import { getDelayData } from "./TraInfoEXWidget";
import { getInfoString } from "./InfoWidget";
import { getFelicaQuickAccessData } from "./FelicaQuickAccessWidget";
import { isAvailable as isNfcAvailable } from "../../modules/expo-felica-reader/src";
import { WidgetColors, widgetLightColors } from "./widget-theme";
export async function getShortcutData() {
const hasNfc = isNfcAvailable();
const [delayResult, infoResult, felicaResult] = await Promise.allSettled([
getDelayData(),
getInfoString(),
hasNfc ? getFelicaQuickAccessData() : Promise.resolve({ amountText: "" }),
]);
const delayCount =
delayResult.status === "fulfilled" && delayResult.value.delayString
? delayResult.value.delayString.length
: 0;
const hasInfo =
infoResult.status === "fulfilled" &&
infoResult.value.text != null &&
infoResult.value.text.length > 0;
const amountText =
felicaResult.status === "fulfilled"
? felicaResult.value.amountText
: "未読取";
return { delayCount, hasInfo, amountText, hasNfc };
}
export type ShortcutWidgetProps = {
delayCount: number;
hasInfo: boolean;
amountText: string;
hasNfc: boolean;
widgetWidth?: number;
widgetHeight?: number;
colors?: WidgetColors;
};
const SPACING = 2;
/** 汎用グリッドタイル */
function GridTile({
icon,
label,
sub,
subColor,
badgeText,
badgeColor,
bottomTrailing,
uri,
colors,
}: {
icon: string;
label: string;
sub?: string;
subColor?: string;
badgeText?: string;
badgeColor?: string;
bottomTrailing?: string;
uri: string;
colors: WidgetColors;
}) {
return (
{badgeText !== undefined && badgeColor !== undefined ? (
) : (
)}
{sub !== undefined ? (
) : (
)}
{bottomTrailing !== undefined && (
)}
);
}
/** アイコンだけのコンパクトタイル */
function IconTile({ icon, uri, colors }: { icon: string; uri: string; colors: WidgetColors }) {
return (
);
}
export function ShortcutWidget({ delayCount, hasInfo, amountText, hasNfc, widgetWidth, widgetHeight, colors = widgetLightColors }: ShortcutWidgetProps) {
const compact = (widgetWidth ?? 300) < 200 || (widgetHeight ?? 300) < 150;
if (compact) {
return (
);
}
return (
{/* Row 1: 走行位置 | 遅延速報EX */}
0 ? `${delayCount}件` : "なし"}
badgeColor={delayCount > 0 ? "#E53935" : "#9E9E9E"}
colors={colors}
/>
{/* Row 2: 運行情報 | ICカード */}
{hasNfc && (
)}
{hasNfc && (
)}
{/* Row 3: トップメニュー(全幅) */}
);
}