Init commit. Rewrite of old project. Not done
This commit is contained in:
69
components/theme/Theme.tsx
Normal file
69
components/theme/Theme.tsx
Normal file
@ -0,0 +1,69 @@
|
||||
import { View, type ViewProps } from 'react-native';
|
||||
import { Text, type TextProps, StyleSheet } from 'react-native';
|
||||
import { useThemeColor } from '@/hooks/useThemeColor';
|
||||
|
||||
export type ThemedViewProps = ViewProps & {
|
||||
lightColor?: string;
|
||||
darkColor?: string;
|
||||
};
|
||||
export type ThemedTextProps = TextProps & {
|
||||
lightColor?: string;
|
||||
darkColor?: string;
|
||||
type?: 'default' | 'title' | 'defaultSemiBold' | 'subtitle' | 'link';
|
||||
};
|
||||
|
||||
export function ThemedView({ style, lightColor, darkColor, ...otherProps }: ThemedViewProps) {
|
||||
const backgroundColor = useThemeColor({ light: lightColor, dark: darkColor }, 'background');
|
||||
return <View style={[{ backgroundColor }, style]} {...otherProps} />;
|
||||
}
|
||||
|
||||
export function ThemedText({
|
||||
style,
|
||||
lightColor,
|
||||
darkColor,
|
||||
type = 'default',
|
||||
...rest
|
||||
}: ThemedTextProps) {
|
||||
const color = useThemeColor({ light: lightColor, dark: darkColor }, 'text');
|
||||
|
||||
return (
|
||||
<Text
|
||||
style={[
|
||||
{ color },
|
||||
type === 'default' ? styles.default : undefined,
|
||||
type === 'title' ? styles.title : undefined,
|
||||
type === 'defaultSemiBold' ? styles.defaultSemiBold : undefined,
|
||||
type === 'subtitle' ? styles.subtitle : undefined,
|
||||
type === 'link' ? styles.link : undefined,
|
||||
style,
|
||||
]}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
default: {
|
||||
fontSize: 16,
|
||||
lineHeight: 24,
|
||||
},
|
||||
defaultSemiBold: {
|
||||
fontSize: 16,
|
||||
lineHeight: 24,
|
||||
fontWeight: '600',
|
||||
},
|
||||
title: {
|
||||
fontSize: 32,
|
||||
fontWeight: 'bold',
|
||||
lineHeight: 32,
|
||||
},
|
||||
subtitle: {
|
||||
fontSize: 20,
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
link: {
|
||||
lineHeight: 30,
|
||||
fontSize: 16,
|
||||
color: '#0a7ea4',
|
||||
},
|
||||
});
|
55
components/theme/buttons/DefaultButton.tsx
Normal file
55
components/theme/buttons/DefaultButton.tsx
Normal file
@ -0,0 +1,55 @@
|
||||
import { StyleSheet, Pressable } from "react-native";
|
||||
import { ThemedView } from "@/components/theme/Theme";
|
||||
import { Colors } from '@/constants/Colors';
|
||||
import { useColorScheme } from '@/hooks/useColorScheme';
|
||||
|
||||
const DEFAULT_WIDTH = 320;
|
||||
const DEFAULT_HEIGHT = 68;
|
||||
|
||||
type Props = {
|
||||
width?: number;
|
||||
height?: number;
|
||||
onPress?: () => void;
|
||||
};
|
||||
|
||||
const Button = ({ width, height, children, onPress }: Props & React.ComponentProps<typeof Pressable>) => {
|
||||
const scheme = useColorScheme() ?? 'dark';
|
||||
return (
|
||||
<ThemedView
|
||||
style={[
|
||||
styles.buttonContainer,
|
||||
{
|
||||
width: (width ?? DEFAULT_WIDTH),
|
||||
height: (height ?? DEFAULT_HEIGHT),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Pressable
|
||||
style={[
|
||||
styles.button,
|
||||
{backgroundColor: Colors[scheme].text}
|
||||
]}
|
||||
onPress={onPress}
|
||||
>
|
||||
{children}
|
||||
</Pressable>
|
||||
</ThemedView>
|
||||
);
|
||||
};
|
||||
export default Button;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
buttonContainer: {
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
padding: 3,
|
||||
},
|
||||
button: {
|
||||
borderRadius: 10,
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
flexDirection: 'row',
|
||||
},
|
||||
});
|
37
components/theme/buttons/TextButton.tsx
Normal file
37
components/theme/buttons/TextButton.tsx
Normal file
@ -0,0 +1,37 @@
|
||||
import Button from '@/components/theme/buttons/DefaultButton';
|
||||
import { ThemedText } from "@/components/theme/Theme";
|
||||
import { Colors } from '@/constants/Colors';
|
||||
import { useColorScheme } from '@/hooks/useColorScheme';
|
||||
|
||||
const DEFAULT_FONT_SIZE = 16;
|
||||
|
||||
type Props = {
|
||||
width?: number;
|
||||
height?: number;
|
||||
text: string;
|
||||
fontSize?: number;
|
||||
onPress?: () => void;
|
||||
};
|
||||
|
||||
const TextButton = ({ width, height, text, fontSize, onPress }: Props ) => {
|
||||
const scheme = useColorScheme() ?? 'dark';
|
||||
return (
|
||||
<Button
|
||||
width={width}
|
||||
height={height}
|
||||
onPress={onPress}
|
||||
>
|
||||
<ThemedText
|
||||
style={[
|
||||
{
|
||||
color: Colors[scheme].text,
|
||||
fontSize: fontSize ?? DEFAULT_FONT_SIZE
|
||||
}
|
||||
]}
|
||||
>
|
||||
{text}
|
||||
</ThemedText>
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
export default TextButton;
|
Reference in New Issue
Block a user