form.tsx 5.2 KB

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