テストウィジェット作成

This commit is contained in:
harukin-expo-dev-env
2024-03-06 03:05:31 +00:00
parent d95eea44a4
commit d3b99535f2
7 changed files with 126 additions and 10 deletions

View File

@@ -0,0 +1,26 @@
import React from "react";
import { FlexWidget, TextWidget } from "react-native-android-widget";
export function HelloWidget() {
return (
<FlexWidget
style={{
height: "match_parent",
width: "match_parent",
justifyContent: "center",
alignItems: "center",
backgroundColor: "#ffffff",
borderRadius: 16,
}}
>
<TextWidget
text="Hello"
style={{
fontSize: 32,
fontFamily: "Inter",
color: "#000000",
}}
/>
</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,37 @@
import React from "react";
import { HelloWidget } from "./HelloWidget";
const nameToWidget = {
// Hello will be the **name** with which we will reference our widget.
Hello: HelloWidget,
};
export async function widgetTaskHandler(props) {
const widgetInfo = props.widgetInfo;
const Widget = nameToWidget[widgetInfo.widgetName];
switch (props.widgetAction) {
case "WIDGET_ADDED":
props.renderWidget(<Widget />);
break;
case "WIDGET_UPDATE":
// Not needed for now
break;
case "WIDGET_RESIZED":
// Not needed for now
break;
case "WIDGET_DELETED":
// Not needed for now
break;
case "WIDGET_CLICK":
// Not needed for now
break;
default:
break;
}
}