ウィジェットの核となる仕組みが完成したので一旦これで仕組みとしては完成

This commit is contained in:
harukin-expo-dev-env 2024-03-07 12:56:19 +00:00
parent 2bbd9ecad8
commit 1f9c3064bf
2 changed files with 97 additions and 17 deletions

View File

@ -1,7 +1,7 @@
import React from "react";
import { FlexWidget, TextWidget } from "react-native-android-widget";
export function HelloWidget() {
export function HelloWidget({ time, delayString }) {
return (
<FlexWidget
style={{
@ -12,15 +12,77 @@ export function HelloWidget() {
backgroundColor: "#ffffff",
borderRadius: 16,
}}
clickAction="WIDGET_CLICK"
>
<TextWidget
text="Hello"
<FlexWidget
style={{
fontSize: 32,
fontFamily: "Inter",
color: "#000000",
justifyContent: "center",
alignItems: "center",
backgroundColor: "#0099CC",
width: "match_parent",
flexDirection: "row",
padding: 10,
}}
/>
>
<TextWidget
text={"列車遅延速報EX"}
style={{
fontSize: 30,
fontWeight: "bold",
fontFamily: "Inter",
color: "#fff",
}}
/>
<FlexWidget style={{ flex: 1 }} />
<TextWidget
text={time}
style={{
fontSize: 32,
fontFamily: "Inter",
color: "#fff",
}}
/>
</FlexWidget>
<FlexWidget
style={{ flex: 1, backgroundColor: "#fff", width: "match_parent" }}
>
{delayString ? (
delayString.map((d) => {
let data = d.split(" ");
return (
<FlexWidget
style={{
flexDirection: "row",
width: "match_parent",
backgroundColor: "#ffffff",
}}
key={data[1]}
>
<TextWidget
style={{ flex: 15, fontSize: 20, color: "#000000" }}
text={data[0].replace("\n", "")}
/>
<TextWidget
style={{ flex: 5, fontSize: 20, color: "#000000" }}
text={data[1]}
/>
<TextWidget
style={{ flex: 6, fontSize: 20, color: "#000000" }}
text={data[3]}
/>
</FlexWidget>
);
})
) : (
<TextWidget
style={{
color: "#000000",
}}
>
現在5分以上の遅れはありません
</TextWidget>
)}
</FlexWidget>
</FlexWidget>
);
}

View File

@ -1,34 +1,52 @@
import React from "react";
import { HelloWidget } from "./HelloWidget";
import dayjs from "dayjs";
import { ToastAndroid } from "react-native";
const nameToWidget = {
// Hello will be the **name** with which we will reference our widget.
Hello: HelloWidget,
JR_shikoku_train_info: HelloWidget,
};
export async function widgetTaskHandler(props) {
const widgetInfo = props.widgetInfo;
const Widget = nameToWidget[widgetInfo.widgetName];
const time = dayjs().format("HH:mm");
ToastAndroid.show(
`Widget Action: ${props.widgetAction} ${time}`,
ToastAndroid.SHORT
);
const delayString = await fetch(
"https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec"
)
.then((response) => response.text())
.then((data) => {
if (data !== "") {
return data.split("^");
}
return null;
});
ToastAndroid.show(`${delayString}`, ToastAndroid.SHORT);
switch (props.widgetAction) {
case "WIDGET_ADDED":
props.renderWidget(<Widget />);
break;
case "WIDGET_UPDATE":
// Not needed for now
break;
// Not needed for now
case "WIDGET_CLICK":
// Not needed for now
case "WIDGET_RESIZED":
// Not needed for now
props.renderWidget(<Widget time={time} delayString={delayString} />);
break;
break;
break;
case "WIDGET_DELETED":
// Not needed for now
break;
case "WIDGET_CLICK":
// Not needed for now
break;
default: