2015-07-07 20:34:09 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-07-07 20:34:09 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-07-07 20:34:09 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
var {Animated, PanResponder, StyleSheet, Text, View} = ReactNative;
|
2015-07-07 20:34:09 +00:00
|
|
|
|
|
|
|
var AnExBobble = require('./AnExBobble');
|
|
|
|
var AnExChained = require('./AnExChained');
|
|
|
|
var AnExScroll = require('./AnExScroll');
|
|
|
|
var AnExTilt = require('./AnExTilt');
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class AnExSet extends React.Component<Object, any> {
|
2015-07-07 20:34:09 +00:00
|
|
|
constructor(props: Object) {
|
|
|
|
super(props);
|
|
|
|
function randColor() {
|
2018-05-11 20:32:37 +00:00
|
|
|
var colors = [0, 1, 2].map(() => Math.floor(Math.random() * 150 + 100));
|
2015-07-07 20:34:09 +00:00
|
|
|
return 'rgb(' + colors.join(',') + ')';
|
|
|
|
}
|
|
|
|
this.state = {
|
|
|
|
closeColor: randColor(),
|
|
|
|
openColor: randColor(),
|
|
|
|
};
|
|
|
|
}
|
2017-08-18 01:36:54 +00:00
|
|
|
render(): React.Node {
|
2018-05-11 20:32:37 +00:00
|
|
|
var backgroundColor = this.props.openVal
|
|
|
|
? this.props.openVal.interpolate({
|
|
|
|
inputRange: [0, 1],
|
|
|
|
outputRange: [
|
|
|
|
this.state.closeColor, // interpolates color strings
|
|
|
|
this.state.openColor,
|
|
|
|
],
|
|
|
|
})
|
|
|
|
: this.state.closeColor;
|
|
|
|
var panelWidth =
|
|
|
|
(this.props.containerLayout && this.props.containerLayout.width) || 320;
|
2015-07-07 20:34:09 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<Animated.View
|
2018-05-11 20:32:37 +00:00
|
|
|
style={[styles.header, {backgroundColor}]}
|
2015-07-07 20:34:09 +00:00
|
|
|
{...this.state.dismissResponder.panHandlers}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text style={[styles.text, styles.headerText]}>{this.props.id}</Text>
|
2015-07-07 20:34:09 +00:00
|
|
|
</Animated.View>
|
2018-05-11 20:32:37 +00:00
|
|
|
{this.props.isActive && (
|
2015-07-07 20:34:09 +00:00
|
|
|
<View style={styles.stream}>
|
|
|
|
<View style={styles.card}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text style={styles.text}>July 2nd</Text>
|
2015-07-07 20:34:09 +00:00
|
|
|
<AnExTilt isActive={this.props.isActive} />
|
|
|
|
<AnExBobble />
|
|
|
|
</View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<AnExScroll panelWidth={panelWidth} />
|
2015-07-07 20:34:09 +00:00
|
|
|
<AnExChained />
|
|
|
|
</View>
|
2018-05-11 20:32:37 +00:00
|
|
|
)}
|
2015-07-07 20:34:09 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:26:45 +00:00
|
|
|
UNSAFE_componentWillMount() {
|
2015-07-07 20:34:09 +00:00
|
|
|
this.state.dismissY = new Animated.Value(0);
|
|
|
|
this.state.dismissResponder = PanResponder.create({
|
|
|
|
onStartShouldSetPanResponder: () => this.props.isActive,
|
|
|
|
onPanResponderGrant: () => {
|
2018-05-11 20:32:37 +00:00
|
|
|
Animated.spring(this.props.openVal, {
|
|
|
|
// Animated value passed in.
|
|
|
|
toValue: this.state.dismissY.interpolate({
|
|
|
|
// Track dismiss gesture
|
|
|
|
inputRange: [0, 300], // and interpolate pixel distance
|
|
|
|
outputRange: [1, 0], // to a fraction.
|
2017-02-17 22:41:23 +00:00
|
|
|
}),
|
|
|
|
useNativeDriver: true,
|
2015-07-07 20:34:09 +00:00
|
|
|
}).start();
|
|
|
|
},
|
|
|
|
onPanResponderMove: Animated.event(
|
2018-05-11 20:32:37 +00:00
|
|
|
[null, {dy: this.state.dismissY}], // track pan gesture
|
|
|
|
{useNativeDriver: true},
|
2015-07-07 20:34:09 +00:00
|
|
|
),
|
|
|
|
onPanResponderRelease: (e, gestureState) => {
|
|
|
|
if (gestureState.dy > 100) {
|
2018-05-11 20:32:37 +00:00
|
|
|
this.props.onDismiss(gestureState.vy); // delegates dismiss action to parent
|
2015-07-07 20:34:09 +00:00
|
|
|
} else {
|
|
|
|
Animated.spring(this.props.openVal, {
|
2018-05-11 20:32:37 +00:00
|
|
|
toValue: 1, // animate back open if released early
|
2017-02-17 22:41:23 +00:00
|
|
|
useNativeDriver: true,
|
2015-07-07 20:34:09 +00:00
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingTop: 18,
|
|
|
|
height: 90,
|
|
|
|
},
|
|
|
|
stream: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: 'rgb(230, 230, 230)',
|
|
|
|
},
|
|
|
|
card: {
|
|
|
|
margin: 8,
|
|
|
|
padding: 8,
|
|
|
|
borderRadius: 6,
|
|
|
|
backgroundColor: 'white',
|
|
|
|
shadowRadius: 2,
|
|
|
|
shadowColor: 'black',
|
|
|
|
shadowOpacity: 0.2,
|
|
|
|
shadowOffset: {height: 0.5},
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
padding: 4,
|
|
|
|
paddingBottom: 10,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
fontSize: 18,
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
},
|
|
|
|
headerText: {
|
|
|
|
fontSize: 25,
|
|
|
|
color: 'white',
|
|
|
|
shadowRadius: 3,
|
|
|
|
shadowColor: 'black',
|
|
|
|
shadowOpacity: 1,
|
|
|
|
shadowOffset: {height: 1},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = AnExSet;
|