import React from 'react'; import { View, StyleSheet, ImageBackground, TouchableOpacity, Text, Image } from 'react-native'; import { connect } from 'react-redux'; import NetInfo from '@react-native-community/netinfo'; import Sync from '../Controllers/Sync'; import * as SplashScreen from 'expo-splash-screen'; import i18n from "../I18n"; function mapStateToProps(state) { return { directories: state.directories, locale: state.locale, }; } class HomeScreen extends React.Component { state = { lastSyncCall: '2020-02-12', }; componentDidMount() { this.props.dispatch({ type: 'INIT' }); SplashScreen.hideAsync(); } unsubscribe() { NetInfo.addEventListener(state => { if (state.isConnected === true) { let seconds = Math.abs(new Date(this.state.lastSyncCall) - Date.now()) / 1000; //console.log(seconds); if (seconds > 30) { this.setState({ lastSyncCall: Date.now() }); Sync.needSync(this.openSync.bind(this)); } } }); } openSync() { this.props.navigation.navigate('SyncScreen', { isInstalled: true }); } openFolder(folderID) { const folder = this.props.directories.filter(tmp => tmp.id === folderID); this.props.navigation.navigate('DirectoriesScreen', { folder: folder }); } render() { i18n.locale = this.props.locale; this.unsubscribe(); return ( this.openFolder(2)} style={styles.button}> {i18n.t('home_s.1')} this.openFolder(3)} style={styles.button}> {i18n.t('home_s.2')} this.props.navigation.navigate('OnlyVideosScreen')} style={styles.button}> {i18n.t('global.videos')} this.props.navigation.navigate('ContactScreen')} style={styles.button}> {i18n.t('global.contacts')} ); } } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'flex-end', justifyContent: 'center', }, text: { height: 40, width: 300, borderColor: 'grey', borderWidth: 1, marginBottom: 20, }, button: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: 'white', marginBottom: 20, marginRight: 50, width: 400, height: 80, borderRadius: 10 }, btnTxt: { fontSize: 20 }, btnImg: { position: 'absolute', left: 15, height: 50, width: 50, resizeMode: 'stretch' } }); export default connect(mapStateToProps)(HomeScreen);