Skip to content

Commit 8b01131

Browse files
authored
Merge pull request #2 from BelkaLab/add_overlay_component
added slideBottomOverlay through RNN
2 parents 3de9044 + 7dda590 commit 8b01131

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { ComposableForm } from './src/ComposableForm';
22
import SharedOptions from './src/options/SharedOptions';
3+
import { SlideBottomOverlay } from './src/overlays/SlideBottomOverlay';
34
import { Navigation } from 'react-native-navigation';
5+
import { SLIDE_BOTTOM_OVERLAY_KEY } from './src/navigation/integration';
46

57
try {
68
Navigation.getLaunchArgs();
9+
Navigation.registerComponent(SLIDE_BOTTOM_OVERLAY_KEY, () => SlideBottomOverlay);
710
SharedOptions.setRNNAvailable(true);
811
} catch (err) {
912
SharedOptions.setRNNAvailable(false);
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import React, { Component } from 'react';
2+
import { Animated, Dimensions, Easing, PanResponder, StyleSheet, TouchableWithoutFeedback, View } from 'react-native';
3+
import { ComponentEvent, Navigation } from 'react-native-navigation';
4+
import { Colors } from '../../styles/colors';
5+
6+
const deviceHeight = Dimensions.get('window').height;
7+
const ANIM_DURATION = 200;
8+
9+
interface ISlideBottomOverlayProps extends ComponentEvent {
10+
renderOverlayComponent: (dismissOverlay: () => void) => React.ReactElement<{}>;
11+
}
12+
13+
interface IState {
14+
overlayHeight: number;
15+
overlaySlide: Animated.Value;
16+
backgroundOpacity: Animated.Value;
17+
}
18+
19+
export default class SlideBottomOverlay extends Component<ISlideBottomOverlayProps, IState> {
20+
constructor(props: ISlideBottomOverlayProps) {
21+
super(props);
22+
23+
this.state = {
24+
overlayHeight: 0,
25+
overlaySlide: new Animated.Value(deviceHeight),
26+
backgroundOpacity: new Animated.Value(0)
27+
};
28+
}
29+
30+
private dismissOverlay = () => {
31+
Animated.parallel([
32+
Animated.timing(this.state.overlaySlide, {
33+
toValue: this.state.overlayHeight,
34+
duration: ANIM_DURATION,
35+
easing: Easing.ease,
36+
useNativeDriver: true
37+
}),
38+
Animated.timing(this.state.backgroundOpacity, {
39+
toValue: 0,
40+
duration: ANIM_DURATION,
41+
useNativeDriver: false
42+
})
43+
]).start(() => {
44+
Navigation.dismissOverlay(this.props.componentId);
45+
});
46+
};
47+
48+
render() {
49+
return (
50+
<TouchableWithoutFeedback style={{ flex: 1 }} onPress={this.dismissOverlay}>
51+
<Animated.View
52+
style={[
53+
styles.backgroundContainer,
54+
{
55+
backgroundColor: this.state.backgroundOpacity.interpolate({
56+
inputRange: [0, 1],
57+
outputRange: ['transparent', Colors.OVERLAY_OPACITY]
58+
})
59+
}
60+
]}
61+
>
62+
<Animated.View
63+
style={{
64+
transform: [{ translateY: this.state.overlaySlide }]
65+
}}
66+
{...PanResponder.create({
67+
onStartShouldSetPanResponder: () => true
68+
}).panHandlers}
69+
>
70+
<TouchableWithoutFeedback
71+
onLayout={({ nativeEvent }) => {
72+
if (this.state.overlayHeight === 0) {
73+
this.setState({ overlayHeight: nativeEvent.layout.height });
74+
this.state.overlaySlide.setValue(nativeEvent.layout.height);
75+
76+
Animated.parallel([
77+
Animated.timing(this.state.overlaySlide, {
78+
toValue: 0,
79+
duration: ANIM_DURATION,
80+
easing: Easing.ease,
81+
useNativeDriver: true
82+
}),
83+
Animated.timing(this.state.backgroundOpacity, {
84+
toValue: 1,
85+
duration: ANIM_DURATION,
86+
useNativeDriver: false
87+
})
88+
]).start();
89+
}
90+
}}
91+
>
92+
<View style={styles.overlayContainer}>{this.props.renderOverlayComponent(this.dismissOverlay)}</View>
93+
</TouchableWithoutFeedback>
94+
</Animated.View>
95+
</Animated.View>
96+
</TouchableWithoutFeedback>
97+
);
98+
}
99+
}
100+
101+
const styles = StyleSheet.create({
102+
backgroundContainer: {
103+
flex: 1,
104+
justifyContent: 'flex-end',
105+
alignItems: 'stretch',
106+
backgroundColor: 'transparent'
107+
},
108+
overlayContainer: {
109+
overflow: 'hidden',
110+
maxHeight: deviceHeight * 0.8,
111+
borderTopRightRadius: 8,
112+
borderTopLeftRadius: 8
113+
}
114+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import SlideBottomOverlay from './SlideBottomOverlay';
2+
3+
export { SlideBottomOverlay };

0 commit comments

Comments
 (0)