ウィジェットの核となる仕組みが完成したので一旦これで仕組みとしては完成
This commit is contained in:
parent
2bbd9ecad8
commit
1f9c3064bf
@ -1,7 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { FlexWidget, TextWidget } from "react-native-android-widget";
|
import { FlexWidget, TextWidget } from "react-native-android-widget";
|
||||||
|
|
||||||
export function HelloWidget() {
|
export function HelloWidget({ time, delayString }) {
|
||||||
return (
|
return (
|
||||||
<FlexWidget
|
<FlexWidget
|
||||||
style={{
|
style={{
|
||||||
@ -12,15 +12,77 @@ export function HelloWidget() {
|
|||||||
backgroundColor: "#ffffff",
|
backgroundColor: "#ffffff",
|
||||||
borderRadius: 16,
|
borderRadius: 16,
|
||||||
}}
|
}}
|
||||||
|
clickAction="WIDGET_CLICK"
|
||||||
>
|
>
|
||||||
<TextWidget
|
<FlexWidget
|
||||||
text="Hello"
|
|
||||||
style={{
|
style={{
|
||||||
fontSize: 32,
|
justifyContent: "center",
|
||||||
fontFamily: "Inter",
|
alignItems: "center",
|
||||||
color: "#000000",
|
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>
|
</FlexWidget>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,52 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { HelloWidget } from "./HelloWidget";
|
import { HelloWidget } from "./HelloWidget";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import { ToastAndroid } from "react-native";
|
||||||
|
|
||||||
const nameToWidget = {
|
const nameToWidget = {
|
||||||
// Hello will be the **name** with which we will reference our widget.
|
// Hello will be the **name** with which we will reference our widget.
|
||||||
Hello: HelloWidget,
|
JR_shikoku_train_info: HelloWidget,
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function widgetTaskHandler(props) {
|
export async function widgetTaskHandler(props) {
|
||||||
const widgetInfo = props.widgetInfo;
|
const widgetInfo = props.widgetInfo;
|
||||||
const Widget = nameToWidget[widgetInfo.widgetName];
|
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) {
|
switch (props.widgetAction) {
|
||||||
case "WIDGET_ADDED":
|
case "WIDGET_ADDED":
|
||||||
props.renderWidget(<Widget />);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "WIDGET_UPDATE":
|
case "WIDGET_UPDATE":
|
||||||
// Not needed for now
|
// Not needed for now
|
||||||
break;
|
case "WIDGET_CLICK":
|
||||||
|
// Not needed for now
|
||||||
case "WIDGET_RESIZED":
|
case "WIDGET_RESIZED":
|
||||||
// Not needed for now
|
// Not needed for now
|
||||||
|
props.renderWidget(<Widget time={time} delayString={delayString} />);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "WIDGET_DELETED":
|
case "WIDGET_DELETED":
|
||||||
// Not needed for now
|
// Not needed for now
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "WIDGET_CLICK":
|
|
||||||
// Not needed for now
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user