Advertisement
Guest User

Untitled

a guest
Nov 6th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. View,
  4. Text,
  5. StyleSheet,
  6. AsyncStorage,
  7. } from 'react-native';
  8.  
  9. import Login from './components/Login'
  10. import Register from './components/Register'
  11. import Home from './components/Home'
  12. import { Scene, Router, TabBar, Modal, Schema, Actions, Reducer, ActionConst } from 'react-native-router-flux'
  13.  
  14. const reducerCreate = params=>{
  15. const defaultReducer = Reducer(params);
  16. return (state, action)=>{
  17. console.log("ACTION:", action);
  18. return defaultReducer(state, action);
  19. }
  20. };
  21.  
  22. export default class App extends Component {
  23.  
  24. constructor(props, context) {
  25. super(props, context);
  26. this.state = {
  27. logged: false,
  28. loading: true,
  29. };
  30. };
  31.  
  32. componentWillMount(){
  33. self = this;
  34. AsyncStorage.getItem('token')
  35. .then( (value) =>{
  36. if (value != null){
  37. this.setState({
  38. logged: true,
  39. loading: false,
  40. });
  41. }
  42. else {
  43. this.setState({
  44. loading: false,
  45. })
  46. }
  47. });
  48. };
  49.  
  50. render() {
  51. if (this.state.loading) {
  52. return <View><Text>Loading</Text></View>;
  53. }
  54. return (
  55. <Router>
  56. <Scene hideNavBar={true} key="root">
  57. <Scene key="logIn" component={Login} title="Login" initial={!this.state.logged}/>
  58. <Scene key="regisTer" component={Register} title="Register"/>
  59. <Scene key="home" component={Home} title="home" initial={this.state.logged}/>
  60. </Scene>
  61. </Router>
  62. )
  63. }
  64. }
  65.  
  66. const styles = StyleSheet.create({
  67. container: {
  68. flex: 1,
  69. },
  70. });
  71.  
  72. /* @flow */
  73.  
  74. import React, { Component } from 'react';
  75.  
  76. import {
  77. View,
  78. StyleSheet,
  79. Image,
  80. ScrollView,
  81. TextInput,
  82. Text,
  83. TouchableHighlight,
  84. Alert,
  85. } from 'react-native';
  86. import { Container, Content, InputGroup, Input, Icon, Item } from 'native-base';
  87. import Button from 'react-native-button'
  88. import {Actions} from 'react-native-router-flux'
  89. import ResponsiveImage from 'react-native-responsive-image'
  90.  
  91. export default class Login extends Component {
  92.  
  93. constructor(props){
  94. super(props)
  95. this.state = {
  96. email: '',
  97. password: '',
  98. data: '',
  99. }
  100. }
  101.  
  102. fetchData() {
  103. fetch('http://allstariq.tbltechnerds.com/api/login/?username=andress&password=23434')
  104. .then((response) => response.json())
  105. .then((responseData) => {
  106. this.setState({
  107. data: responseData.movies,
  108. });
  109. })
  110. .done();
  111. }
  112.  
  113. render() {
  114. return (
  115. <View style={styles.container}>
  116.  
  117. <ScrollView>
  118.  
  119. <View style={ styles.logoContainer }>
  120.  
  121. <View style={{flexDirection: 'row',}}>
  122. <ResponsiveImage
  123. source={require('../assets/logo.png')}
  124. initWidth="300"
  125. initHeight="160" />
  126. </View>
  127.  
  128. </View>
  129.  
  130. <View style={ styles.formContainer }>
  131. <Item>
  132. <Icon active name='mail' />
  133. <Input
  134. onChangeText={(text) => this.setState({email: text})}
  135. value={this.state.email}
  136. placeholder='Email'/>
  137. </Item>
  138.  
  139. <Item>
  140. <Icon active name='key' />
  141. <Input
  142. onChangeText={(text) => this.setState({password: text})}
  143. value={this.state.password}
  144. placeholder='Password'/>
  145. </Item>
  146. <TouchableHighlight
  147. style={ styles.loginButton }
  148. onPress={ () => this.fetchData() }>
  149. <Text style={ styles.btnText}>Login</Text>
  150. </TouchableHighlight>
  151. </View>
  152.  
  153. <View style={ styles.bottomContainer }>
  154. <Text style={ styles.cenText }>Dont worry if you haven't an account yet . . </Text>
  155. <Text
  156. style={ styles.blueText}
  157. onPress={ Actions.regisTer }
  158. >Register Now</Text>
  159. </View>
  160.  
  161. </ScrollView>
  162.  
  163. </View>
  164. );
  165. }
  166. }
  167.  
  168. const styles = StyleSheet.create({
  169. container: {
  170. flex: 1,
  171. },
  172. logoContainer: {
  173. flex: .5,
  174. padding: 10,
  175. justifyContent: 'center',
  176. alignItems: 'center',
  177. },
  178. logoItem: {
  179. width: null,
  180. height: null,
  181. resizeMode: 'cover',
  182. },
  183. formContainer: {
  184. flex: 4,
  185. padding: 10,
  186. },
  187. inputelm: {
  188. marginBottom: 10,
  189. backgroundColor: '#999',
  190. borderWidth: 0,
  191. fontSize: 20,
  192. color: '#FFF',
  193. fontFamily: 'AmaticSC-Bold',
  194. },
  195. loginButton: {
  196. borderRadius: 3,
  197. marginBottom: 20,
  198. marginTop: 20,
  199. paddingLeft: 10,
  200. paddingRight: 10,
  201. backgroundColor: '#2196f3',
  202. elevation: 4,
  203. },
  204. signupButton: {
  205. borderRadius: 3,
  206. marginBottom: 20,
  207. marginTop: 20,
  208. paddingLeft: 10,
  209. paddingRight: 10,
  210. backgroundColor: '#7cb342',
  211. elevation: 4,
  212. },
  213. btnText: {
  214. textAlign: 'center',
  215. color: '#FFF',
  216. fontSize: 30,
  217. lineHeight: 40,
  218. },
  219. blueText: {
  220. textAlign: 'center',
  221. color: '#2196f3',
  222. fontSize: 20,
  223. lineHeight: 40,
  224. },
  225. bottomContainer: {
  226. flex: 1,
  227. padding: 10,
  228. },
  229. cenText: {
  230. textAlign: 'center',
  231. fontSize: 16,
  232. },
  233. });
  234.  
  235. Import fetch from "fetch";
  236.  
  237. import fetch from 'node-fetch'
  238.  
  239. fetchData() {
  240.  
  241. }
  242.  
  243. this.fetchData = function() {
  244.  
  245. }
  246.  
  247. fetchData = () => {
  248.  
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement