Files
Krzysztof Magiera 067b440b33 Interactable.View implementation based on reanimated and gesture handler (#106)
This PR adds an implementation of Interactable.View to examples folder. The implementation is pretty feature full with the exception of alertAreas that I haven't had time yet to work on.
2018-09-21 16:18:27 +02:00

119 lines
3.4 KiB
JavaScript

import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import Interactable from '../../Interactable';
import Animated from 'react-native-reanimated';
export default class IconDrawer extends Component {
constructor(props) {
super(props);
this._deltaX = new Animated.Value(0);
}
render() {
return (
<View style={styles.container}>
<View style={{ backgroundColor: 'red' }}>
<View
style={{
position: 'absolute',
right: 0,
height: 75,
flexDirection: 'row',
alignItems: 'center',
}}>
<Animated.View
style={[
styles.button,
{
opacity: Animated.interpolate(this._deltaX, {
inputRange: [-230, -230, -180, -180],
outputRange: [1, 1, 0, 0],
}),
transform: [
{
scale: Animated.interpolate(this._deltaX, {
inputRange: [-230, -230, -180, -180],
outputRange: [1, 1, 0.8, 0.8],
}),
},
],
},
]}
/>
<Animated.View
style={[
styles.button,
{
opacity: Animated.interpolate(this._deltaX, {
inputRange: [-165, -165, -115, -115],
outputRange: [1, 1, 0, 0],
}),
transform: [
{
scale: Animated.interpolate(this._deltaX, {
inputRange: [-165, -165, -115, -115],
outputRange: [1, 1, 0.8, 0.8],
}),
},
],
},
]}
/>
<Animated.View
style={[
styles.button,
{
opacity: Animated.interpolate(this._deltaX, {
inputRange: [-100, -100, -50, -50],
outputRange: [1, 1, 0, 0],
}),
transform: [
{
scale: Animated.interpolate(this._deltaX, {
inputRange: [-100, -100, -50, -50],
outputRange: [1, 1, 0.8, 0.8],
}),
},
],
},
]}
/>
</View>
<Interactable.View
horizontalOnly={true}
snapPoints={[{ x: 0, id: 'closed' }, { x: -230, id: 'open' }]}
onSnap={this.onDrawerSnap}
animatedValueX={this._deltaX}>
<View
style={{
left: 0,
right: 0,
height: 75,
backgroundColor: '#e0e0e0',
}}
/>
</Interactable.View>
</View>
</View>
);
}
onDrawerSnap(event) {
const snapPointId = event.nativeEvent.id;
console.log(`drawer state is ${snapPointId}`);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: 'white',
},
button: {
width: 40,
height: 40,
marginRight: 25,
backgroundColor: 'blue',
},
});