Merge commit '1f9c3064bf16c57119af415804c7f3bf495927ff' into develop

This commit is contained in:
harukin-expo-dev-env 2024-03-07 13:00:22 +00:00
commit 5d5cf23773
7 changed files with 206 additions and 10 deletions

View File

@ -3,9 +3,24 @@
"name": "JR四国運行状況",
"slug": "jrshikoku",
"privacy": "public",
"platforms": [
"ios",
"android"
"platforms": ["ios", "android"],
"plugins": [
[
"react-native-android-widget",
{
"widgets": [
{
"name": "JR_shikoku_train_info",
"label": "My Hello Widget",
"minWidth": "320dp",
"minHeight": "120dp",
"description": "This is my first widget",
"previewImage": "./assets/icon.png",
"updatePeriodMillis": 1800000
}
]
}
]
],
"version": "4.6",
"orientation": "default",
@ -19,9 +34,7 @@
"fallbackToCacheTimeout": 0,
"url": "https://u.expo.dev/398abf60-57a7-11e9-970c-8f04356d08bf"
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"buildNumber": "31",
"supportsTablet": true,
@ -33,9 +46,7 @@
"android": {
"package": "jrshikokuinfo.xprocess.hrkn",
"versionCode": 20,
"permissions": [
"ACCESS_FINE_LOCATION"
],
"permissions": ["ACCESS_FINE_LOCATION"],
"googleServicesFile": "./google-services.json",
"config": {
"googleMaps": {

View File

@ -0,0 +1,88 @@
import React from "react";
import { FlexWidget, TextWidget } from "react-native-android-widget";
export function HelloWidget({ time, delayString }) {
return (
<FlexWidget
style={{
height: "match_parent",
width: "match_parent",
justifyContent: "center",
alignItems: "center",
backgroundColor: "#ffffff",
borderRadius: 16,
}}
clickAction="WIDGET_CLICK"
>
<FlexWidget
style={{
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

@ -0,0 +1,25 @@
import * as React from "react";
import { StyleSheet, View } from "react-native";
import { WidgetPreview } from "react-native-android-widget";
import { HelloWidget } from "./HelloWidget";
export function HelloWidgetPreviewScreen() {
return (
<View style={styles.container}>
<WidgetPreview
renderWidget={() => <HelloWidget />}
width={320}
height={200}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
});

View File

@ -0,0 +1,55 @@
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.
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":
case "WIDGET_UPDATE":
// 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;
break;
default:
break;
}
}

11
index.js Normal file
View File

@ -0,0 +1,11 @@
import { registerRootComponent } from "expo";
import { registerWidgetTaskHandler } from "react-native-android-widget";
import App from "./App";
import { widgetTaskHandler } from "./components/AndroidWidget/widget-task-handler";
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
// the environment is set up appropriately
registerRootComponent(App);
registerWidgetTaskHandler(widgetTaskHandler);

View File

@ -1,5 +1,5 @@
{
"main": "node_modules/expo/AppEntry.js",
"main": "index.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
@ -31,6 +31,7 @@
"react": "18.2.0",
"react-native": "0.72.6",
"react-native-actions-sheet": "0.8.21",
"react-native-android-widget": "^0.11.2",
"react-native-auto-height-image": "^3.2.4",
"react-native-elements": "^3.4.2",
"react-native-gesture-handler": "~2.12.0",

View File

@ -8684,6 +8684,11 @@ react-native-actions-sheet@0.8.21:
resolved "https://registry.yarnpkg.com/react-native-actions-sheet/-/react-native-actions-sheet-0.8.21.tgz#d9175e7d5d862217f990b2ccc8a216fb4fc35b06"
integrity sha512-WUtrGbPSlY8YuVSxKVJ36f3PrVMGMOQ5Cp5dtpurc71Uih4LEGGhEEk8yme/QOquiGsu77be0sZT4CrSUOSXag==
react-native-android-widget@^0.11.2:
version "0.11.2"
resolved "https://registry.yarnpkg.com/react-native-android-widget/-/react-native-android-widget-0.11.2.tgz#541cc4931f6cf362b533d0e079a740ee595cd88e"
integrity sha512-Ro4inoMaXFtcMX/9p+O+e/Cm0ckg6tkbIB/PFdF+xX90+B/2sWjXDL9qgGRAsFN7Auj38hMqTl8bWBlImFCC2A==
react-native-auto-height-image@^3.2.4:
version "3.2.4"
resolved "https://registry.yarnpkg.com/react-native-auto-height-image/-/react-native-auto-height-image-3.2.4.tgz#c7a95d4d9701055c680c8dc02076def1107f9522"