領域を仮作成

This commit is contained in:
harukin-expo-dev-env 2024-03-28 13:37:17 +00:00
parent aa7c57a848
commit d55a62b8ae
4 changed files with 221 additions and 7 deletions

View File

@ -8,14 +8,9 @@ const nameToWidget = {
JR_shikoku_train_info: TraInfoEXWidget, JR_shikoku_train_info: TraInfoEXWidget,
}; };
export async function widgetTaskHandler(props) { export const getDelayData = async () => {
const widgetInfo = props.widgetInfo; // Fetch data from the server
const Widget = nameToWidget[widgetInfo.widgetName];
const time = dayjs().format("HH:mm"); const time = dayjs().format("HH:mm");
ToastAndroid.show(
`Widget Action: ${props.widgetAction} ${time}`,
ToastAndroid.SHORT
);
const delayString = await fetch( const delayString = await fetch(
"https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec" "https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec"
) )
@ -27,6 +22,16 @@ export async function widgetTaskHandler(props) {
return null; return null;
}); });
ToastAndroid.show(`${delayString}`, ToastAndroid.SHORT); ToastAndroid.show(`${delayString}`, ToastAndroid.SHORT);
return { time, delayString };
};
export async function widgetTaskHandler(props) {
const widgetInfo = props.widgetInfo;
const Widget = nameToWidget[widgetInfo.widgetName];
ToastAndroid.show(
`Widget Action: ${JSON.stringify(props.widgetInfo.widgetId)}`,
ToastAndroid.SHORT
);
const { time, delayString } = await getDelayData();
switch (props.widgetAction) { switch (props.widgetAction) {
case "WIDGET_ADDED": case "WIDGET_ADDED":
case "WIDGET_UPDATE": case "WIDGET_UPDATE":

View File

@ -167,6 +167,34 @@ export const SettingTopPage = ({
{">"} {">"}
</Text> </Text>
</ListItem> </ListItem>
<ListItem
style={{ flexDirection: "row" }}
onPress={() => navigate("WidgetSettings")}
>
<Text
style={{
fontSize: 20,
alignItems: "center",
alignContent: "center",
textAlign: "center",
textAlignVertical: "center",
}}
>
ウィジェット設定
</Text>
<View style={{ flex: 1 }} />
<Text
style={{
fontSize: 20,
alignItems: "center",
alignContent: "center",
textAlign: "center",
textAlignVertical: "center",
}}
>
{">"}
</Text>
</ListItem>
<ListItem <ListItem
style={{ flexDirection: "row" }} style={{ flexDirection: "row" }}
onPress={() => onPress={() =>

View File

@ -0,0 +1,168 @@
import React, { useEffect, useState } from "react";
import { View, Text, TouchableOpacity, ScrollView } from "react-native";
import { SwitchArea } from "../atom/SwitchArea";
import { CheckBox } from "react-native-elements";
import { TripleSwitchArea } from "../atom/TripleSwitchArea";
import { getWidgetInfo, WidgetPreview } from "react-native-android-widget";
import { TraInfoEXWidget } from "../AndroidWidget/TraInfoEXWidget";
import { getDelayData } from "../AndroidWidget/widget-task-handler";
import { ListItem } from "native-base";
export const WidgetSettings = ({ navigate }) => {
const widgetInfo = getWidgetInfo("JR_shikoku_train_info");
const [widgetList, setWidgetList] = useState([]);
useEffect(() => {
widgetInfo.then((s) => {
if (s.length > 0) {
setWidgetList(s);
s.forEach((element) => {
console.log(element);
});
}
});
}, []);
const [time, setTime] = useState(time);
const [delayString, setDelayString] = useState(delayString);
useEffect(() => {
getDelayData().then(({ time, delayString }) => {
setTime(time);
setDelayString(delayString);
});
}, []);
return (
<View style={{ height: "100%", backgroundColor: "#0099CC" }}>
<View style={{ backgroundColor: "#0099CC", flexDirection: "row" }}>
<View style={{ flex: 1 }}>
<TouchableOpacity
onPress={() => navigate("settingTopPage")}
style={{
flexDirection: "column",
flex: 1,
}}
>
<View style={{ flex: 1 }} />
<Text
style={{
fontSize: 20,
fontWeight: "bold",
textAlign: "left",
textAlignVertical: "center",
color: "white",
padding: 10,
}}
>
設定
</Text>
<View style={{ flex: 1 }} />
</TouchableOpacity>
</View>
<Text
style={{
fontSize: 20,
fontWeight: "bold",
textAlign: "center",
color: "white",
padding: 10,
}}
>
ウィジェット設定
</Text>
<View style={{ flex: 1 }}></View>
</View>
<ScrollView style={{ flex: 1, backgroundColor: "white" }}>
<View style={{ alignContent: "center", alignItems: "center" }}>
<View
style={{
borderRadius: 15,
borderColor: "black",
borderWidth: 5,
borderStyle: "solid",
overflow: "hidden",
margin: 10,
}}
>
<WidgetPreview
renderWidget={() => (
<TraInfoEXWidget time={time} delayString={delayString} />
)}
width={400}
height={250}
/>
</View>
</View>
<ListItem key={"default"}>
<Text
style={{
fontSize: 20,
alignItems: "center",
alignContent: "center",
textAlign: "center",
textAlignVertical: "center",
marginRight: 10,
}}
>
ID
</Text>
<Text
style={{
fontSize: 20,
alignItems: "center",
alignContent: "center",
textAlign: "center",
textAlignVertical: "center",
}}
>
名前
</Text>
</ListItem>
{widgetList.map((widget) => (
<ListItem key={widget.widgetId}>
<Text
style={{
fontSize: 20,
alignItems: "center",
alignContent: "center",
textAlign: "center",
textAlignVertical: "center",
marginRight: 10,
}}
>
{widget.widgetId}
</Text>
<Text
style={{
fontSize: 20,
alignItems: "center",
alignContent: "center",
textAlign: "center",
textAlignVertical: "center",
}}
>
{widget.widgetName}
</Text>
</ListItem>
))}
</ScrollView>
</View>
);
};
const SimpleSwitch = ({ bool, setBool, str }) => (
<View style={{ flexDirection: "row" }}>
<CheckBox
checked={bool == "true" ? true : false}
checkedColor="red"
onPress={() => setBool(bool == "true" ? "false" : "true")}
containerStyle={{
flex: 1,
backgroundColor: "#00000000",
borderColor: "white",
alignContent: "center",
}}
textStyle={{ fontSize: 20, fontWeight: "normal" }}
title={str}
/>
</View>
);

View File

@ -20,6 +20,7 @@ import { Switch } from "react-native-elements";
import AutoHeightImage from "react-native-auto-height-image"; import AutoHeightImage from "react-native-auto-height-image";
import { SettingTopPage } from "./SettingTopPage"; import { SettingTopPage } from "./SettingTopPage";
import { LayoutSettings } from "./LayoutSettings"; import { LayoutSettings } from "./LayoutSettings";
import { WidgetSettings } from "./WidgetSettings";
const Stack = createStackNavigator(); const Stack = createStackNavigator();
export default function Setting(props) { export default function Setting(props) {
@ -123,6 +124,18 @@ export default function Setting(props) {
/> />
)} )}
</Stack.Screen> </Stack.Screen>
<Stack.Screen
name="WidgetSettings"
options={{
gestureEnabled: true,
...TransitionPresets.SlideFromRightIOS,
cardOverlayEnabled: true,
headerTransparent: true,
headerShown: false,
}}
>
{(props) => <WidgetSettings {...props} navigate={navigate} />}
</Stack.Screen>
</Stack.Navigator> </Stack.Navigator>
); );
} }