소스 검색

Themed Switch Initialization

Savio Fernando 1 년 전
부모
커밋
ea2c4a9228
1개의 변경된 파일99개의 추가작업 그리고 0개의 파일을 삭제
  1. 99 0
      components/molecules/ThemedSwitch.js

+ 99 - 0
components/molecules/ThemedSwitch.js

@@ -0,0 +1,99 @@
+import { StyleSheet, Text, View } from 'react-native'
+import React from 'react'
+import CustomSwitch from './CustomSwitch'
+import colors from '../../theme/colors'
+import { interpolateColor, useAnimatedStyle, useSharedValue } from 'react-native-reanimated'
+
+const ThemedSwitch = ({ value = true, onValueChange, theme }) => {
+    let style = {}
+    let toggleOnColor = colors.white
+    let toggleOffColor = colors.white
+    const shareValue = useSharedValue(value ? 1 : 0)
+    const InterpolateXInput = [0, 1];
+
+    switch (theme) {
+        case 'secondary':
+
+            toggleOffColor = colors.primaryColor
+            toggleOnColor = colors.white
+            style = {
+                containerStyle: {
+                    // borderColor: colors.primaryColor,
+                    borderColor: interpolateColor(shareValue.value, InterpolateXInput, [
+                        toggleOffColor,
+                        toggleOnColor,
+                    ]),
+                    borderWidth: 2,
+                    backgroundColor: interpolateColor(shareValue.value, InterpolateXInput.reverse(), [
+                        toggleOffColor,
+                        toggleOnColor,
+                    ]),
+
+                }
+            }
+
+
+            break;
+        case 'primary':
+        default:
+
+            toggleOffColor = colors.primaryColor
+            toggleOnColor = colors.white
+            style = {
+                containerStyle: {
+                    // borderColor: colors.primaryColor,
+                    borderColor: interpolateColor(shareValue.value, InterpolateXInput.reverse(), [
+                        toggleOffColor,
+                        toggleOnColor,
+                    ]),
+                    borderWidth: 2,
+                    backgroundColor: interpolateColor(shareValue.value, InterpolateXInput.reverse(), [
+                        toggleOffColor,
+                        toggleOnColor,
+                    ]),
+
+                }
+            }
+
+
+            break;
+
+    }
+
+
+    const containerAnimatedStyle = useAnimatedStyle(() => style)
+
+    // {
+    //     return {
+    //       transform: [
+    //         {
+    //           translateX: interpolate(
+    //             shareValue.value,
+    //             InterpolateXInput,
+    //             [0, BUTTON_WIDTH - SWITCH_BUTTON_AREA - 2 * SWITCH_BUTTON_PADDING],
+    //             Extrapolate.CLAMP,
+    //           ),
+    //         },
+    //       ],
+    //       backgroundColor: interpolateColor(shareValue.value, InterpolateXInput, [
+    //         toggleOffColor,
+    //         toggleOnColor,
+    //       ]),
+    //     };
+    //   });
+    return (
+        <CustomSwitch
+            onChange={onValueChange}
+            value={value}
+            containerStyle={containerAnimatedStyle}
+            toggleOffColor={toggleOffColor}
+            toggleOnColor={toggleOnColor}
+            height={22}
+            width={40}
+        />
+    )
+}
+
+export default ThemedSwitch
+
+const styles = StyleSheet.create({})