disable drag if stop is the last added action

main
alex 2023-08-10 10:23:05 +00:00
parent da484d8b5f
commit 8ce4a5582e
3 changed files with 74 additions and 25 deletions

View File

@ -2,10 +2,15 @@ import Icon from "@expo/vector-icons/MaterialCommunityIcons";
import { useContext } from "react"; import { useContext } from "react";
import { AppContext } from "../../utils"; import { AppContext } from "../../utils";
export default function MyIcon({ style, name, color, size }) { export default function MyIcon({ style, name, color, size, disabled }) {
const appContext = useContext(AppContext); const appContext = useContext(AppContext);
const iconColor = color === undefined ? appContext.appTheme.icon : color; const iconColor =
disabled === true
? (color = appContext.appTheme.iconDisabled)
: color === undefined
? appContext.appTheme.icon
: color;
return <Icon style={style} name={name} color={iconColor} size={size} />; return <Icon style={style} name={name} color={iconColor} size={size} />;
} }

View File

@ -8,7 +8,7 @@ import {
GetDevice, GetDevice,
VibrateShort, VibrateShort,
} from "../../utils"; } from "../../utils";
import { useCallback, useContext, useEffect, useState } from "react"; import { useCallback, useContext, useState } from "react";
import MyDropdown from "../../Components/Dropdown"; import MyDropdown from "../../Components/Dropdown";
import MyIcon from "../../Components/Icon"; import MyIcon from "../../Components/Icon";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@ -130,6 +130,23 @@ export default function SceneView({ navigation }) {
); );
}; };
const lastSceneAction = deviceSceneActions[deviceSceneActions.length - 1];
console.log(
"lastSceneAction",
lastSceneAction?.type === Constants.actionType.stop
);
/*
) : (
<ActionListItem
navigation={navigation}
device={device}
item={deviceSceneActions[deviceSceneActions.length - 1]}
/>
)}
*/
return ( return (
<> <>
{device.selectedScene === "" ? ( {device.selectedScene === "" ? (
@ -171,29 +188,45 @@ export default function SceneView({ navigation }) {
/> />
} }
ListFooterComponent={ ListFooterComponent={
<MyTextButton <>
title={t("screens.device.scenes.buttonAddAction")} {lastSceneAction?.type !== Constants.actionType.stop ? (
styleContainer={[ <MyTextButton
{ title={t("screens.device.scenes.buttonAddAction")}
alignItems: "center", styleContainer={[
marginTop: 10, {
}, alignItems: "center",
AppStyles.appBottom, marginTop: 10,
]} },
style={{ padding: 8 }} AppStyles.appBottom,
actionColor={ ]}
deviceSceneActions === undefined || style={{ padding: 8 }}
deviceSceneActions.length === 0 actionColor={
} deviceSceneActions === undefined ||
onPress={() => deviceSceneActions.length === 0
navigation.navigate("modalAddSceneAction", { }
deviceFirmwareVersion: device.firmware.version, onPress={() =>
}) navigation.navigate("modalAddSceneAction", {
} deviceFirmwareVersion: device.firmware.version,
iconName="plus-circle-outline" })
/> }
iconName="plus-circle-outline"
/>
) : (
<ActionListItem
drag={false}
navigation={navigation}
device={device}
item={lastSceneAction}
/>
)}
</>
} }
renderItem={({ item, drag }) => { renderItem={({ item, drag }) => {
// the item for stop will be rendered on the footer of the FlatList to prevent dragging other actions below the stop
if (item.type === Constants.actionType.stop) {
return null;
}
return ( return (
<ScaleDecorator> <ScaleDecorator>
<ActionListItem <ActionListItem
@ -519,14 +552,23 @@ function ActionListItem({ drag, navigation, device, item }) {
</View> </View>
</View> </View>
{console.log("drag", drag)}
<TouchableOpacity <TouchableOpacity
disabled={drag === false}
onLongPress={() => { onLongPress={() => {
// darg will be null if stop is rendered on the footer of the FlatList
if (!drag) return;
drag(); drag();
VibrateShort(); VibrateShort();
}} }}
style={{ padding: 4 }} style={{ padding: 4 }}
> >
<MyIcon name="menu" size={20} /> <MyIcon
name="menu"
size={20}
disabled={drag === false}
/>
</TouchableOpacity> </TouchableOpacity>
</View> </View>

View File

@ -102,6 +102,7 @@ const DarkAppTheme = {
divider: "#434443", divider: "#434443",
textInputBottomColor: "#b2b3b3", textInputBottomColor: "#b2b3b3",
icon: "#ddd", icon: "#ddd",
iconDisabled: "#b2b3b3",
switch: { switch: {
trackColorTrue: "#01d064", trackColorTrue: "#01d064",
trackColorFalse: "#b2b3b3", trackColorFalse: "#b2b3b3",
@ -152,6 +153,7 @@ const LightAppTheme = {
divider: "#ddd", divider: "#ddd",
textInputBottomColor: "#b2b3b3", textInputBottomColor: "#b2b3b3",
icon: "#000", icon: "#000",
iconDisabled: "#b2b3b3",
switch: { switch: {
trackColorTrue: "#01d064", trackColorTrue: "#01d064",
trackColorFalse: "#b2b3b3", trackColorFalse: "#b2b3b3",