Commit 8dd36e05 authored by Sebastian Trebunak's avatar Sebastian Trebunak
Browse files

interval to get notifications

parent 9f09d8d9
import React from 'react';
import { Platform, StatusBar, StyleSheet, View } from 'react-native';
import { AppLoading, Asset, Font, Icon } from 'expo';
import AppNavigator from './navigation/AppNavigator';
import React from "react";
import { Platform, StatusBar, StyleSheet, View } from "react-native";
import { AppLoading, Asset, Font, Icon } from "expo";
import AppNavigator from "./navigation/AppNavigator";
import { NOTIFICATIONS } from "./constants/Data";
export default class App extends React.Component {
state = {
isLoadingComplete: false,
notifications: NOTIFICATIONS
};
componentDidMount() {
this.timer = setInterval(this.getNotifications, 7500);
}
componentWillUnmount() {
if (this.timer) {
clearInterval(this.timer);
}
}
getNotifications = () => {
console.log("Get Notifications now!!");
// const notifications treba nahradit za fetch a setState spustit iba v pripade ze sa data zmenia
// pretoze by default to re-renderuje celu aplikaciu
const notifications = [
...this.state.notifications,
NOTIFICATIONS[this.state.notifications.length - 5]
];
this.setState({ notifications });
};
render() {
......@@ -20,8 +43,8 @@ export default class App extends React.Component {
} else {
return (
<View style={styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
<AppNavigator />
{Platform.OS === "ios" && <StatusBar barStyle="default" />}
<AppNavigator screenProps={this.state} />
</View>
);
}
......@@ -30,16 +53,16 @@ export default class App extends React.Component {
_loadResourcesAsync = async () => {
return Promise.all([
Asset.loadAsync([
require('./assets/images/robot-dev.png'),
require('./assets/images/robot-prod.png'),
require("./assets/images/robot-dev.png"),
require("./assets/images/robot-prod.png")
]),
Font.loadAsync({
// This is the font that we are using for our tab bar
...Icon.Ionicons.font,
// We include SpaceMono because we use it in HomeScreen.js. Feel free
// to remove this if you are not using it in your app
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
}),
"space-mono": require("./assets/fonts/SpaceMono-Regular.ttf")
})
]);
};
......@@ -57,6 +80,6 @@ export default class App extends React.Component {
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
backgroundColor: "#fff"
}
});
......@@ -4,23 +4,16 @@ import { StyleSheet } from "react-native";
import MapView, { Marker } from "react-native-maps";
class BranchesMap extends PureComponent {
state = {
region: {
atitude: 48.723221,
longitude: 21.256716,
render() {
const initialRegion = {
latitude: this.props.data.lat,
longitude: this.props.data.long,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}
};
};
render() {
const { data } = this.props;
return (
<MapView
style={styles.map}
initialRegion={this.state.region}
loadingEnabled
>
<MapView style={styles.map} initialRegion={initialRegion} loadingEnabled>
<Marker
key="marker"
coordinate={{ latitude: data.lat, longitude: data.long }}
......
import React, { Component } from "react";
import { View, StyleSheet } from "react-native";
import { ButtonGroup } from "react-native-elements";
import { withNavigationFocus } from "react-navigation";
import NotificationList from "../components/notifications/NotificationList";
import { iOSColors } from "react-native-typography";
import { NOTIFICATIONS } from "../constants/Data";
export default class NotificationScreen extends Component {
class NotificationScreen extends Component {
static navigationOptions = {
title: "Upozornenia"
};
......@@ -19,6 +19,18 @@ export default class NotificationScreen extends Component {
};
}
shouldComponentUpdate() {
return this.props.isFocused;
}
componentDidUpdate(prevProps) {
const lastNotifications = prevProps.screenProps.notifications;
const currentNotifications = this.props.screenProps.notifications;
if (lastNotifications.length !== currentNotifications.length) {
this.setState({ data: currentNotifications });
}
}
updateIndex = selectedIndex => {
this.setState({ selectedIndex });
};
......@@ -59,3 +71,5 @@ const styles = StyleSheet.create({
},
disabledTextStyle: { color: iOSColors.blue, fontWeight: "bold" }
});
export default withNavigationFocus(NotificationScreen);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment