form.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { useState } from 'react';
  2. import { View, Text, StyleSheet, TouchableWithoutFeedback, Keyboard, Pressable } from 'react-native';
  3. import ResetSuccessful from './formPages/resetSuccessful';
  4. import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
  5. import ForgetPasswordPage from './formPages/forgetPasswordPage';
  6. import { forgetPasswordFormData } from '../../../types/signup';
  7. import PaginationIndicator from '../../global/PaginationIndicator';
  8. import { router } from 'expo-router';
  9. import { useTranslation } from '../../../util/hooks/useTranslation';
  10. type ForgetPasswordFormProps = {
  11. forgetPasswordFormData: forgetPasswordFormData;
  12. setForgetPasswordFormData: React.Dispatch<React.SetStateAction<forgetPasswordFormData>>;
  13. };
  14. const ForgetPasswordForm: React.FC<ForgetPasswordFormProps> = ({
  15. forgetPasswordFormData,
  16. setForgetPasswordFormData
  17. }) => {
  18. const { t } = useTranslation(); // 使用翻译钩子
  19. const [screen, setScreen] = useState<number>(0);
  20. const FormTitle = [t('forgotPassword.phone_verification')];
  21. const goToPreviousPage = () => {
  22. if (router.canGoBack()) {
  23. router.back();
  24. } else {
  25. router.replace('/(public)/login');
  26. }
  27. };
  28. const ScreenDisplay = () => {
  29. switch (screen) {
  30. case 0:
  31. return (
  32. <ForgetPasswordPage
  33. forgetPasswordFormData={forgetPasswordFormData}
  34. setForgetPasswordFormData={setForgetPasswordFormData}
  35. setScreen={setScreen}
  36. />
  37. );
  38. case 1:
  39. return <ResetSuccessful />;
  40. default:
  41. return <></>;
  42. }
  43. };
  44. return (
  45. <>
  46. <KeyboardAwareScrollView
  47. enableOnAndroid={true}
  48. resetScrollToCoords={{ x: 0, y: 0 }}
  49. style={{
  50. height: '100%'
  51. }}
  52. >
  53. {screen === 0 && (
  54. <View style={styles.topContainer}>
  55. <Text style={styles.text}>{FormTitle[screen]}</Text>
  56. <View style={styles.breakline} />
  57. <View className="w-full flex-row justify-between items-center">
  58. <Pressable onPress={goToPreviousPage} className="flex-1">
  59. <Text
  60. style={{
  61. color: '#888888',
  62. fontSize: 18,
  63. paddingLeft: 25
  64. }}
  65. >{t('common.previous')}</Text>
  66. </Pressable>
  67. <PaginationIndicator totalPages={2} currentPage={0} />
  68. <View className="flex-1" />
  69. </View>
  70. </View>
  71. )}
  72. <View style={styles.bottomContainer}>{ScreenDisplay()}</View>
  73. </KeyboardAwareScrollView>
  74. </>
  75. );
  76. };
  77. const styles = StyleSheet.create({
  78. topContainer: {
  79. flex: 1,
  80. alignItems: 'center',
  81. justifyContent: 'center',
  82. paddingBottom: '25%',
  83. paddingTop: '15%'
  84. },
  85. previouspageAndPaginationWrapper: {
  86. display: 'flex',
  87. width: '100%',
  88. flexDirection: 'row',
  89. justifyContent: 'space-between',
  90. alignItems: 'center',
  91. paddingHorizontal: 25
  92. },
  93. bottomContainer: { flex: 1 },
  94. breakline: {
  95. width: 24,
  96. height: 1,
  97. backgroundColor: '#000000',
  98. marginVertical: 17
  99. },
  100. text: { fontSize: 24, fontWeight: '300' }
  101. });
  102. export default ForgetPasswordForm;