Last active
March 6, 2017 12:17
-
-
Save vedovato/d4405ff36db140125e607fdec6d66621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Platform } from 'react-native' | |
import { Navigation } from 'react-native-navigation' | |
import { registerScreens } from './utils/Screens' | |
import codePush from 'react-native-code-push' | |
registerScreens() | |
const renderTabs = () => { | |
let tabs = [ | |
{ | |
label: 'Notícias', | |
screen: 'app.news', | |
icon: require('./images/newspaper.png'), | |
selectedIcon: require('./images/newspaper_selected.png'), | |
navigatorStyle: { navBarHidden: true }, | |
}, | |
// { | |
// label: 'Doe sua nota', | |
// screen: 'app.donation', | |
// icon: require('./images/newspaper.png'), | |
// selectedIcon: require('./images/newspaper_selected.png'), | |
// title: 'Doe sua nota sem CPF', | |
// }, | |
{ | |
label: 'Indicadores', | |
screen: 'app.indicators', | |
icon: require('./images/line-chart.png'), | |
selectedIcon: require('./images/line-chart_selected.png'), | |
title: 'Indicadores', | |
}, | |
{ | |
label: 'Contato', | |
screen: 'app.contacts', | |
icon: require('./images/comments.png'), | |
selectedIcon: require('./images/comments_selected.png'), | |
title: 'Entre em Contato', | |
} | |
] | |
return tabs | |
} | |
// this will start our app | |
Navigation.startTabBasedApp({ | |
tabs: renderTabs(), | |
animationType: 'slide', | |
tabsStyle: { | |
tabBarButtonColor: '#919191', | |
tabBarSelectedButtonColor: '#26316C', | |
tabBarBackgroundColor: '#f7f7f7' | |
}, | |
appStyle: { | |
tabBarBackgroundColor: '#f7f7f7', | |
tabBarButtonColor: '#919191', | |
tabBarSelectedButtonColor: '#26316C' | |
} | |
}) | |
codePush.sync({ installMode: codePush.InstallMode.ON_NEXT_RESUME }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
import React, { Component } from 'react' | |
import { Text, View, ListView, StyleSheet, RefreshControl } from 'react-native' | |
import Meteor from 'react-native-meteor' | |
import MergeObj from 'object-merge' | |
import SETTINGS from '../utils/settings' | |
import NewsItem from '../components/NewsItem' | |
import Loading from '../components/Loading' | |
import Separator from '../components/Separator' | |
import codePush from 'react-native-code-push' | |
export default class News extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
isLoading: true, | |
refreshing: false, | |
dataSource: new ListView.DataSource({ | |
rowHasChanged: (row1, row2) => row1 !== row2 | |
}) | |
} | |
} | |
componentDidMount() { | |
this.filterData() | |
this.setState({ isLoading: false }) | |
codePush.sync({ installMode: codePush.InstallMode.ON_NEXT_RESUME }); | |
// this.teste() | |
} | |
teste() { | |
const handle = Meteor.subscribe('news.app') | |
let newArr = [] | |
Meteor.collection('newsApp').find().map((res, i) => { | |
newArr = newArr.concat(res.noticias) | |
}) | |
this.setState({ | |
dataSource: this.state.dataSource.cloneWithRows(newArr), | |
}) | |
} | |
componentWillReceiveProps() { | |
this.teste() | |
} | |
// codePushCheck() { | |
// codePush.sync({ | |
// updateDialog: true, | |
// installMode: codePush.InstallMode.IMMEDIATE, | |
// checkFrequency: codePush.CheckFrequency.ON_APP_RESUME | |
// }); | |
// } | |
filterData(updatedData) { | |
let data = '' // server data | |
, result = '' // filter result | |
, type = this.props.dataType // economia, politica etc | |
data = this.props.meteorData.filter(Boolean) | |
// if type IS empty, return all news types | |
if(!type) { | |
result = data | |
} else { | |
result = data.filter((value) => value.cat === type) | |
} | |
this.setState({ | |
dataSource: this.state.dataSource.cloneWithRows(result), | |
}) | |
} | |
refreshScreen() { | |
this.setState({ refreshing: true }) | |
this.teste() | |
this.setState({ refreshing: false }) | |
} | |
render() { | |
return this.state.isLoading ? <Loading /> : ( | |
<View style={styles.wrapper}> | |
<ListView | |
dataSource={this.state.dataSource} | |
enableEmptySections={true} | |
renderSeparator={ (data, i)=> <Separator key={i} /> } | |
renderRow={ (data)=> <NewsItem navigator={this.props.navigator} data={data} /> } | |
refreshControl={ | |
<RefreshControl | |
refreshing={this.state.refreshing} | |
onRefresh={this.refreshScreen.bind(this)} | |
/> | |
} | |
/> | |
</View> | |
) | |
} | |
} | |
const styles = StyleSheet.create({ | |
wrapper: { | |
backgroundColor: SETTINGS.LIGHT_COLOR, | |
height: SETTINGS.WINDOW_HEIGHT, | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment