disable drag if stop is the last added action
parent
da484d8b5f
commit
8ce4a5582e
|
@ -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} />;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,6 +188,8 @@ export default function SceneView({ navigation }) {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
ListFooterComponent={
|
ListFooterComponent={
|
||||||
|
<>
|
||||||
|
{lastSceneAction?.type !== Constants.actionType.stop ? (
|
||||||
<MyTextButton
|
<MyTextButton
|
||||||
title={t("screens.device.scenes.buttonAddAction")}
|
title={t("screens.device.scenes.buttonAddAction")}
|
||||||
styleContainer={[
|
styleContainer={[
|
||||||
|
@ -192,8 +211,22 @@ export default function SceneView({ navigation }) {
|
||||||
}
|
}
|
||||||
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>
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue