Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jmanhart/bf77b31bf97e67c0af8d6a4c1d07599c to your computer and use it in GitHub Desktop.

Select an option

Save jmanhart/bf77b31bf97e67c0af8d6a4c1d07599c to your computer and use it in GitHub Desktop.
import React, {Component} from 'react'
import {
Animated,
Button,
Image,
ListView,
LayoutAnimation,
Text,
ScrollView,
StyleSheet,
TouchableWithoutFeedback,
View,
} from 'react-native'
import { connect } from 'react-redux'
import Dimensions from 'Dimensions'
import BottomNav from 'mosey/components/common/BottomNav'
import Groups from 'mosey/components/Groups'
import Common from 'mosey/lib/common'
import { apikey } from 'mosey/keystore'
import Panner from 'mosey/lib/panner'
import ReducerConst from 'mosey/reducers/actions'
//Import Global Styles
import { main, typeStyles, button03, colors, common } from 'mosey/lib/global_styles/index'
import FA from 'react-native-vector-icons/FontAwesome';
const star = (<FA name="star" size={16} color="#F6A623" />)
const starHalf = (<FA name="star-half" size={14} color="#F6A623" />)
//Dimensions
let {height, width} = Dimensions.get('window');
//Page Animation
let Page= {
duration: 600,
create: {
type: LayoutAnimation.Types.spring,
property: LayoutAnimation.Properties.scaleXY,
springDamping: 0.7,
},
update: {
type: LayoutAnimation.Types.spring,
springDamping: 0.7,
},
};
//Card Animation
let CardAnimtion= {
duration: 600,
create: {
type: LayoutAnimation.Types.spring,
property: LayoutAnimation.Properties.scaleXY,
springDamping: 0.7,
},
update: {
type: LayoutAnimation.Types.spring,
springDamping: 0.7,
},
};
let cardDimensions = ( width - 80 )
class GroupSwipeContainer extends Component {
constructor(props) {
super(props);
this.state = {
f: 0,
t: 150,
a: 0,
on: '',
off: 'none',
opacity:1,
cardWidth: ( cardDimensions ),
pick: props.pick,
panner: {},
};
}
// This Handles the inital animation
componentWillMount() {
// Animate creation
LayoutAnimation.configureNext(Page);
this._panner = new Panner(this.swipeSuccessful.bind(this))
}
swipeSuccessful(right) {
alert('You swiped ' + (right? 'right':'left'))
}
_onPressOpen(){
LayoutAnimation.configureNext(CardAnimtion);
this.setState({
f: this.state.f + 1,
t: this.state.t - 75,
a: this.state.a + 1 ,
on: 'none',
off: 'none',
opacity: this.state.opacity - 1,
cardWidth: (this.state.cardWidth + 40)
})
}
_onPressClose(){
LayoutAnimation.configureNext(CardAnimtion);
this.setState({
f: 0,
t: 150,
a: 0,
on: '',
off: '',
opacity: this.state.opacity + 1,
cardWidth: this.state.cardWidth - 40
})
}
getPicture(place) {
let photo_url = place.icon
if (place.photos) {
photo_url = "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference="+place.photos[0].photo_reference+"&key="+apikey;
}
return photo_url
}
next() {
let index = this.state.pick.index + 1
let record = {
index: index,
place: this.props.all[index]
}
this.setState({
pick: record
})
// Update redux
this.props.setCurrentPick(record)
}
renderStars(rating) {
let stars = [];
for (let i = 1; i < rating; i++) {
stars.push(<Text key={'star-'+i}>{star}</Text>)
}
if (rating%1 >= 0.4) {
stars.push(<Text>{starHalf}</Text>)
}
return stars
}
itemDetails(){
let place = this.props.pick.place
let photo_url = this.getPicture(place)
let addr = place.formatted_address.split(',')[0]
return(
<ScrollView style={{flex:1}}>
<View style={[itemDetails.wrapper, {opacity: this.state.a, width:( this.state.cardWidth )}]}>
<TouchableWithoutFeedback onPress={() => this._onPressClose()}>
<View>
<Text style={[typeStyles.header02]}>Close</Text>
</View>
</TouchableWithoutFeedback>
<View style={[itemDetails.container,{flex:1, flexDirection:'column'}]}>
{/*Place info*/}
<View style={[itemDetails.container,{ flexDirection:'row', paddingBottom: 20 }]}>
<Image style={{width:50, height: 50}} source={{url:photo_url}} />
<View>
<Text style={typeStyles.header01}>{place.name}</Text>
<Text style={typeStyles.header06}>{addr}</Text>
</View>
</View>
{/*Rating and Reviews*/}
<View style={[itemDetails.container,{ flexDirection:'row', paddingBottom: 20 }]}>
<View>
<Text>{place.rating}{this.renderStars(place.rating)}</Text>
<Text style={typeStyles.header06}>13,453 Reviews</Text>
</View>
</View>
{/*Photo(s)*/}
<View style={[itemDetails.container,{ flexDirection:'column', paddingBottom: 20 }]}>
<Text style={typeStyles.header04}>Photos</Text>
<View>
<View style={{width: this.state.cardWidth , height: 200, backgroundColor:'gray'}}/>
</View>
</View>
{/*Price Range*/}
<View style={[itemDetails.container,{ flexDirection:'column', paddingBottom: 20 }]}>
<Text style={typeStyles.header04}>Price Range</Text>
<View style={{flexDirection:'row'}}>
<View style={{width:25, height: 25, marginRight: 10, backgroundColor:'gray'}}/>
<Text style={typeStyles.header04}>View Menu</Text>
</View>
</View>
{/*What People are Saying*/}
<View style={[itemDetails.container,{ flexDirection:'column', paddingBottom: 20}]}>
<Text style={typeStyles.header04}>What People are saying</Text>
<View style={{flexDirection:'row'}}>
<View style={{width:25, height: 25, marginRight: 10, backgroundColor:'green'}}/>
<Text style={typeStyles.header04}>Tasted like poop</Text>
</View>
</View>
{/*Details*/}
<View style={[itemDetails.container,{ flexDirection:'column', paddingBottom: 20}]}>
<Text style={typeStyles.header04}>Details</Text>
<View style={{flexDirection:'row', paddingBottom: 10}}>
<View style={{width:25, height: 25, marginRight: 10, backgroundColor:'green'}}/>
<Text style={typeStyles.header04}>Get Directions</Text>
</View>
<View style={{flexDirection:'row', paddingBottom: 10}}>
<View style={{width:25, height: 25, marginRight: 10, backgroundColor:'green'}}/>
<Text style={typeStyles.header04}>Phone Number</Text>
</View>
<View style={{flexDirection:'row', paddingBottom: 300}}>
<View style={{width:25, height: 25, marginRight: 10, backgroundColor:'green'}}/>
<Text style={typeStyles.header04}>Website</Text>
</View>
</View>
</View>
</View>
</ScrollView>
)
}
animStuff() {
let { pan, scale } = this._panner.state;
let [translateX, translateY] = [pan.x, pan.y];
let rotate = pan.x.interpolate({
inputRange: [-200, 0, 200],
outputRange: ["-5deg", "0deg", "5deg"],
})
let opacity = pan.x.interpolate({
inputRange: [-200, 0, 200],
outputRange: [0.5, 1, 0.5],
})
return {
transform: [{translateX}, {translateY}, {rotate}, {scale}]
}
}
render() {
let { pan, scale } = this._panner.state;
let [translateX, translateY] = [pan.x, pan.y];
let rotate = pan.x.interpolate({
inputRange: [-200, 0, 200],
outputRange: ["-5deg", "0deg", "5deg"],
})
let opacity = pan.x.interpolate({
inputRange: [-200, 0, 200],
outputRange: [0.5, 1, 0.5],
})
let imageStyle = {
flex: 1,
transform: [{translateX}, {translateY}, {rotate}, {scale}]
}
// let imageStyle = this.animStuff()
if (!this.props.pick.place.formatted_address) {
return (
<Text>Nothing to vote on</Text>
)
}
let place = this.props.pick.place
let photo_url = this.getPicture(place)
let addr = place.formatted_address.split(',')[0]
return(
<View style={[main.container, styles.wrapper, {paddingTop: this.state.t}]}>
{/*Business Card*/}
<View style={[styles.boundBox, {flex: this.state.f}]}>
<Animated.View style={imageStyle} {...this._panner._pan.panHandlers}>
<View style={[styles.card, {width: this.state.cardWidth }]}>
<TouchableWithoutFeedback onPress={() => this._onPressOpen()} activeOpacity={1}>
<Image style={[styles.cardImage,{ display: this.state.on, opacity:this.state.opacity }]} source={{url:photo_url}} />
</TouchableWithoutFeedback>
</View>
</Animated.View>
{this.itemDetails()}
</View>
{/*Business Info*/}
<View>
<View style={[{ display: this.state.on, opacity:this.state.opacity }]}>
<View style={[common.centerHoriz,{padding:10}]}>
<Text style={typeStyles.header01}>{place.name}</Text>
<Text style={typeStyles.header06}>{addr}</Text>
</View>
<View style={common.centerHoriz}>
<Text>{place.rating}{this.renderStars(place.rating)}</Text>
</View>
</View>
{/*FPO Next Button*/}
<View style={[{ display: this.state.on, opacity:this.state.opacity, backgroundColor:'rgba(0,0,0,0)' }]}>
<Button title="Next" onPress={()=>this.next()} />
</View>
</View>
</View>
)
}
}
const mapStateToProps = (state) => {
return {
all: state.picks.all.results,
pick: state.picks.current,
group: state.group.currentGroup,
}
}
const mapDispatchToProps = (dispatch) => {
return {
setCurrentPick(record) {
dispatch({
type: ReducerConst.CURRENT_PICK,
index: record.index,
place: record.place,
})
}
}
}
export default connect(mapStateToProps, mapDispatchToProps)(GroupSwipeContainer)
const styles = StyleSheet.create({
wrapper:{
backgroundColor:'#F7F7F7',
},
boundBox:{
flex: 1,
marginLeft: 0,
marginRight: 0,
alignItems:'center',
justifyContent:'center',
},
card:{
height: cardDimensions,
width: cardDimensions,
borderRadius:5,
alignItems:'center',
justifyContent:'center',
backgroundColor:'rgba(255, 255, 255, 1)',
shadowColor: "#000000",
shadowOpacity: 0.1,
shadowRadius: 2,
shadowOffset: {
height: 4,
width: 0
},
},
cardContent:{
backgroundColor:'rgba(255, 255, 255, 1)',
flex:1,
},
cardImage:{
height: 250,
width: 250,
}
})
const itemDetails = StyleSheet.create({
wrapper:{
opacity: 0,
flex:1,
backgroundColor:'rgba(0,0,0,0.0)',
justifyContent:'center',
alignItems:'center',
},
container:{
backgroundColor:'rgba(0,0,0,0.0)',
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment