import { Text, View, TextInput, Pressable, ScrollView, Alert, TouchableHighlight,…
- User
import { Text, View, TextInput, Pressable, ScrollView, Alert, TouchableHighlight, TouchableOpacity } from 'react-native'; import { gStyle } from '../styles/style'; import Header from '../components/Header'; import Footer from '../components/Footer'; import { useNavigation } from '@react-navigation/native'; import { firebase } from '../Firebase/firebase'; import 'firebase/compat/auth'; import 'firebase/compat/database'; import 'firebase/compat/firestore'; import React, {useState} from 'react';
export default function Auth() { const navigation = useNavigation(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const handleLogin = () => { firebase.auth().signInWithEmailAndPassword(email, password) .then((userCredential) => { const user = userCredential.user; console.log('Пользователь вошел:', user.email); }) .catch((error) => { const errorMessage = error.message; console.log(errorMessage); Alert.alert('Ошибка!', errorMessage); }); };
const handleResetPassword =()=>{ firebase.auth().sendPasswordResetEmail(email) .then(()=>{ Alert.alert('Успешно!','Письмо с инструкцией отправлено на указанную почту') }) .catch((error)=>{ const errorMessage=error.message; console.log(errorMessage); Alert.alert('Ошибка!',errorMessage); }) }return (
<Text style={gStyle.header}>Войти в личный{"\n"}кабинет</Text> <View style={gStyle.AuthContainer}> <View style={gStyle.AuthBox}> <View style={gStyle.AuthBox1}> <Text style={gStyle.AuthName}>Почта</Text> <TextInput style={gStyle.AuthInfo} onChangeText={setEmail} /> </View> <View style={gStyle.AuthBox1}> <Text style={gStyle.AuthName}>Пароль</Text> <TextInput style={gStyle.AuthInfo} onChangeText={setPassword} secureTextEntry={true} /> </View> </View> <Pressable style={gStyle.AuthForgotPassword} onPress={()=>navigation.navigate('ResetPassword')} > <Text style={gStyle.AuthPass}>Забыли пароль?</Text> </Pressable> <TouchableOpacity style={gStyle.AuthLogin} onPress={handleLogin}> <Text style={gStyle.AuthBtnLogin}>Войти</Text> </TouchableOpacity> <Pressable onPress={()=>navigation.navigate('Registration')} > <Text style={gStyle.AuthRegistr}>Я не зарегистрирован(а)</Text> </Pressable> </View> </View> <Footer/> </ScrollView> </View>); }
how can i do redirect on screen Home if user logged in correctly?
- Assistant
You can use the
useNavigationhook to navigate to the Home screen after a successful login. You can do this by calling thenavigatemethod on the navigation object after thesignInWithEmailAndPasswordmethod resolves successfully.Here's an example:
import { useNavigation } from '@react-navigation/native'; function Auth() { const navigation = useNavigation(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const handleLogin = () => { firebase.auth().signInWithEmailAndPassword(email, password) .then((userCredential) => { const user = userCredential.user; console.log('Пользователь вошел:', user.email); // Navigate to Home screen on successful login navigation.navigate('Home'); }) .catch((error) => { const errorMessage = error.message; console.log(errorMessage); Alert.alert('Ошибка!', errorMessage); }); }; // rest of the component code }This will navigate the user to the Home screen when the
signInWithEmailAndPasswordmethod resolves successfully. - User
import { SafeAreaView} from 'react-native'; import * as Font from 'expo-font'; import { Navigation } from './app/Navigation'; import AppLoading from 'expo-app-loading'; import React, {useState} from 'react';
const fonts = ()=> Font.loadAsync({ 'multi':require('./app/assets/fonts/MultiroundPro.otf'), 'yu-reg':require('./app/assets/fonts/YuGothicUIRegular.ttf'), 'yu-semibold':require('./app/assets/fonts/YuGothicUISemibold.ttf') });
export default function App() { const [font, setFont]=useState(false); if(font){ return ( <SafeAreaView style={{ flex: 1 }}> ); }else{ return( <AppLoading startAsync={fonts} onFinish={()=>setFont(true)} onError={console.warn}/> ) }
};
it says if this is a custom font be sure to load it with Font.loadAsync. Can u help me please?
- Assistant
The error message is indicating that you need to load the custom fonts using the
Font.loadAsync()method before rendering any component that uses the custom fonts. In your code, the custom fonts are already being loaded using thefonts()function, which is being called in theAppLoadingcomponent.However, you are not using the loaded fonts correctly in your components. To use the loaded fonts, you need to specify the font family name which you set while loading the fonts using
Font.loadAsync()method. In your case, the font family name for 'multi' font is 'Multi' (capital M) and for the Yu Gothic UI Regular and Semibold fonts, the font family names are 'Yu Gothic UI' and 'Yu Gothic UI Semibold', respectively.Here is an example of how you can use the loaded custom fonts in your components:
- User
- Assistant
You can conditionally render the
Забронированные мастер-классыblock based on whether thebookedMKstate array has any elements or is empty using a ternary operator.Here's an example:
<View style={gStyle.ProfilePaidMK}> {bookedMK.length > 0 ? ( <> <Text style={gStyle.ProfilePaid}>Забронированные{'\n'}мастер-классы</Text> <Text style={gStyle.ProfileLine}></Text> {bookedMK.map((mk, index)=>( <BookedMK key={mk.index} mk={mk} userId={userId} onDelete={handleDeleteBookedMK} index={index} /> ))} </> ) : null} </View>In this example, the
Забронированные мастер-классыblock including its child components will only be rendered if thebookedMKarray contains elements. IfbookedMKis empty, no block will be rendered.I hope this helps!
- User
u r the best! i understand what u r writing and i appreciate that! Thank u a lot, u r my saviour!
- Assistant
You're welcome! It's great to hear that my explanations were helpful to you. Don't hesitate to ask if you have any other questions. I'm always here to help!
- User
okay, how can i make search screen where a can search in 2 collections? First FutureMK the second PastMK, and i need to show image, title and description (150symbols)
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.