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 React from 'react';
|
||||||
import { Stack } from 'expo-router';
|
import { Stack } from 'expo-router';
|
||||||
import { StyleSheet, TextInput, TouchableOpacity } from 'react-native';
|
import { StyleSheet, TouchableOpacity } from 'react-native';
|
||||||
import { router } from 'expo-router';
|
import { router } from 'expo-router';
|
||||||
import DeviceInfo from 'react-native-device-info';
|
import DeviceInfo from 'react-native-device-info';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
@ -15,6 +15,7 @@ import { Message } from '@/lib/services/message';
|
||||||
import { Request } from '@/lib/services/request';
|
import { Request } from '@/lib/services/request';
|
||||||
import { store } from '@/lib/store/store';
|
import { store } from '@/lib/store/store';
|
||||||
import { setSession } from '@/lib/store/dataStore';
|
import { setSession } from '@/lib/store/dataStore';
|
||||||
|
import ThemedInput from '@/lib/components/ThemedInput';
|
||||||
|
|
||||||
export default function OnboardStartScreen() {
|
export default function OnboardStartScreen() {
|
||||||
const colorScheme = useColorScheme() ?? 'light';
|
const colorScheme = useColorScheme() ?? 'light';
|
||||||
|
@ -67,33 +68,30 @@ export default function OnboardStartScreen() {
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
|
|
||||||
<ThemedView style={styles.inputContainer}>
|
<ThemedView style={styles.inputContainer}>
|
||||||
<ThemedText>{t( "onboarding.your-name" )}</ThemedText>
|
<ThemedInput
|
||||||
<TextInput
|
label={t( "onboarding.your-name" )}
|
||||||
style={styles.input}
|
|
||||||
onChangeText={setName}
|
|
||||||
placeholder={t( "onboarding.name" )}
|
placeholder={t( "onboarding.name" )}
|
||||||
|
onChangeText={setName}
|
||||||
value={name}
|
value={name}
|
||||||
|
style={{paddingTop: 20}}
|
||||||
/>
|
/>
|
||||||
</ThemedView>
|
|
||||||
|
|
||||||
<ThemedView style={styles.inputContainer}>
|
<ThemedInput
|
||||||
<ThemedText>{t( "onboarding.your-address" )}</ThemedText>
|
label={t( "onboarding.your-address" )}
|
||||||
<TextInput
|
|
||||||
style={styles.input}
|
|
||||||
onChangeText={setZipcode}
|
|
||||||
placeholder={t( "onboarding.zipcode" )}
|
placeholder={t( "onboarding.zipcode" )}
|
||||||
|
onChangeText={setZipcode}
|
||||||
value={zipcode}
|
value={zipcode}
|
||||||
|
style={{paddingTop: 20}}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
|
||||||
style={styles.input}
|
<ThemedInput
|
||||||
onChangeText={setHouseNumber}
|
|
||||||
placeholder={t( "onboarding.house-number" )}
|
placeholder={t( "onboarding.house-number" )}
|
||||||
|
onChangeText={setHouseNumber}
|
||||||
value={houseNumber}
|
value={houseNumber}
|
||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
/>
|
/>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
|
|
||||||
|
|
||||||
<TouchableOpacity style={{ ...styles.button, backgroundColor: Colors[ colorScheme ].tint }} onPress={start}>
|
<TouchableOpacity style={{ ...styles.button, backgroundColor: Colors[ colorScheme ].tint }} onPress={start}>
|
||||||
<ThemedText style={{ color: Colors.white }}>
|
<ThemedText style={{ color: Colors.white }}>
|
||||||
{t( "onboarding.start" )}
|
{t( "onboarding.start" )}
|
||||||
|
@ -118,15 +116,7 @@ const styles = StyleSheet.create( {
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
inputContainer: {
|
inputContainer: {
|
||||||
paddingTop: 20,
|
|
||||||
},
|
|
||||||
input: {
|
|
||||||
width: 250,
|
width: 250,
|
||||||
borderWidth: 1,
|
|
||||||
padding: 10,
|
|
||||||
paddingLeft: 20,
|
|
||||||
borderRadius: 3,
|
|
||||||
marginBottom: 10,
|
|
||||||
},
|
},
|
||||||
button: {
|
button: {
|
||||||
borderRadius: 5,
|
borderRadius: 5,
|
||||||
|
|
|
@ -223,6 +223,7 @@ export default function SettingsScreen() {
|
||||||
fields={[
|
fields={[
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
|
title: t( "modal.name.name" ),
|
||||||
placeholder: t( "modal.name.your-name" ),
|
placeholder: t( "modal.name.your-name" ),
|
||||||
defaultValue: name,
|
defaultValue: name,
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,14 +2,14 @@ import React, { useEffect } from 'react';
|
||||||
import { Redirect, useRouter } from 'expo-router';
|
import { Redirect, useRouter } from 'expo-router';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import '@/lib/localization/i18n';
|
||||||
|
|
||||||
import { ThemedText } from '@/lib/components/ThemedText';
|
import { ThemedText } from '@/lib/components/ThemedText';
|
||||||
import { ThemedView } from '@/lib/components/ThemedView';
|
import { ThemedView } from '@/lib/components/ThemedView';
|
||||||
import { useToken } from '@/lib/context/AppProvider';
|
import { useToken } from '@/lib/context/AppProvider';
|
||||||
import { Request } from '@/lib/services/request';
|
import { Request } from '@/lib/services/request';
|
||||||
import { store } from '@/lib/store/store';
|
import { store } from '@/lib/store/store';
|
||||||
import { setSession } from '@/lib/store/dataStore';
|
import { setSession } from '@/lib/store/dataStore';
|
||||||
import '@/lib/localization/i18n';
|
|
||||||
|
|
||||||
|
|
||||||
export default function OnboardStartScreen() {
|
export default function OnboardStartScreen() {
|
||||||
const { token, isLoading } = useToken();
|
const { token, isLoading } = useToken();
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
"modal": {
|
"modal": {
|
||||||
"name": {
|
"name": {
|
||||||
"title": "Change name",
|
"title": "Change name",
|
||||||
|
"name": "Name",
|
||||||
"your-name": "Your name"
|
"your-name": "Your name"
|
||||||
},
|
},
|
||||||
"address": {
|
"address": {
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
"modal": {
|
"modal": {
|
||||||
"name": {
|
"name": {
|
||||||
"title": "Naam wijzigen",
|
"title": "Naam wijzigen",
|
||||||
|
"name": "Naam",
|
||||||
"your-name": "Je naam"
|
"your-name": "Je naam"
|
||||||
},
|
},
|
||||||
"address": {
|
"address": {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { Colors } from '@/lib/constants/Colors';
|
||||||
import { ThemedView } from '@/lib/components/ThemedView';
|
import { ThemedView } from '@/lib/components/ThemedView';
|
||||||
import { ThemedText } from '@/lib/components/ThemedText';
|
import { ThemedText } from '@/lib/components/ThemedText';
|
||||||
import { useColorScheme } from '@/lib/hooks/useColorScheme';
|
import { useColorScheme } from '@/lib/hooks/useColorScheme';
|
||||||
|
import ThemedInput from '@/lib/components/ThemedInput';
|
||||||
|
|
||||||
interface Field {
|
interface Field {
|
||||||
name: string;
|
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>
|
<ThemedText style={styles.text}>{title ? title : t( "modal.default.title" )}</ThemedText>
|
||||||
|
|
||||||
{fields.map( (field, index) => (
|
{fields.map( (field, index) => (
|
||||||
<ThemedView key={index} style={styles.inputContainer}>
|
<ThemedInput
|
||||||
{field.title && <ThemedText style={styles.inputTitle}>{field.title}</ThemedText>}
|
key={index}
|
||||||
<TextInput
|
label={field.title}
|
||||||
style={[ styles.input, { color: Colors[ colorScheme ].text } ]}
|
onChangeText={(text) => handleInputChange( field.name, text )}
|
||||||
placeholder={field.placeholder}
|
value={inputValues[ field.name ] || ''}
|
||||||
onChangeText={(text) => handleInputChange( field.name, text )}
|
placeholder={field.placeholder}
|
||||||
value={inputValues[ field.name ] || ''}
|
/>
|
||||||
placeholderTextColor={Colors[ colorScheme ].text}
|
|
||||||
/>
|
|
||||||
</ThemedView>
|
|
||||||
|
|
||||||
) )}
|
) )}
|
||||||
|
|
||||||
<ThemedView style={styles.buttonContainer}>
|
<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