Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {Text, View,TextInput,Button,Alert,Switch} from 'react-
  3. native';
  4.  
  5. import TimerMixin from 'react-timer-mixin';
  6.  
  7. export default class home extends React.Component {
  8.  
  9. constructor(props) {
  10. super(props)
  11.  
  12. this.state = {switchstate:false,timer:null};
  13.  
  14. var timer = setInterval(this.tick, 1000);
  15. this.setState({timer});
  16.  
  17. }
  18. tick=async()=>{
  19.  
  20.  
  21. return await console.log('asdas','iam printing')
  22. }
  23.  
  24. toogleswitchstate=()=>{
  25.  
  26.  
  27. if(this.state.switchstate==false){
  28.  
  29. this.setState({switchstate:true})
  30.  
  31.  
  32.  
  33. }else if(this.state.switchstate==true){
  34.  
  35.  
  36. this.setState({switchstate:false})
  37. clearInterval(this.timer);
  38.  
  39. //geolocation.stopObserving();
  40. }
  41.  
  42. console.log(this.state.switchstate)
  43. }
  44.  
  45. render() {
  46. return (
  47.  
  48.  
  49.  
  50. <View style={{flex:1,flexDirection:'column',justifyContent:'space-evenly',alignItems:'center',backgroundColor:datum.secondaryColor}}>
  51.  
  52. <Button
  53. title={String(this.state.switchstate)}
  54. onPress={()=>this.toogleswitchstate()}
  55. />
  56.  
  57. </View>
  58.  
  59. );
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement