Move files to lib folder

This commit is contained in:
Maarten 2024-08-08 14:22:02 +02:00
parent d8d8ac35f8
commit cec664c8d0
26 changed files with 58 additions and 59 deletions

View file

@ -0,0 +1,148 @@
import React, { useEffect, useState } from 'react';
import {
TextInput,
TouchableOpacity,
StyleSheet,
} from 'react-native';
import Modal from "react-native-modal";
import { Colors } from '@/constants/Colors';
import { ThemedView } from '@/components/ThemedView';
import { ThemedText } from '@/components/ThemedText';
import { useColorScheme } from '@/hooks/useColorScheme';
interface Field {
name: string;
title?: string;
placeholder: string;
defaultValue?: string;
}
interface EditModalProps {
title?: string;
visible: boolean;
onClose?: () => void;
onSave: (inputValues: Record<string, string>) => void;
fields: Field[];
}
const CustomModal: React.FC<EditModalProps> = ({ title, visible, onClose, onSave, fields }) => {
const colorScheme = useColorScheme() ?? 'light';
const [ inputValues, setInputValues ] = useState<Record<string, string>>( {} );
useEffect( () => {
const initialValues: Record<string, string> = {};
fields.forEach( field => {
if (field.defaultValue) {
initialValues[ field.name ] = field.defaultValue;
}
} );
setInputValues( initialValues );
}, [ fields ] );
const handleInputChange = (name: string, value: string) => {
setInputValues( { ...inputValues, [ name ]: value } );
};
const handleSave = () => {
onSave( inputValues );
if (onClose) onClose();
};
return (
<Modal isVisible={visible}>
<ThemedView style={{ ...styles.view, backgroundColor: Colors[ colorScheme ].background }}>
<ThemedText style={styles.text}>{title ? title : 'Pas je gegevens aan:'}</ThemedText>
{fields.map( (field, index) => (
<ThemedView key={index} style={styles.inputContainer}>
{field.title && <ThemedText style={styles.inputTitle}>{field.title}</ThemedText>}
<TextInput
style={styles.input}
placeholder={field.placeholder}
onChangeText={(text) => handleInputChange( field.name, text )}
value={inputValues[ field.name ] || ''}
/>
</ThemedView>
) )}
<ThemedView style={styles.buttonContainer}>
<TouchableOpacity onPress={onClose || ( () => {
} )}>
<ThemedText style={[ styles.textStyle, styles.buttonClose ]}>Annuleren</ThemedText>
</TouchableOpacity>
<TouchableOpacity style={styles.buttonSave} onPress={handleSave}>
<ThemedText style={styles.textStyle}>Opslaan</ThemedText>
</TouchableOpacity>
</ThemedView>
</ThemedView>
</Modal>
);
};
const styles = StyleSheet.create( {
view: {
margin: 25,
borderRadius: 10,
paddingTop: 30,
paddingBottom: 30,
paddingLeft: 35,
paddingRight: 35,
alignItems: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
},
text: {
marginBottom: 15,
textAlign: 'center',
},
inputContainer: {
width: '100%',
marginBottom: 15,
},
inputTitle: {
fontSize: 16,
marginBottom: 5,
},
input: {
height: 40,
borderColor: 'gray',
borderWidth: 1,
width: '100%',
paddingHorizontal: 10,
borderRadius: 5,
},
buttonContainer: {
marginTop: 20,
flexDirection: 'row',
justifyContent: 'space-between',
width: '100%',
},
buttonClose: {
color: Colors.red,
paddingTop: 8,
},
buttonSave: {
backgroundColor: Colors.tint,
borderRadius: 5,
paddingTop: 10,
paddingBottom: 10,
paddingLeft: 40,
paddingRight: 40,
},
textStyle: {
color: 'white',
fontWeight: 'bold',
textAlign: 'center',
},
} );
export default CustomModal;

31
lib/components/List.tsx Normal file
View file

@ -0,0 +1,31 @@
import React from 'react';
import {ViewStyle} from 'react-native';
import {ThemedView} from '@/components/ThemedView';
interface ListProps {
data: any;
renderItem: Function;
viewStyle?: ViewStyle;
}
const CustomList: React.FC<ListProps> = ({ data, renderItem, viewStyle }) => {
const renderList = () => {
let list: any[] = [];
for (let i = 0; i < data.length; i++) {
const item = data[i];
list[i] = renderItem(item, i);
}
return list;
};
return (
<ThemedView style={viewStyle ? viewStyle : undefined}>
{renderList()}
</ThemedView>
);
};
export default CustomList;

View file

@ -0,0 +1,60 @@
import { Text, type TextProps, StyleSheet } from 'react-native';
import { useThemeColor } from '@/hooks/useThemeColor';
export type ThemedTextProps = TextProps & {
lightColor?: string;
darkColor?: string;
type?: 'default' | 'title' | 'defaultSemiBold' | 'subtitle' | 'link';
};
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',
},
});

View file

@ -0,0 +1,14 @@
import { View, type ViewProps } from 'react-native';
import { useThemeColor } from '@/hooks/useThemeColor';
export type ThemedViewProps = ViewProps & {
lightColor?: string;
darkColor?: string;
};
export function ThemedView({ style, lightColor, darkColor, ...otherProps }: ThemedViewProps) {
const backgroundColor = useThemeColor({ light: lightColor, dark: darkColor }, 'background');
return <View style={[{ backgroundColor }, style]} {...otherProps} />;
}

View file

@ -0,0 +1,10 @@
import * as React from 'react';
import renderer from 'react-test-renderer';
import { ThemedText } from '../ThemedText';
it(`renders correctly`, () => {
const tree = renderer.create(<ThemedText>Snapshot test!</ThemedText>).toJSON();
expect(tree).toMatchSnapshot();
});

View file

@ -0,0 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders correctly 1`] = `
<Text
style={
[
{
"color": "#11181C",
},
{
"fontSize": 16,
"lineHeight": 24,
},
undefined,
undefined,
undefined,
undefined,
undefined,
]
}
>
Snapshot test!
</Text>
`;

View file

@ -0,0 +1,9 @@
// You can (explore) the built-in icon families and icons on the web at https://icons.expo.fyi/
import Ionicons from '@expo/vector-icons/Ionicons';
import { type IconProps } from '@expo/vector-icons/build/createIconSet';
import { type ComponentProps } from 'react';
export function TabBarIcon({ style, ...rest }: IconProps<ComponentProps<typeof Ionicons>['name']>) {
return <Ionicons size={28} style={[style]} {...rest} />;
}