I have built DateTimePicker into an InputField for my Android app, but the DateTimePicker by default takes the width of its content and not the total ready of the screen
import React, { useState, useEffect } from 'react';
import { View, TextInput, Button, Text, StyleSheet, TouchableOpacity, Dimensions } from 'react-native';
import DateTimePicker from '@react-native-community/datetimepicker';
const SCREEN_WIDTH = Dimensions.get('window').width;
const SignUpScreen = () => {
// ...
const handleDateChange = (event, selectedDate) => {
const currentDate = selectedDate || birthdate;
setShowDatePicker(false);
setBirthdate(currentDate);
};
// ...
return (
<View style={styles.container}>
<View style={styles.inputView}>
<InputField
label="Geburtsdatum"
value={birthdate}
onDateChange={() => setShowDatePicker(true)}
required
error={errors.birthdate}
/>
{showDatePicker && (
<DateTimePicker
style={{ width: SCREEN_WIDTH }} // Setze die Breite des DateTimePicker auf die Bildschirmbreite
value={birthdate}
mode="date"
display="spinner"
onChange={handleDateChange}
/>
)}
</View>
</View>
);
};
I want to display InputField of DateTimePicker on the total width, what should I do?
2
Answers
in this package ‘@react-native-community/datetimepicker’ style option is optional on IOS only.
check this link please:
https://www.npmjs.com/package/@react-native-community/datetimepicker#style-optional-ios-only
just find in those native code, you can see all the supported property:
from here
The second: This lib using native DatePickerIOS, so you better lets it’s choose the size automatically by system