Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. import React from "react";
  2. import { Text, View, StatusBar, Image } from "react-native";
  3. import styled from "styled-components";
  4. import { NavigationScreenProp, NavigationState } from 'react-navigation';
  5. import Swiper from 'react-native-swiper';
  6. import ProfileInputContainer from "../components/profile/ProfileInputContainer";
  7. import AvailableProgram from "../components/profile/AvailableProgram";
  8. import ConnectUtility from "../components/profile/ConnectUtility";
  9. interface NavigationParams {
  10. text: string;
  11. }
  12. type Navigation = NavigationScreenProp<NavigationState, NavigationParams>;
  13.  
  14. interface Props {
  15. navigation: Navigation;
  16. }
  17. interface State {
  18. firstName: string;
  19. lastName: string;
  20. locationName: string;
  21. zipcode: string;
  22. swipeIndex: number;
  23. }
  24.  
  25. export default class ProfileSetup extends React.Component<Props, State> {
  26. swiper: React.RefObject<any>;
  27.  
  28. constructor(props: Props) {
  29. super(props);
  30. this.swiper = React.createRef();
  31. this.state = {
  32. firstName: "",
  33. lastName: "",
  34. locationName: "",
  35. zipcode: "",
  36. swipeIndex: 0,
  37. }
  38. }
  39.  
  40. _onSendLinkPressed = () => {
  41. // TODO: set this.state.emailError a message if there is no email found from db.
  42. }
  43.  
  44. _onNext = () => {
  45. this.swiper.current.scrollBy(1);
  46. }
  47.  
  48. _renderPagination = (index: number, total: number) => {
  49. if (total <= 1) return null
  50.  
  51. let dots = [];
  52. const ActiveDot = (
  53. <View
  54. style={{
  55. backgroundColor: '#4a8e1f',
  56. width: 8,
  57. height: 8,
  58. borderRadius: 4,
  59. marginLeft: 3,
  60. marginRight: 3,
  61. marginTop: 3,
  62. marginBottom: 3
  63. }}
  64. />
  65. )
  66. const Dot = (
  67. <View
  68. style={{
  69. backgroundColor: 'rgba(0,0,0,.2)',
  70. width: 8,
  71. height: 8,
  72. borderRadius: 4,
  73. marginLeft: 3,
  74. marginRight: 3,
  75. marginTop: 3,
  76. marginBottom: 3
  77. }}
  78. />
  79. )
  80. for (let i = 0; i < total; i++) {
  81. dots.push(
  82. i <= index
  83. ? React.cloneElement(ActiveDot, { key: i })
  84. : React.cloneElement(Dot, { key: i })
  85. )
  86. }
  87.  
  88. return (
  89. <View
  90. pointerEvents="none"
  91. style={{
  92. position: 'absolute',
  93. bottom: "10%",
  94. left: 0,
  95. right: 0,
  96. flexDirection: 'row',
  97. flex: 1,
  98. justifyContent: 'center',
  99. alignItems: 'center',
  100. backgroundColor: 'transparent'
  101. }}
  102. >
  103. {dots}
  104. </View>
  105. )
  106. }
  107.  
  108. _onIndexChanged = (index: number) => {
  109. console.log("swiped!, index: ", index);
  110. this.setState({
  111. swipeIndex: index
  112. })
  113.  
  114. }
  115. _onFirstNameChange = (event: string) => {
  116. this.setState({
  117. firstName: event
  118. })
  119. }
  120. _onLastNameChange = (event: string) => {
  121. this.setState({
  122. lastName: event
  123. })
  124. }
  125. _onLocationNameChange = (event: string) => {
  126. this.setState({
  127. locationName: event
  128. })
  129. }
  130. _onZipcodeChange = (event: string) => {
  131. this.setState({
  132. zipcode: event
  133. })
  134. }
  135. _calculateScrollEnabled = (index: number) => {
  136. if (index === 0) {
  137. const firstStepButtonDisabled: boolean = this.state.firstName.length > 0 && this.state.lastName.length > 0
  138. return firstStepButtonDisabled;
  139. }
  140. }
  141. _renderBackButton = () => {
  142. let button = null;
  143. if (this.state.swipeIndex !== 0) {
  144. button = <Text>Backk</Text>
  145. }
  146. if (button !== null) {
  147. return (
  148. <BackButton onPress={() => this.swiper.current.scrollBy(-1)}>
  149. <Image style={{ width: 30, height: 30 }} source={require('../assets/ic-keyboard-backspace.png')} />
  150. <BackText>Back</BackText>
  151. </BackButton>
  152. )
  153. }
  154. return;
  155. }
  156.  
  157. render() {
  158. const { firstName, lastName, swipeIndex, locationName, zipcode } = this.state;
  159. const firstStepButtonDisabled: boolean = firstName.length > 0 && lastName.length > 0
  160. const secondStepButtonDisabled: boolean = locationName.length > 0 && zipcode.length > 0
  161.  
  162. return (
  163. <Container>
  164. <StatusBar barStyle="dark-content" />
  165. <Swiper
  166. ref={this.swiper}
  167. loop={false}
  168. renderPagination={this._renderPagination}
  169. onIndexChanged={this._onIndexChanged}
  170. showsButtons={false}
  171. scrollEnabled={true}
  172. >
  173. <ViewContainer>
  174. <ProfileInputContainer
  175. title={"Profile setup"}
  176. _onTopTextInputChange={this._onFirstNameChange}
  177. _onBottomTextInputChange={this._onLastNameChange}
  178. topPlaceholder={"First name"}
  179. bottomPlaceholder={"Last name"}
  180. _onNext={this._onNext}
  181. swipeIndex={swipeIndex}
  182. firstStepButtonDisabled={firstStepButtonDisabled}
  183. />
  184. </ViewContainer>
  185. <ViewContainer>
  186. <BackContainer>
  187. {this._renderBackButton()}
  188. </BackContainer>
  189. <ProfileInputContainer
  190. title={"Location setup"}
  191. _onTopTextInputChange={this._onLocationNameChange}
  192. _onBottomTextInputChange={this._onZipcodeChange}
  193. topPlaceholder={"Location name"}
  194. bottomPlaceholder={"Zip code"}
  195. _onNext={this._onNext}
  196. swipeIndex={swipeIndex}
  197. secondStepButtonDisabled={secondStepButtonDisabled}
  198. />
  199. </ViewContainer>
  200. <ViewContainer>
  201. <BackContainer>
  202. {this._renderBackButton()}
  203. </BackContainer>
  204. <AvailableProgram
  205. _onNext={this._onNext}
  206. />
  207. </ViewContainer>
  208. <ViewContainer>
  209. <BackContainer>
  210. {this._renderBackButton()}
  211. </BackContainer>
  212. <ConnectUtility
  213. _onNext={this._onNext}
  214. />
  215. <Text>44</Text>
  216. </ViewContainer>
  217. </Swiper>
  218. </Container>
  219. )
  220. }
  221. }
  222. const Container = styled.View`
  223. flex:1;
  224. justify-content: center;
  225. align-items: center;
  226. `;
  227. const ViewContainer = styled.View`
  228. flex: 1;
  229. justify-content: center;
  230. align-items: center;
  231.  
  232. `;
  233. const BackContainer = styled.View`
  234. position: absolute;
  235. top: 50;
  236. left: 5%;
  237. justify-content: flex-end;
  238. flex-direction: row;
  239. `;
  240. const BackButton = styled.TouchableOpacity`
  241. flex-direction: row;
  242. `;
  243. const BackText = styled.Text`
  244. top: 3;
  245. font-family: Avenir;
  246. font-size: 18px;
  247. font-weight: 500;
  248. color: #4a4a4a;
  249.  
  250. `;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement