test commit
This commit is contained in:
parent
59696b2caf
commit
04e73d2edb
4 changed files with 100 additions and 13 deletions
|
|
@ -1,12 +1,32 @@
|
||||||
import { Tabs } from 'expo-router/tabs';
|
import { Tabs } from 'expo-router/tabs';
|
||||||
import {HeaderTitle} from "@react-navigation/elements";
|
import {HeaderTitle} from "@react-navigation/elements";
|
||||||
|
|
||||||
|
import { FontAwesome } from "@expo/vector-icons";
|
||||||
|
|
||||||
export default function Layout() {
|
export default function Layout() {
|
||||||
return (
|
return (
|
||||||
<Tabs>
|
<Tabs initialRouteName={"index"}>
|
||||||
<Tabs.Screen name="budget" options={{tabBarShowLabel: false}}/>
|
<Tabs.Screen name="budget" options={
|
||||||
<Tabs.Screen name="index" />
|
{
|
||||||
<Tabs.Screen name="stats" />
|
tabBarLabel: "Budget",
|
||||||
|
tabBarIcon: ({ color, size }) => (
|
||||||
|
<FontAwesome name="money" size={size} color={color}/>),
|
||||||
|
}
|
||||||
|
}/>
|
||||||
|
<Tabs.Screen name="index" options={
|
||||||
|
{
|
||||||
|
tabBarLabel: "Home",
|
||||||
|
tabBarIcon: ({ color, size }) => (
|
||||||
|
<FontAwesome name="home" size={size} color={color}/>),
|
||||||
|
}
|
||||||
|
}/>
|
||||||
|
<Tabs.Screen name="stats" options={
|
||||||
|
{
|
||||||
|
tabBarLabel: "Stats",
|
||||||
|
tabBarIcon: ({ color, size }) => (
|
||||||
|
<FontAwesome name="bar-chart" size={size} color={color}/>),
|
||||||
|
}
|
||||||
|
}/>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,21 @@
|
||||||
import { Text, StyleSheet } from 'react-native';
|
import { StyleSheet } from 'react-native';
|
||||||
|
import { View, Text } from "../components/themed-components";
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<Text style={styles.lightThemeText}>Home Page</Text>
|
<View>
|
||||||
|
<Text>Home</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
lightThemeText: {
|
container: {
|
||||||
color: "#242c40"
|
flex: 1,
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
},
|
},
|
||||||
darkThemeText: {
|
text: {
|
||||||
color: "#d0d0c0"
|
color: "#ffffff",
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
47
components/themed-components.tsx
Normal file
47
components/themed-components.tsx
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
import { Text as DefaultText, View as DefaultView, useColorScheme} from "react-native";
|
||||||
|
import colors from "../constants/colors";
|
||||||
|
|
||||||
|
type ThemeProperties = {
|
||||||
|
lightColor?: string;
|
||||||
|
darkColor?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is a TypeScript intersection type encompassing both ThemeProperties and DefaultReactComponent properties.
|
||||||
|
*/
|
||||||
|
export type TextProperties = ThemeProperties & DefaultText["props"];
|
||||||
|
export type ViewProperties = ThemeProperties & DefaultView["props"];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function 'useThemeColor' allows you to apply different colors for light and dark theme mode in a React Native application.
|
||||||
|
* The function takes a 'properties' object (with possible 'light' and 'dark' properties representing color strings) and 'colorName' - a key from predefined colors for both 'light' and 'dark' mode.
|
||||||
|
* The function first checks the current color scheme using the 'useColorScheme' hook from React Native, defaulting to 'light' mode if none is defined.
|
||||||
|
* If no color is specified in 'properties' for current theme, the function falls back to returning a color corresponding to the provided 'colorName' from the predefined 'colors' object for the current theme.
|
||||||
|
*/
|
||||||
|
export function useThemeColor(
|
||||||
|
properties: {light?: string, dark?: string},
|
||||||
|
colorName: keyof typeof colors.light & keyof typeof colors.dark
|
||||||
|
) {
|
||||||
|
const theme = useColorScheme() ?? "light";
|
||||||
|
const colorFromProps = properties[theme];
|
||||||
|
|
||||||
|
if(colorFromProps) {
|
||||||
|
return colorFromProps;
|
||||||
|
}
|
||||||
|
return colors[theme][colorName];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Text(properties: TextProperties) {
|
||||||
|
const { style, lightColor, darkColor, ...otherProps } = properties;
|
||||||
|
const color = useThemeColor({ light: lightColor, dark: darkColor }, "color");
|
||||||
|
|
||||||
|
return <DefaultText style={[{ color }, style]} {...otherProps} />
|
||||||
|
}
|
||||||
|
|
||||||
|
export function View(properties: TextProperties) {
|
||||||
|
const { style, lightColor, darkColor, ...otherProps } = properties;
|
||||||
|
const backgroundColor = useThemeColor({ light: lightColor, dark: darkColor }, "backgroundColor");
|
||||||
|
|
||||||
|
return <DefaultView style={[{backgroundColor}, style]} {...otherProps}/>
|
||||||
|
}
|
||||||
18
constants/colors.ts
Normal file
18
constants/colors.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
export default {
|
||||||
|
light: {
|
||||||
|
tabIconDefault: "",
|
||||||
|
tabIconSelected: "",
|
||||||
|
color: "#15616d",
|
||||||
|
contrastColor: "",
|
||||||
|
accentColor: "",
|
||||||
|
backgroundColor: "#ffecd1",
|
||||||
|
},
|
||||||
|
dark: {
|
||||||
|
tabIconDefault: "",
|
||||||
|
tabIconSelected: "",
|
||||||
|
color: "#1B9AAA",
|
||||||
|
contrastColor: "",
|
||||||
|
accentColor: "",
|
||||||
|
backgroundColor: "#050505",
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in a new issue