form.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { useState } from "react";
  2. import { View, Text, StyleSheet, Pressable, TouchableWithoutFeedback, Keyboard } from "react-native";
  3. import Verification from "./formPages/verification";
  4. import BasicInformation from "./formPages/basicInformation";
  5. import UberDriver from "./formPages/uberDriver";
  6. import CarInformation from "./formPages/carInformation";
  7. import PaginationIndicator from "../../global/PaginationIndicator";
  8. import CreateWallet from "./formPages/createWallet";
  9. import FinishSignUp from "./formPages/finishSignUp";
  10. import LoginPage from "./formPages/loginPage";
  11. import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
  12. type FormProps = {};
  13. const Form: React.FC<FormProps> = ({}) => {
  14. const [screen, setScreen] = useState<number>(0);
  15. const FormTitle = [
  16. "",
  17. "註冊 - 電話驗證",
  18. "註冊 - 基本資料",
  19. "註冊 - Uber Driver",
  20. "註冊 - 車輛資料",
  21. "註冊 - 設立銀包",
  22. ];
  23. const ScreenDisplay = () => {
  24. switch (screen) {
  25. case 0:
  26. return <LoginPage goToNextPage={goToNextPage} />;
  27. case 1:
  28. return <Verification setScreen={setScreen} />;
  29. case 2:
  30. return <BasicInformation goToNextPage={goToNextPage} />;
  31. case 3:
  32. return <UberDriver goToNextPage={goToNextPage} />;
  33. case 4:
  34. return <CarInformation goToNextPage={goToNextPage} />;
  35. case 5:
  36. return <CreateWallet goToNextPage={goToNextPage} />;
  37. case 6:
  38. return <FinishSignUp />;
  39. default:
  40. return <></>;
  41. }
  42. };
  43. const goToPreviousPage = () => {
  44. setScreen((prevState) => {
  45. if (prevState > 0) {
  46. return prevState - 1;
  47. } else {
  48. return prevState;
  49. }
  50. });
  51. };
  52. const goToNextPage = () => {
  53. setScreen((prevState) => {
  54. if (prevState < 6) {
  55. return prevState + 1;
  56. } else {
  57. return prevState;
  58. }
  59. });
  60. };
  61. return (
  62. <>
  63. <KeyboardAwareScrollView enableOnAndroid={true} resetScrollToCoords={{ x: 0, y: 0 }}>
  64. {/* not showing title and pagination on the first and last page */}
  65. {screen == 0 ||
  66. (screen < 6 && (
  67. //dismiss keyboard when user click outside of the input field to improve user experience
  68. <TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
  69. <View style={styles.topContainer}>
  70. <Text style={styles.text}>{FormTitle[screen]}</Text>
  71. <View style={styles.breakline} />
  72. <View style={styles.previouspageAndPaginationWrapper}>
  73. <Pressable onPress={goToPreviousPage}>
  74. <Text style={{ color: "#888888" }}>{`< 上一步`}</Text>
  75. </Pressable>
  76. <PaginationIndicator totalPages={FormTitle.length} currentPage={screen} />
  77. <Pressable disabled={true} onPress={goToNextPage}>
  78. <Text style={{ color: "#888888", opacity: 0 }}>{`下一步 >`}</Text>
  79. </Pressable>
  80. </View>
  81. </View>
  82. </TouchableWithoutFeedback>
  83. ))}
  84. <View style={styles.bottomContainer}>{ScreenDisplay()}</View>
  85. </KeyboardAwareScrollView>
  86. </>
  87. );
  88. };
  89. const styles = StyleSheet.create({
  90. topContainer: {
  91. flex: 1,
  92. alignItems: "center",
  93. justifyContent: "center",
  94. paddingBottom: "20%",
  95. paddingTop: "15%",
  96. },
  97. previouspageAndPaginationWrapper: {
  98. display: "flex",
  99. width: "100%",
  100. flexDirection: "row",
  101. justifyContent: "space-between",
  102. alignItems: "center",
  103. paddingHorizontal: 25,
  104. },
  105. bottomContainer: { flex: 2.5 },
  106. breakline: { width: 24, height: 1, backgroundColor: "#000000", marginVertical: 17 },
  107. text: { fontSize: 24, fontWeight: "300" },
  108. });
  109. export default Form;