@towsila/expo-ui-library 4.6.0 → 4.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M10.2891 1.00684C10.1017 1.63863 10 2.3074 10 3C10 6.86599 13.134 10 17 10C17.6924 10 18.3606 9.8972 18.9922 9.70996C18.9952 9.8063 19 9.90292 19 10C19 14.9706 14.9706 19 10 19C5.02944 19 1 14.9706 1 10C1 5.02944 5.02944 1 10 1C10.0967 1 10.1931 1.00381 10.2891 1.00684Z" stroke-width="2" stroke-linejoin="round" stroke="currentColor"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<circle cx="12" cy="12" r="4" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/>
|
|
3
|
+
<path d="M20 12H21" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
|
|
4
|
+
<path d="M3 12H4" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
|
|
5
|
+
<path d="M12 20L12 21" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
|
|
6
|
+
<path d="M12 3L12 4" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
|
|
7
|
+
<path d="M17.6572 17.6569L18.3643 18.364" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
|
|
8
|
+
<path d="M5.63574 5.63603L6.34285 6.34314" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
|
|
9
|
+
<path d="M6.34277 17.6569L5.63567 18.364" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
|
|
10
|
+
<path d="M18.3643 5.63603L17.6572 6.34314" stroke-width="2" stroke-linecap="round" stroke="currentColor"/>
|
|
11
|
+
</svg>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useRef, useEffect } from "react";
|
|
2
|
-
import { Animated, TouchableOpacity, View, Text
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import { Animated, TouchableOpacity, View, Text } from "react-native";
|
|
3
|
+
import DarkMode from "../../assets/icons/dark.svg";
|
|
4
|
+
import LightMode from "../../assets/icons/light.svg";
|
|
5
5
|
import { useAppTheme } from "../../context/ThemeContext";
|
|
6
|
+
import { useLanguage } from "../../context/LanguageContext";
|
|
6
7
|
import { Fonts, textSize } from "../../tokens/typography";
|
|
7
8
|
|
|
8
9
|
interface TextTheme {
|
|
@@ -11,84 +12,86 @@ interface TextTheme {
|
|
|
11
12
|
|
|
12
13
|
const TRACK_W = 52;
|
|
13
14
|
const TRACK_H = 30;
|
|
14
|
-
const THUMB
|
|
15
|
-
const MARGIN
|
|
16
|
-
const TRAVEL
|
|
15
|
+
const THUMB = 22;
|
|
16
|
+
const MARGIN = 4;
|
|
17
|
+
const TRAVEL = TRACK_W - THUMB - MARGIN * 2;
|
|
17
18
|
|
|
18
19
|
export default function ThemeToggle({ label }: TextTheme) {
|
|
19
20
|
const { isDark, toggleTheme, colors } = useAppTheme();
|
|
20
|
-
const
|
|
21
|
+
const { isRTL } = useLanguage();
|
|
22
|
+
const progress = useRef(new Animated.Value(isDark ? 1 : 0)).current;
|
|
21
23
|
|
|
22
24
|
useEffect(() => {
|
|
23
|
-
Animated.spring(
|
|
24
|
-
toValue: isDark ?
|
|
25
|
+
Animated.spring(progress, {
|
|
26
|
+
toValue: isDark ? 1 : 0,
|
|
25
27
|
useNativeDriver: true,
|
|
26
28
|
bounciness: 6,
|
|
27
29
|
}).start();
|
|
28
30
|
}, [isDark]);
|
|
29
31
|
|
|
32
|
+
// in RTL the thumb travels the other way
|
|
33
|
+
const translateX = progress.interpolate({
|
|
34
|
+
inputRange: [0, 1],
|
|
35
|
+
outputRange: isRTL ? [0, TRAVEL] : [0, -TRAVEL],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
|
|
30
39
|
return (
|
|
31
|
-
<View style={{ flexDirection: "row", alignItems: "center",
|
|
32
|
-
{isDark
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
<View style={{ flexDirection: isRTL ? "row" : "row-reverse", alignItems: "center",justifyContent:"space-between"}}>
|
|
41
|
+
<View style={{flexDirection: isRTL ? "row" : "row-reverse", gap: isDark ? 20:17}}>
|
|
42
|
+
{isDark ? (
|
|
43
|
+
<DarkMode width={22} height={22} color={colors.text.primary} />
|
|
44
|
+
) : (
|
|
45
|
+
<LightMode width={26} height={26} color={colors.text.primary} />
|
|
46
|
+
)}
|
|
36
47
|
|
|
37
48
|
{label && (
|
|
38
|
-
<Text style={{
|
|
39
|
-
fontFamily: Fonts.montserrat.regular,
|
|
40
|
-
fontSize: textSize.md,
|
|
41
|
-
color: colors.text.primary,
|
|
42
|
-
|
|
43
|
-
}}>
|
|
49
|
+
<Text style={{ fontFamily: Fonts.montserrat.semiBold, fontSize: textSize.md, color: colors.text.primary }}>
|
|
44
50
|
{label}
|
|
45
51
|
</Text>
|
|
46
52
|
)}
|
|
47
|
-
|
|
48
|
-
<TouchableOpacity
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
{/* Border */}
|
|
63
|
-
<Path
|
|
64
|
-
d="M16.5762 0.555176C19.0518 0.621842 21.5273 0.685176 24.0029 0.745176C29.5273 0.87907 35.0518 0.996364 40.5762 1.09706C48.8146 1.06558 55.9659 8.51881 55.6907 16.5552C55.6907 16.5552 55.6907 16.5552 55.6907 16.5552C55.8007 24.604 48.5576 31.7464 40.5762 31.5552C32.5762 31.5552 24.5762 31.59 16.5762 31.6596C8.54491 31.9309 1.10353 24.7824 1.13849 16.5552C1.13849 16.5552 1.13849 16.5552 1.13849 16.5552C0.96865 10.834 4.30374 5.12979 9.49713 2.41467C11.6569 1.26135 14.098 0.618935 16.5762 0.555176C14.0986 0.48538 11.5935 1.00216 9.32675 2.07501C3.8814 4.58411 0.0515389 10.4081 0.0138575 16.5552C0.0138575 16.5552 0.0138575 16.5552 0.0138575 16.5552C-0.365635 25.3731 7.56226 33.5939 16.5762 33.4507C24.5762 33.5204 32.5762 33.5552 40.5762 33.5552C40.5762 33.5552 40.5762 33.5552 40.5762 33.5552C49.6399 33.7784 57.7661 25.5516 57.4616 16.5552C57.4616 16.5552 57.4616 16.5552 57.4616 16.5552C57.6009 7.54638 49.383 -0.369685 40.5762 0.0132933C35.0518 0.113988 29.5273 0.231282 24.0029 0.365176C21.5273 0.425176 19.0518 0.488509 16.5762 0.555176ZM16.5762 0.555176"
|
|
65
|
-
fill={colors.text.primary}
|
|
66
|
-
/>
|
|
67
|
-
</Svg>
|
|
68
|
-
|
|
69
|
-
{/* Thumb */}
|
|
70
|
-
<Animated.View style={{
|
|
71
|
-
position: "absolute",
|
|
72
|
-
top: MARGIN,
|
|
73
|
-
...(I18nManager.isRTL ? { right: MARGIN } : { left: MARGIN }),
|
|
74
|
-
width: THUMB,
|
|
75
|
-
height: THUMB,
|
|
76
|
-
borderRadius: THUMB / 2,
|
|
77
|
-
backgroundColor: colors.text.primary,
|
|
78
|
-
transform: [{ translateX }],
|
|
79
|
-
overflow: "hidden",
|
|
53
|
+
</View>
|
|
54
|
+
<TouchableOpacity
|
|
55
|
+
onPress={toggleTheme}
|
|
56
|
+
activeOpacity={0.9}
|
|
57
|
+
accessibilityRole="switch"
|
|
58
|
+
accessibilityState={{ checked: isDark }}
|
|
59
|
+
>
|
|
60
|
+
<View
|
|
61
|
+
style={{
|
|
62
|
+
width: TRACK_W,
|
|
63
|
+
height: TRACK_H,
|
|
64
|
+
borderRadius: TRACK_H / 2,
|
|
65
|
+
backgroundColor: colors.primary,
|
|
66
|
+
borderWidth: 1,
|
|
67
|
+
borderColor: colors.text.primary,
|
|
80
68
|
justifyContent: "center",
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
:
|
|
91
|
-
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
<Animated.View
|
|
72
|
+
style={{
|
|
73
|
+
position: "absolute",
|
|
74
|
+
top: (TRACK_H - THUMB) / 2 - 1,
|
|
75
|
+
...(isRTL ? { right: MARGIN - 1 } : { left: MARGIN - 1 }),
|
|
76
|
+
width: THUMB,
|
|
77
|
+
height: THUMB,
|
|
78
|
+
borderRadius: THUMB / 2,
|
|
79
|
+
backgroundColor: colors.text.primary,
|
|
80
|
+
alignItems: "center",
|
|
81
|
+
justifyContent: "center",
|
|
82
|
+
transform: [{ translateX }],
|
|
83
|
+
elevation: 3,
|
|
84
|
+
shadowColor: "#000",
|
|
85
|
+
shadowOffset: { width: 0, height: 2 },
|
|
86
|
+
shadowOpacity: 0.25,
|
|
87
|
+
shadowRadius: 3,
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
{isDark ? (
|
|
91
|
+
<LightMode width={16} height={16} color={colors.background.main} />
|
|
92
|
+
) : (
|
|
93
|
+
<DarkMode width={12} height={12} color={colors.background.main} />
|
|
94
|
+
)}
|
|
92
95
|
</Animated.View>
|
|
93
96
|
</View>
|
|
94
97
|
</TouchableOpacity>
|