Guest User

Untitled

a guest
Feb 5th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. View,
  4. TextInput,
  5. Text,
  6. TouchableOpacity,
  7. ScrollView,
  8. StyleSheet,
  9. Dimensions,
  10. Animated
  11. } from 'react-native';
  12. const window = Dimensions.get('window');
  13.  
  14. class RegisterPage extends Component {
  15. state = {
  16. x: 0,
  17. scrollX: new Animated.Value(0),
  18. next: false,
  19. back: false,
  20. email: '',
  21. username: '',
  22. password: '',
  23. passwordValidation: '',
  24. }
  25.  
  26. handleNext = () => {
  27. const { x } = this.state;
  28. const toX = x + window.width;
  29. this.setState({x: toX}, () => {
  30. this.viewScroll.scrollTo({y: 0, x: toX });
  31. });
  32. }
  33.  
  34. handleBack = () => {
  35. const { x } = this.state;
  36. const toX = x > 0 ? x - window.width : 0;
  37.  
  38. this.setState({x: toX}, () => {
  39. this.viewScroll.scrollTo({y: 0, x: toX });
  40. });
  41. }
  42.  
  43. handleSubmit = () => {
  44. console.log(this.state);
  45. }
  46.  
  47. handleScroll = () => {
  48. Animated.event(
  49. [{nativeEvent: {contentOffset: {x: this.state.scrollX}}}],
  50. {
  51. useNativeDriver: true // <- Native Driver used for animated events
  52. }
  53. );
  54. }
  55.  
  56. render() {
  57. return (
  58. <ScrollView
  59. horizontal
  60. ref={ref => this.viewScroll = ref }
  61. scrollEnabled={false}
  62. scrollEventThrottle={16}
  63. onScroll={this.handleScroll}
  64. style={{flex: 1, backgroundColor: 'black'}}
  65. >
  66. <View style={styles.section}>
  67. <Text>Email</Text>
  68. <TextInput
  69. underlineColorAndroid="transparent"
  70. style={{width: 200, height: 40, borderColor: 'white', borderBottomWidth: 2, marginBottom: 20}}
  71. onChangeText={(text) => this.setState({text})}
  72. />
  73. <TouchableOpacity onPress={this.handleNext}>
  74. <Text>NEXT</Text>
  75. </TouchableOpacity>
  76. <TouchableOpacity onPress={this.props.showLogin}>
  77. <Text>Login</Text>
  78. </TouchableOpacity>
  79. </View>
  80.  
  81. <View style={styles.section}>
  82. <Text>Username</Text>
  83. <TextInput
  84. underlineColorAndroid="transparent"
  85. style={styles.input}
  86. onChangeText={(text) => this.setState({text})}
  87. />
  88. <TouchableOpacity onPress={this.handleNext}>
  89. <Text>NEXT</Text>
  90. </TouchableOpacity>
  91. <TouchableOpacity onPress={this.handleBack}>
  92. <Text>BACK</Text>
  93. </TouchableOpacity>
  94. </View>
  95.  
  96. <View style={styles.section}>
  97. <Text>Password</Text>
  98. <TextInput
  99. underlineColorAndroid="transparent"
  100. style={styles.input}
  101. onChangeText={(text) => this.setState({text})}
  102. />
  103. <Text>Confirmar password</Text>
  104. <TextInput
  105. underlineColorAndroid="transparent"
  106. style={styles.input}
  107. onChangeText={(text) => this.setState({text})}
  108. />
  109. <TouchableOpacity onPress={this.handleSubmit}>
  110. <Text>Entrar</Text>
  111. </TouchableOpacity>
  112. <TouchableOpacity onPress={this.handleBack}>
  113. <Text>BACK</Text>
  114. </TouchableOpacity>
  115. </View>
  116. </ScrollView>
  117. )
  118. }
  119. }
  120.  
  121. const styles = StyleSheet.create({
  122. container: {
  123. backgroundColor: 'transparent',
  124. position: 'relative',
  125. flex: 1
  126. },
  127. section: {
  128. flex: 1,
  129. backgroundColor: '#1A2F3B',
  130. justifyContent: 'center',
  131. alignItems: 'center',
  132. height: window.height,
  133. width: window.width
  134. },
  135. input: {
  136. width: 200,
  137. height: 40,
  138. borderColor: 'white',
  139. borderBottomWidth: 2,
  140. marginBottom: 20
  141. }
  142. });
  143.  
  144. export default RegisterPage;
Add Comment
Please, Sign In to add comment