-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
161 lines (149 loc) Β· 3.76 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import React, { useState } from "react";
import {
AccessibilityRole,
ImageProps,
ImageStyle,
StyleSheet,
TouchableOpacity,
View,
Text as RNText,
} from "react-native";
import {
ApplicationProvider,
Button,
Icon,
IconRegistry,
Layout,
Text,
} from "@ui-kitten/components";
import { EvaIconsPack } from "@ui-kitten/eva-icons";
import { mapping, light, dark } from "@eva-design/eva";
const heartIcons = ["π»", "π", "π", "π₯°", "π", "π", "π", "π", "π", "π±"];
const themes = {
light: {
theme: light,
icon: "sun",
text: "LIGHT",
},
dark: {
theme: dark,
icon: "moon",
text: "DARK",
},
};
type IconProps = {
name: string;
style?: ImageStyle;
};
type CustomButtonWithIconProps = {
accessibilityRole: AccessibilityRole;
accessibilityLabel: string;
icon: string;
iconStyle?: ImageStyle;
onPress: () => void;
text: string;
style: any;
};
const renderIcon = ({ name, style }: IconProps) => (
<Icon {...style} name={name} />
);
const CustomButtonWithIcon = ({
accessibilityRole,
accessibilityLabel,
icon,
iconStyle,
onPress,
text,
style,
}: CustomButtonWithIconProps) => {
const ButtonIcon = () => renderIcon({ name: icon, style: iconStyle });
return (
<Button
style={style}
icon={ButtonIcon}
onPress={onPress}
accessibilityRole={accessibilityRole}
accessibilityLabel={accessibilityLabel}
>
{text}
</Button>
);
};
const App = (): React.ReactFragment => {
const [icon, setIcon] = useState(heartIcons[0]);
const [themeName, setThemeName] = useState("light");
const theme = themes[themeName].theme;
const changeIcon = () => {
const index = Math.floor(Math.random() * heartIcons.length);
setIcon(heartIcons[index]);
};
const changeTheme = () => {
setThemeName(themeName === "light" ? "dark" : "light");
};
const { text: themeButtonText, icon: themeButtonIcon } =
themeName === "light" ? themes.dark : themes.light;
return (
<>
<IconRegistry icons={EvaIconsPack} />
<ApplicationProvider mapping={mapping} theme={theme}>
<Layout style={styles.container}>
<Text style={styles.text} category="h1">
Welcome to UI Kitten {icon}
</Text>
<Text style={styles.text} category="s1">
It works great in the browser and as a native app!
</Text>
<Text style={styles.text} appearance="hint">
Click some buttons to see it working.
</Text>
<Button
accessibilityRole="button"
accessibilityLabel="Change Icon"
style={styles.iconButton}
onPress={changeIcon}
>
CHANGE ICON
</Button>
<CustomButtonWithIcon
accessibilityRole="button"
accessibilityLabel="UI Kitten Change Theme"
style={styles.iconButton}
text={`SWITCH TO ${themeButtonText} THEME`}
icon={themeButtonIcon}
onPress={changeTheme}
iconStyle={{ tintColor: "white" }}
/>
<TouchableOpacity
accessibilityRole="button"
accessibilityLabel="Native Change Theme"
onPress={changeTheme}
>
<View style={styles.nativeButton}>
<RNText>NATIVE CHANGE THEME</RNText>
</View>
</TouchableOpacity>
</Layout>
</ApplicationProvider>
</>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
paddingHorizontal: 10,
},
text: {
textAlign: "center",
},
iconButton: {
marginVertical: 16,
},
nativeButton: {
alignItems: "center",
backgroundColor: "#DDDDDD",
padding: 10,
},
});
export default App;