From 8ce4a5582eb0e7e1dff64db3acb724997df74916 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 10 Aug 2023 10:23:05 +0000 Subject: [PATCH] disable drag if stop is the last added action --- src/Components/Icon/index.js | 9 +++- src/Screens/Device/scene.js | 88 ++++++++++++++++++++++++++---------- src/utils.js | 2 + 3 files changed, 74 insertions(+), 25 deletions(-) diff --git a/src/Components/Icon/index.js b/src/Components/Icon/index.js index 73e05d0..531bd29 100644 --- a/src/Components/Icon/index.js +++ b/src/Components/Icon/index.js @@ -2,10 +2,15 @@ import Icon from "@expo/vector-icons/MaterialCommunityIcons"; import { useContext } from "react"; 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 iconColor = color === undefined ? appContext.appTheme.icon : color; + const iconColor = + disabled === true + ? (color = appContext.appTheme.iconDisabled) + : color === undefined + ? appContext.appTheme.icon + : color; return ; } diff --git a/src/Screens/Device/scene.js b/src/Screens/Device/scene.js index d6392c2..fc59f18 100644 --- a/src/Screens/Device/scene.js +++ b/src/Screens/Device/scene.js @@ -8,7 +8,7 @@ import { GetDevice, VibrateShort, } from "../../utils"; -import { useCallback, useContext, useEffect, useState } from "react"; +import { useCallback, useContext, useState } from "react"; import MyDropdown from "../../Components/Dropdown"; import MyIcon from "../../Components/Icon"; 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 + ); + + /* +) : ( + + )} + */ + return ( <> {device.selectedScene === "" ? ( @@ -171,29 +188,45 @@ export default function SceneView({ navigation }) { /> } ListFooterComponent={ - - navigation.navigate("modalAddSceneAction", { - deviceFirmwareVersion: device.firmware.version, - }) - } - iconName="plus-circle-outline" - /> + <> + {lastSceneAction?.type !== Constants.actionType.stop ? ( + + navigation.navigate("modalAddSceneAction", { + deviceFirmwareVersion: device.firmware.version, + }) + } + iconName="plus-circle-outline" + /> + ) : ( + + )} + } 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 ( + {console.log("drag", drag)} { + // darg will be null if stop is rendered on the footer of the FlatList + if (!drag) return; + drag(); VibrateShort(); }} style={{ padding: 4 }} > - + diff --git a/src/utils.js b/src/utils.js index 1412076..c2b72ed 100644 --- a/src/utils.js +++ b/src/utils.js @@ -102,6 +102,7 @@ const DarkAppTheme = { divider: "#434443", textInputBottomColor: "#b2b3b3", icon: "#ddd", + iconDisabled: "#b2b3b3", switch: { trackColorTrue: "#01d064", trackColorFalse: "#b2b3b3", @@ -152,6 +153,7 @@ const LightAppTheme = { divider: "#ddd", textInputBottomColor: "#b2b3b3", icon: "#000", + iconDisabled: "#b2b3b3", switch: { trackColorTrue: "#01d064", trackColorFalse: "#b2b3b3",