form.tsx 4.0 KB

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