Skip to content

Instantly share code, notes, and snippets.

@magnatronus
Created May 18, 2017 16:16
Show Gist options
  • Save magnatronus/b6428d4cb0dc7e10de224b5c973f0bfc to your computer and use it in GitHub Desktop.
Save magnatronus/b6428d4cb0dc7e10de224b5c973f0bfc to your computer and use it in GitHub Desktop.
Example source code of ES6 test Titanium app
import React, { Component, Globals } from '/libs/erbium';
import { View, Image, Label, TableView, TableViewSection, TableViewRow } from '/libs/erbium-ui';
import Theme from '/themes/ThemeOne';
import WeatherAPI from '/components/WeatherAPI';
import moment from '/libs/moment';
class ForecastList extends Component {
componentWillMount(){
this.api = new WeatherAPI();
}
componentDidMount() {
console.log('ForecastList didMount:');
}
renderForecast() {
console.log('in renderForecast');
const { list } = Globals.otg('weather');
//console.log(list);
return list.map(day =>
<TableViewRow>
<View style={styles.rowStyle} >
<Label style={styles.dayLabelStyle}>{new moment.unix(day.dt).format("dddd")}</Label>
<Image style={styles.weatherIconStyle}>{this.api.getIcon(day.weather[0].icon)}</Image>
<Label style={styles.weatherLabelStyle}>{day.weather[0].description}</Label>
<Label style={styles.dayTempStyle}>{ Math.round(day.temp.day) + "\u00b0"}</Label>
<Label style={styles.nightTempStyle}>{ Math.round(day.temp.night) + "\u00b0"}</Label>
</View>
</TableViewRow>
);
}
render(props){
return (
<TableView style={styles.tableViewStyle} >
<TableViewSection>
{this.renderForecast()}
</TableViewSection>
</TableView>
);
}
}
const styles = {
tableViewStyle: {
height: Ti.UI.FILL,
top: 20,
left: 0,
right: 0
},
rowStyle: {
height: Ti.UI.SIZE,
width: Ti.UI.FILL
},
weatherLabelStyle: {
left: 145,
height: Ti.UI.SIZE,
width: 80,
textAlign: 'left',
font: {fontSize: 15},
color: '#004080'
},
dayLabelStyle: {
left: 5,
height: Ti.UI.SIZE,
width: 80,
textAlign: 'left',
font: {fontSize: 15},
color: '#191919'
},
nightTempStyle: {
right: 10,
height: Ti.UI.SIZE,
width: 40,
textAlign: 'right',
font: {fontSize: 15},
color: '#B3B3B3'
},
dayTempStyle: {
right: 60,
height: Ti.UI.SIZE,
width: 40,
textAlign: 'right',
font: {fontSize: 15},
color: '#FF8000'
},
weatherIconStyle: {
width: 40,
left: 90
},
h4: {
color: '#666666',
font: {fontSize: 12,fontWeight: 'bold'},
textAlign: 'center',
width: Ti.UI.FILL,
height: 16,
top: 5
},
h2: {
color: '#666666',
font: {fontSize: 16, fontWeight: 'bold'},
textAlign: 'center',
width: Ti.UI.SIZE,
height: 20,
top: 5
}
};
export default ForecastList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment