Voici votre URL de partage https://sharemycode.io/c/20b7bf1 (Cliquer pour copier) (Copié)

import React, { useState, useEffect } from 'react'
import { StyleSheet, Button, Image } from 'react-native';
import DateTimePicker from '@react-native-community/datetimepicker';
import { Text, View } from '../components/Themed';
import * as ImagePicker from 'expo-image-picker';
import AsyncStorage from '@react-native-async-storage/async-storage';

export default function ModalScreen() {
  const [date, setDate] = useState(new Date(1669282586000));
  const [mode, setMode] = useState('date');
  const [show, setShow] = useState(false);
  const [image, setImage] = useState('');

  useEffect(() => {
    getData(),
  []
});

  const storeData = async (value) => {
    try {
      await AsyncStorage.setItem('profilpic', value)
    } catch (e) {
      // saving error
    }
  }
  const getData = async () => {
    try {
      const value = await AsyncStorage.getItem('profilpic')
      if(value !== null) {
        console.log(value)
      }
    } catch(e) {
      // error reading value
    }
  }
  
  const onChange = (event, selectedDate) => {
    const currentDate = selectedDate;
    setShow(false); 
    setDate(currentDate);
  }
  const pickImage = async () => {
    // No permissions request is necessary for launching the image library
    let result = await ImagePicker.launchImageLibraryAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.All,
      allowsEditing: true,
      aspect: [4, 3],
      quality: 1,
    });
    
    if (!result.canceled) {
      setImage(result.assets[0].uri);
      storeData(result.assets[0].uri);
    }
  }
  return (
    <View style={styles.container}>

      <Text style={styles.title}></Text>
      <Text>Quel est votre date de naissance ?</Text>
      <DateTimePicker
          testID="dateTimePicker"
          value={date}
          mode= "date"
          is24Hour={true}
          onChange={onChange}
        />
        <Text>Tu es né le : {date.toLocaleString()}</Text>

        
      <Button 
      title="Importer une photo depuis ma gallerie" 
      onPress={pickImage} 
      />
      {image && <Image source={{ uri: image }} style={{ width: 200, height: 200, borderRadius: 50 }} />}
    </View>

  );
  }




const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  title: {
    fontSize: 20,
    fontWeight: 'bold',
  },
  separator: {
    marginVertical: 30,
    height: 1,
    width: '80%',
  },
  date: {
    fontSize: 20,
    
  }
});

Informations

Cet extrait a été créé le 24 nov. 2022 à 15:21:58

Cet extrait expire le 24 déc. 2022 à 15:21:58

Langage : javascript

Logo javascript

Link

Voici votre URL de partage : https://sharemycode.io/c/20b7bf1 Copié

Demander la suppression