Browse Source

rn: refactor BottomSheet

Avoid using a Modal since those create trouble with the view hierarchy.
master
Saúl Ibarra Corretgé 6 years ago
parent
commit
70dc22c107

+ 24
- 41
react/features/base/dialog/components/native/BottomSheet.js View File

@@ -1,10 +1,10 @@
1 1
 // @flow
2 2
 
3
-import React, { Component, type Node } from 'react';
4
-import { TouchableWithoutFeedback, View } from 'react-native';
3
+import React, { PureComponent, type Node } from 'react';
4
+import { SafeAreaView, View } from 'react-native';
5 5
 
6 6
 import { ColorSchemeRegistry } from '../../../color-scheme';
7
-import { Modal } from '../../../react';
7
+import { SlidingView } from '../../../react';
8 8
 import { connect } from '../../../redux';
9 9
 import { StyleType } from '../../../styles';
10 10
 
@@ -33,19 +33,22 @@ type Props = {
33 33
 };
34 34
 
35 35
 /**
36
- * A component emulating Android's BottomSheet. For all intents and purposes,
37
- * this component has been designed to work and behave as a {@code Dialog}.
36
+ * A component emulating Android's BottomSheet.
38 37
  */
39
-class BottomSheet extends Component<Props> {
38
+class BottomSheet extends PureComponent<Props> {
40 39
     /**
41
-     * Initializes a new {@code BottomSheet} instance.
40
+     * Assembles a style for the BottomSheet container.
42 41
      *
43
-     * @inheritdoc
42
+     * @private
43
+     * @returns {StyleType}
44 44
      */
45
-    constructor(props: Props) {
46
-        super(props);
45
+    _getContainerStyle() {
46
+        const { _styles } = this.props;
47 47
 
48
-        this._onCancel = this._onCancel.bind(this);
48
+        return {
49
+            ...styles.container,
50
+            backgroundColor: _styles.sheet.backgroundColor
51
+        };
49 52
     }
50 53
 
51 54
     /**
@@ -57,39 +60,19 @@ class BottomSheet extends Component<Props> {
57 60
     render() {
58 61
         const { _styles } = this.props;
59 62
 
60
-        return [
61
-            <View
62
-                key = 'overlay'
63
-                style = { styles.overlay } />,
64
-            <Modal
65
-                key = 'modal'
66
-                onRequestClose = { this._onCancel }
67
-                visible = { true }>
68
-                <View style = { styles.container }>
69
-                    <TouchableWithoutFeedback
70
-                        onPress = { this._onCancel } >
71
-                        <View style = { styles.backdrop } />
72
-                    </TouchableWithoutFeedback>
63
+        return (
64
+            <SlidingView
65
+                onHide = { this.props.onCancel }
66
+                position = 'bottom'
67
+                show = { true }>
68
+                <SafeAreaView
69
+                    style = { this._getContainerStyle() }>
73 70
                     <View style = { _styles.sheet }>
74 71
                         { this.props.children }
75 72
                     </View>
76
-                </View>
77
-            </Modal>
78
-        ];
79
-    }
80
-
81
-    _onCancel: () => void;
82
-
83
-    /**
84
-     * Cancels the dialog by calling the onCancel prop callback.
85
-     *
86
-     * @private
87
-     * @returns {void}
88
-     */
89
-    _onCancel() {
90
-        const { onCancel } = this.props;
91
-
92
-        onCancel && onCancel();
73
+                </SafeAreaView>
74
+            </SlidingView>
75
+        );
93 76
     }
94 77
 }
95 78
 

+ 4
- 21
react/features/base/dialog/components/native/styles.js View File

@@ -28,31 +28,14 @@ export const PLACEHOLDER_COLOR = ColorPalette.lightGrey;
28 28
  * {@link https://material.io/guidelines/components/bottom-sheets.html}.
29 29
  */
30 30
 export const bottomSheetStyles = createStyleSheet({
31
-    /**
32
-     * Style for a backdrop which dims the view in the background. This view
33
-     * will also be clickable. The backgroundColor is applied to the overlay
34
-     * view instead, so the modal animation doesn't affect the backdrop.
35
-     */
36
-    backdrop: {
37
-        ...StyleSheet.absoluteFillObject
38
-    },
39
-
40 31
     /**
41 32
      * Style for the container of the sheet.
42 33
      */
43 34
     container: {
44
-        alignItems: 'flex-end',
45
-        flex: 1,
46
-        flexDirection: 'row',
47
-        justifyContent: 'center'
48
-    },
49
-
50
-    /**
51
-     * Style for an overlay on top of which the sheet will be displayed.
52
-     */
53
-    overlay: {
54
-        ...StyleSheet.absoluteFillObject,
55
-        backgroundColor: 'rgba(127, 127, 127, 0.6)'
35
+        bottom: 0,
36
+        left: 0,
37
+        position: 'absolute',
38
+        right: 0
56 39
     }
57 40
 });
58 41
 

+ 1
- 0
react/features/base/react/components/native/SlidingView.js View File

@@ -162,6 +162,7 @@ export default class SlidingView extends PureComponent<Props, State> {
162 162
                     <View style = { styles.sliderViewShadow } />
163 163
                 </TouchableWithoutFeedback>
164 164
                 <Animated.View
165
+                    pointerEvents = 'box-none'
165 166
                     style = { this._getContentStyle() }>
166 167
                     { this.props.children }
167 168
                 </Animated.View>

Loading…
Cancel
Save