Refactor to new ThemedInput component
This commit is contained in:
parent
f3c5667f0a
commit
0bfb70af8b
7 changed files with 90 additions and 36 deletions
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import { Stack } from 'expo-router';
|
||||
import { StyleSheet, TextInput, TouchableOpacity } from 'react-native';
|
||||
import { StyleSheet, TouchableOpacity } from 'react-native';
|
||||
import { router } from 'expo-router';
|
||||
import DeviceInfo from 'react-native-device-info';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
@ -15,6 +15,7 @@ import { Message } from '@/lib/services/message';
|
|||
import { Request } from '@/lib/services/request';
|
||||
import { store } from '@/lib/store/store';
|
||||
import { setSession } from '@/lib/store/dataStore';
|
||||
import ThemedInput from '@/lib/components/ThemedInput';
|
||||
|
||||
export default function OnboardStartScreen() {
|
||||
const colorScheme = useColorScheme() ?? 'light';
|
||||
|
@ -67,33 +68,30 @@ export default function OnboardStartScreen() {
|
|||
</ThemedView>
|
||||
|
||||
<ThemedView style={styles.inputContainer}>
|
||||
<ThemedText>{t( "onboarding.your-name" )}</ThemedText>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
onChangeText={setName}
|
||||
<ThemedInput
|
||||
label={t( "onboarding.your-name" )}
|
||||
placeholder={t( "onboarding.name" )}
|
||||
onChangeText={setName}
|
||||
value={name}
|
||||
style={{paddingTop: 20}}
|
||||
/>
|
||||
</ThemedView>
|
||||
|
||||
<ThemedView style={styles.inputContainer}>
|
||||
<ThemedText>{t( "onboarding.your-address" )}</ThemedText>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
onChangeText={setZipcode}
|
||||
<ThemedInput
|
||||
label={t( "onboarding.your-address" )}
|
||||
placeholder={t( "onboarding.zipcode" )}
|
||||
onChangeText={setZipcode}
|
||||
value={zipcode}
|
||||
style={{paddingTop: 20}}
|
||||
/>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
onChangeText={setHouseNumber}
|
||||
|
||||
<ThemedInput
|
||||
placeholder={t( "onboarding.house-number" )}
|
||||
onChangeText={setHouseNumber}
|
||||
value={houseNumber}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
</ThemedView>
|
||||
|
||||
|
||||
<TouchableOpacity style={{ ...styles.button, backgroundColor: Colors[ colorScheme ].tint }} onPress={start}>
|
||||
<ThemedText style={{ color: Colors.white }}>
|
||||
{t( "onboarding.start" )}
|
||||
|
@ -118,15 +116,7 @@ const styles = StyleSheet.create( {
|
|||
justifyContent: 'center',
|
||||
},
|
||||
inputContainer: {
|
||||
paddingTop: 20,
|
||||
},
|
||||
input: {
|
||||
width: 250,
|
||||
borderWidth: 1,
|
||||
padding: 10,
|
||||
paddingLeft: 20,
|
||||
borderRadius: 3,
|
||||
marginBottom: 10,
|
||||
},
|
||||
button: {
|
||||
borderRadius: 5,
|
||||
|
|
|
@ -223,6 +223,7 @@ export default function SettingsScreen() {
|
|||
fields={[
|
||||
{
|
||||
name: 'name',
|
||||
title: t( "modal.name.name" ),
|
||||
placeholder: t( "modal.name.your-name" ),
|
||||
defaultValue: name,
|
||||
},
|
||||
|
|
|
@ -2,14 +2,14 @@ import React, { useEffect } from 'react';
|
|||
import { Redirect, useRouter } from 'expo-router';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import '@/lib/localization/i18n';
|
||||
|
||||
import { ThemedText } from '@/lib/components/ThemedText';
|
||||
import { ThemedView } from '@/lib/components/ThemedView';
|
||||
import { useToken } from '@/lib/context/AppProvider';
|
||||
import { Request } from '@/lib/services/request';
|
||||
import { store } from '@/lib/store/store';
|
||||
import { setSession } from '@/lib/store/dataStore';
|
||||
import '@/lib/localization/i18n';
|
||||
|
||||
|
||||
export default function OnboardStartScreen() {
|
||||
const { token, isLoading } = useToken();
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
"modal": {
|
||||
"name": {
|
||||
"title": "Change name",
|
||||
"name": "Name",
|
||||
"your-name": "Your name"
|
||||
},
|
||||
"address": {
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
"modal": {
|
||||
"name": {
|
||||
"title": "Naam wijzigen",
|
||||
"name": "Naam",
|
||||
"your-name": "Je naam"
|
||||
},
|
||||
"address": {
|
||||
|
|
|
@ -11,6 +11,7 @@ import { Colors } from '@/lib/constants/Colors';
|
|||
import { ThemedView } from '@/lib/components/ThemedView';
|
||||
import { ThemedText } from '@/lib/components/ThemedText';
|
||||
import { useColorScheme } from '@/lib/hooks/useColorScheme';
|
||||
import ThemedInput from '@/lib/components/ThemedInput';
|
||||
|
||||
interface Field {
|
||||
name: string;
|
||||
|
@ -59,17 +60,13 @@ const CustomModal: React.FC<EditModalProps> = ({ title, visible, onClose, onSave
|
|||
<ThemedText style={styles.text}>{title ? title : t( "modal.default.title" )}</ThemedText>
|
||||
|
||||
{fields.map( (field, index) => (
|
||||
<ThemedView key={index} style={styles.inputContainer}>
|
||||
{field.title && <ThemedText style={styles.inputTitle}>{field.title}</ThemedText>}
|
||||
<TextInput
|
||||
style={[ styles.input, { color: Colors[ colorScheme ].text } ]}
|
||||
placeholder={field.placeholder}
|
||||
onChangeText={(text) => handleInputChange( field.name, text )}
|
||||
value={inputValues[ field.name ] || ''}
|
||||
placeholderTextColor={Colors[ colorScheme ].text}
|
||||
/>
|
||||
</ThemedView>
|
||||
|
||||
<ThemedInput
|
||||
key={index}
|
||||
label={field.title}
|
||||
onChangeText={(text) => handleInputChange( field.name, text )}
|
||||
value={inputValues[ field.name ] || ''}
|
||||
placeholder={field.placeholder}
|
||||
/>
|
||||
) )}
|
||||
|
||||
<ThemedView style={styles.buttonContainer}>
|
||||
|
|
64
lib/components/ThemedInput.tsx
Normal file
64
lib/components/ThemedInput.tsx
Normal file
|
@ -0,0 +1,64 @@
|
|||
import React from 'react';
|
||||
import { TextInput, StyleSheet, TextInputProps, StyleProp, TextStyle, ViewStyle } from 'react-native';
|
||||
import { ThemedView } from '@/lib/components/ThemedView';
|
||||
import { ThemedText } from '@/lib/components/ThemedText';
|
||||
import { Colors } from '@/lib/constants/Colors';
|
||||
import { useColorScheme } from '@/lib/hooks/useColorScheme';
|
||||
|
||||
interface InputComponentProps extends TextInputProps {
|
||||
label?: string;
|
||||
style?: StyleProp<ViewStyle>;
|
||||
inputStyle?: StyleProp<TextStyle>;
|
||||
}
|
||||
|
||||
const ThemedInput: React.FC<InputComponentProps> = ({
|
||||
label,
|
||||
placeholder,
|
||||
value,
|
||||
onChangeText,
|
||||
secureTextEntry = false,
|
||||
keyboardType = 'default',
|
||||
style,
|
||||
inputStyle,
|
||||
...props
|
||||
}) => {
|
||||
const colorScheme = useColorScheme() ?? 'light';
|
||||
|
||||
return (
|
||||
<ThemedView style={[ styles.container, style ]}>
|
||||
{label && <ThemedText style={styles.label}>{label}</ThemedText>}
|
||||
<TextInput
|
||||
style={[ styles.input, inputStyle, {
|
||||
color: Colors[ colorScheme ].text,
|
||||
borderColor: Colors[ colorScheme ].text
|
||||
} ]}
|
||||
placeholderTextColor={Colors[ colorScheme ].text}
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
onChangeText={onChangeText}
|
||||
secureTextEntry={secureTextEntry}
|
||||
keyboardType={keyboardType}
|
||||
{...props}
|
||||
/>
|
||||
</ThemedView>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create( {
|
||||
container: {
|
||||
width: '100%',
|
||||
},
|
||||
label: {
|
||||
marginBottom: 4,
|
||||
},
|
||||
input: {
|
||||
width: '100%',
|
||||
borderWidth: 1,
|
||||
padding: 10,
|
||||
paddingLeft: 20,
|
||||
borderRadius: 3,
|
||||
marginBottom: 10,
|
||||
},
|
||||
} );
|
||||
|
||||
export default ThemedInput;
|
Loading…
Add table
Add a link
Reference in a new issue