Advertisement
Guest User

Untitled

a guest
Mar 12th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.82 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import { FBLogin, FBLoginView, FBLoginManager } from 'react-native-facebook-login'
  3. import { FormLabel, FormInput } from 'react-native-elements'
  4. import Icon from 'react-native-vector-icons/Ionicons'
  5. import ImagePicker from 'react-native-image-picker'
  6. import ActionSheet from 'react-native-actionsheet'
  7. import DatePicker from 'react-native-datepicker'
  8. import Modal from 'react-native-modal'
  9. import Usuario from '../models/usuario'
  10. import strings from '../strings'
  11. import Termos from './termos'
  12. import {
  13. StyleSheet, Dimensions, View,
  14. Text, ImageBackground, TouchableOpacity,
  15. StatusBar, Image, NativeModules, AsyncStorage,
  16. TextInput, ScrollView, Picker
  17. } from 'react-native'
  18.  
  19.  
  20. const { RNTwitterSignIn } = NativeModules;
  21. const w = Dimensions.get('window').width
  22. const h = Dimensions.get('window').height
  23.  
  24. export default class Cadastro extends Component {
  25.  
  26.  
  27. constructor(props) {
  28.  
  29. super(props)
  30.  
  31. this.state = {
  32. fullname: '',
  33. birthday: '',
  34. gender: '',
  35. password: '',
  36. confirmation: '',
  37. email: '',
  38. avatarSource: require('../imgs/no-image.jpg')
  39. }
  40.  
  41. this.cadastrar = this.cadastrar.bind(this)
  42. this.selecinarAvatar = this.selecinarAvatar.bind(this)
  43. }
  44.  
  45. static navigationOptions = ({ navigation }) => {
  46. const { state, setParams } = navigation;
  47. return {
  48. title: 'GRANSPOT'
  49. };
  50. };
  51.  
  52. cadastrar() {
  53. if (this.state.confirmation != this.state.password) {
  54. alert('Senhas não conferem')
  55. return;
  56. }
  57.  
  58. let usuario = {
  59. nome: this.state.fullname,
  60. usuario: this.state.username,
  61. email: this.state.email,
  62. genero: this.state.gender,
  63. password: this.state.password,
  64. picture: this.state.avatarSource,
  65. data_nascimento: this.state.birthday
  66. }
  67.  
  68. let callback = (hasErrors) => {
  69. if (hasErrors.error) {
  70. alert('Email ou usuário já em uso.')
  71. } else {
  72. alert('Favor ative seu cadastro no link enviado por email.')
  73. this.props.navigation.goBack()
  74. }
  75. }
  76.  
  77. Usuario.novo(usuario, callback)
  78. }
  79.  
  80. selecinarAvatar() {
  81. var options = {
  82. title: 'Select Avatar',
  83. storageOptions: {
  84. skipBackup: true,
  85. path: 'images'
  86. }
  87. };
  88.  
  89. let callback = (response) => {
  90. console.log("SPACE ZOMBIES")
  91. if (response.didCancel) {
  92. console.log('User cancelled image picker');
  93. }
  94. else if (response.error) {
  95. console.log('ImagePicker Error: ', response.error);
  96. }
  97. else if (response.customButton) {
  98. console.log('User tapped custom button: ', response.customButton);
  99. }
  100. else {
  101. let fonte = 'data:image/jpeg;base64,' + response.data
  102. console.log(fonte.substr(0, 50))
  103. this.setState({
  104. avatarSource: {uri: fonte}
  105. });
  106. }
  107. }
  108.  
  109. ImagePicker.showImagePicker(options, callback.bind(this))
  110. }
  111.  
  112.  
  113. render() {
  114. return (
  115. <ScrollView style={{ width: '100%', backgroundColor: 'white', height: '100%' }}>
  116. <View style={{ flex: 0.4 }}>
  117. <Text style={{
  118. marginLeft: 10,
  119. fontSize: 20,
  120. fontWeight: 'bold',
  121. textAlignVertical: 'center',
  122. color: 'black',
  123. height: '100%'
  124. }}>{strings.register_profile}</Text>
  125. </View>
  126.  
  127. <TouchableOpacity
  128. onPress={this.selecinarAvatar}
  129. style={{
  130. marginTop: 20,
  131. flex: 1, backgroundColor: 'white',
  132. justifyContent: 'center', alignItems: 'center' ,
  133. height: 140
  134. }}>
  135. <ImageBackground style={{
  136. flex: 1,
  137. aspectRatio: 1,
  138. backgroundColor: '#ccc',
  139. borderRadius: 400
  140. }}
  141. source={this.state.avatarSource}
  142. borderRadius={400} >
  143. </ImageBackground>
  144. </TouchableOpacity>
  145.  
  146. <View style={{ flex: 3, marginLeft: 20, marginRight: 20, marginTop: 50 }}>
  147. <View style={{ flex: 1 }}>
  148. <TextInput placeholderTextColor="#000"
  149. value={this.state.fullname}
  150.  
  151. onChangeText={ (v) => this.setState({ fullname: v }) }
  152. placeholder={strings.full_name} />
  153. </View>
  154.  
  155. <View style={{ flex: 1 }}>
  156. <TextInput placeholderTextColor="#000"
  157. value={this.state.birthday}
  158.  
  159.  
  160. onChangeText={(v) => this.setState({ birthday: v })}
  161. placeholder={strings.birthday} />
  162.  
  163. <DatePicker
  164. style={{ display: 'none' }}
  165. date={this.state.birthday}
  166. mode="date"
  167. placeholder={strings.birthday}
  168. format={strings.formatDate}
  169. confirmBtnText={strings.confirm}
  170. cancelBtnText={strings.cancel}
  171. ref='birthday'
  172. onDateChange={(birthday) => { this.setState({ birthday: birthday }) }}
  173. />
  174. </View>
  175.  
  176. <View style={{ flex: 1}}>
  177.  
  178. <Picker
  179. selectedValue={this.state.gender}
  180. textStyle={{
  181. borderColor: '#000',
  182. borderWidth: 2
  183. }}
  184. onValueChange={(itemValue, itemIndex) => this.setState({ gender: itemValue })}>
  185. <Picker.Item label={strings.male} value={strings.male} />
  186. <Picker.Item label={strings.female} value={strings.female} />
  187. <Picker.Item label={strings.other} value={strings.other} />
  188. </Picker>
  189. </View>
  190.  
  191. <View style={{ flex: 1 }}>
  192.  
  193. <TextInput
  194. style={{ display: 'none' }}
  195. placeholderTextColor="#000"
  196. value={this.state.gender}
  197.  
  198. onChangeText={(v) => this.setState({ gender: v })}
  199. placeholder={strings.gender} />
  200. </View>
  201.  
  202.  
  203. <View style={{ flex: 1 }}>
  204. <TextInput placeholderTextColor="#000"
  205. value={this.state.email}
  206.  
  207. onChangeText={(v) => this.setState({ email: v })}
  208. placeholder={strings.email} />
  209. </View>
  210.  
  211.  
  212. <View style={{ flex: 1 }}>
  213. <TextInput placeholderTextColor="#000"
  214. value={this.state.username}
  215.  
  216. onChangeText={(v) => this.setState({ username: v })}
  217. placeholder={strings.username} />
  218. </View>
  219.  
  220.  
  221.  
  222. <View style={{ flex: 1 }}>
  223. <TextInput secureTextEntry={true}
  224. placeholderTextColor="#000"
  225. value={this.state.password}
  226.  
  227. onChangeText={(v) => this.setState({ password: v })}
  228. placeholder={strings.password} />
  229. </View>
  230.  
  231. <View style={{ flex: 1 }}>
  232. <TextInput secureTextEntry={true}
  233. placeholderTextColor="#000"
  234. value={this.state.confirmation}
  235.  
  236. onChangeText={(v) => this.setState({ confirmation: v })}
  237. placeholder={strings.confirmation} />
  238. </View>
  239.  
  240.  
  241.  
  242. </View>
  243. <View style={{ flex: 1, justifyContent: 'center', alignItems: 'flex-end' }}>
  244.  
  245. <TouchableOpacity
  246. onPress={this.cadastrar}
  247. style={{
  248. backgroundColor: '#C3F340',
  249. borderRadius: 8,
  250. width: 160,
  251. height: 50,
  252. marginRight: 10,
  253. alignItems: 'center',
  254. justifyContent: 'center'
  255. }}>
  256. <Text style={{ fontWeight: 'bold' }}>{strings.next}</Text>
  257. </TouchableOpacity>
  258.  
  259. </View>
  260. </ScrollView>
  261. )
  262. }
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement