import {
FlatList,
Image,
ScrollView,
Text,
TouchableOpacity,
View,
} from "react-native";
import {
MyDeviceTabButton,
topFirst,
topSecond,
} from "../../../deviceTabButton";
import Card from "../../../../../Components/Card";
import MyDropdown from "../../../../../Components/Dropdown";
import { useCallback, useContext, useEffect, useRef, useState } from "react";
import { AppContext, AppStyles, ModalContainer } from "../../../../../utils";
import { MyPickerModalListItem } from "../../../../../Components/Modal";
import { MyColorPickerV2 } from "../../../../../Components/ColorPicker";
import Animated, {
useAnimatedStyle,
useSharedValue,
} from "react-native-reanimated";
import { Divider } from "../../../../../Components/Divider";
import { MyIconButton } from "../../../../../Components/Button";
import { ColorPickerRef } from "reanimated-color-picker"; // used
import EditActionAnimationsCardContent, {
EditActionAdjustmentContent,
} from "..";
import { useTranslation } from "react-i18next";
import { useFocusEffect } from "@react-navigation/native";
function LightModeDefaultColor({
sharedColor,
index,
backgroundColor,
selected,
}) {
const backgroundColorStyle = useAnimatedStyle(() => {
return {
backgroundColor: sharedColor.value[index],
};
});
return (
);
}
export function LightsEditActionModalContent({ navigation, route }) {
const appContext = useContext(AppContext);
const [lightModeDefaultColors, setLightModeDefaultColors] = useState([]);
const sharedLightModeDefaultColors = useSharedValue([]);
const [selectedDefaultLightModeColor, setSelectedDefaultLightModeColor] =
useState(0);
const colorPickerRef = useRef(ColorPickerRef);
const { t } = useTranslation();
const { actionId, deviceFirmwareVersion } = route.params;
const supportedDeviceLightModes =
appContext.deviceFirmwareModes.lightModes.filter((lightMode) =>
lightMode.supportedFirmwareVersions.includes(deviceFirmwareVersion)
);
const selectedSceneActionModeId = appContext.deviceSceneActions.find(
(a) => a.actionId === actionId
).modeId;
const selectedLightMode = supportedDeviceLightModes.find(
(s) => s.id === selectedSceneActionModeId
);
useEffect(() => {
if (colorPickerRef.current && selectedLightMode.defaults.length > 0) {
colorPickerRef.current.setColor(selectedLightMode.defaults[0]);
}
}, [lightModeDefaultColors]);
useEffect(() => {
if (selectedLightMode !== undefined) {
sharedLightModeDefaultColors.value = selectedLightMode.defaults;
setLightModeDefaultColors(selectedLightMode.defaults);
setSelectedDefaultLightModeColor(0);
}
}, [selectedSceneActionModeId]);
return (
{appContext.isUserDeveloperModeEnabled ? (
) : (
)}
navigation.navigate("modalLayersEditActionColorModeSelection", {
supportedDeviceLightModes: supportedDeviceLightModes,
selectedSceneActionModeId: selectedSceneActionModeId,
actionId: route.params.actionId,
})
}
/>
{selectedSceneActionModeId !== "" && (
<>
{lightModeDefaultColors.length > 0 && (
<>
{t(
"screens.device.scenes.modalLayersEditAction.modeSpecificColors"
)}
{lightModeDefaultColors.map((_, index) => (
{
/*const newSelection =
selectedDefaultLightModeColor !== index
? index
: undefined;
setSelectedDefaultLightModeColor(newSelection);
if (newSelection !== undefined) {
colorPickerRef.current.setColor(
sharedLightModeDefaultColors.value[index]
);
}*/
setSelectedDefaultLightModeColor(index);
colorPickerRef.current.setColor(
sharedLightModeDefaultColors.value[index]
);
}}
>
))}
{
if (selectedDefaultLightModeColor !== undefined) {
let newColors = sharedLightModeDefaultColors.value;
newColors[selectedDefaultLightModeColor] = color;
sharedLightModeDefaultColors.value = newColors;
}
}}
/>
>
)}
{selectedLightMode.adjustments.length > 0 && (
{selectedLightMode.adjustments.map((adjustment, index) => (
))}
)}
>
)}
);
}
export function LayersEditActionColorModeSelectionModalContent({
navigation,
route,
}) {
const appContext = useContext(AppContext);
return (
item.id}
renderItem={({ item }) => (
{
appContext.setDeviceSceneActions((arr) => {
const newArr = [...arr];
const actionIndex = newArr.findIndex(
(a) => a.actionId === route.params.actionId
);
if (actionIndex !== -1) {
newArr[actionIndex].modeId = item.id;
}
return newArr;
});
navigation.goBack();
}}
/>
)}
/>
);
}