瀏覽代碼

[RN] Don't destroy containers when they are not visible

This essentially reverts
023359b9d2

In the filmstrip we keep a container full of thumbnail views. Destroying these
every time we want we want to hide it is costly, as new renderers have to be
recreated, and they lack context, so there is an increased chance for "black
thumbnails".
j8
Saúl Ibarra Corretgé 8 年之前
父節點
當前提交
157eadc44a

+ 0
- 5
react/features/base/react/components/AbstractContainer.js 查看文件

@@ -69,11 +69,6 @@ export default class AbstractContainer extends Component {
69 69
             ...filteredProps
70 70
         } = props || this.props;
71 71
 
72
-        // visible
73
-        if (typeof visible !== 'undefined' && !visible) {
74
-            return null;
75
-        }
76
-
77 72
         return React.createElement(type, filteredProps, children);
78 73
     }
79 74
 }

+ 45
- 16
react/features/base/react/components/native/Container.js 查看文件

@@ -1,5 +1,6 @@
1 1
 import React from 'react';
2 2
 import {
3
+    Dimensions,
3 4
     TouchableHighlight,
4 5
     TouchableWithoutFeedback,
5 6
     View
@@ -28,26 +29,54 @@ export default class Container extends AbstractContainer {
28 29
      */
29 30
     render() {
30 31
         // eslint-disable-next-line prefer-const
31
-        let { onClick, style, touchFeedback, ...props } = this.props;
32
+        let { onClick, style, touchFeedback, visible, ...props } = this.props;
33
+
34
+        // visible
35
+
36
+        // The following property is responsible to hide/show this Container by
37
+        // moving it out of site of the screen boundaries. An attempt to use the
38
+        // opacity property was made in order to eventually implement a
39
+        // fadeIn/fadeOut animation, however a known React Native problem was
40
+        // discovered, which allows the view to still capture touch events even
41
+        // if hidden.
42
+        let visibilityStyle;
43
+
44
+        if (typeof visible !== 'undefined' && !visible) {
45
+            const windowDimensions = Dimensions.get('window');
46
+
47
+            visibilityStyle = {
48
+                bottom: -windowDimensions.height,
49
+                right: -windowDimensions.width
50
+            };
51
+        }
52
+
53
+        // onClick & touchFeedback
54
+        (typeof touchFeedback === 'undefined') && (touchFeedback = onClick);
55
+
56
+        const renderParent = touchFeedback || onClick;
57
+
58
+        if (!renderParent && visibilityStyle) {
59
+            style = {
60
+                ...style,
61
+                ...visibilityStyle
62
+            };
63
+        }
32 64
 
33 65
         // eslint-disable-next-line object-property-newline
34 66
         let component = this._render(View, { ...props, style });
35 67
 
36
-        if (component) {
37
-            // onClick & touchFeedback
38
-            (typeof touchFeedback === 'undefined') && (touchFeedback = onClick);
39
-            if (touchFeedback || onClick) {
40
-                const parentType
41
-                    = touchFeedback
42
-                        ? TouchableHighlight
43
-                        : TouchableWithoutFeedback;
44
-                const parentProps = {};
45
-
46
-                onClick && (parentProps.onPress = onClick);
47
-
48
-                component
49
-                    = React.createElement(parentType, parentProps, component);
50
-            }
68
+        if (renderParent) {
69
+            const parentType
70
+                = touchFeedback
71
+                    ? TouchableHighlight
72
+                    : TouchableWithoutFeedback;
73
+            const parentProps = {};
74
+
75
+            onClick && (parentProps.onPress = onClick);
76
+            visibilityStyle && (parentProps.style = visibilityStyle);
77
+
78
+            component
79
+                = React.createElement(parentType, parentProps, component);
51 80
         }
52 81
 
53 82
         return component;

+ 6
- 0
react/features/base/react/components/web/Container.js 查看文件

@@ -20,6 +20,12 @@ export default class Container extends AbstractContainer {
20 20
      * @returns {ReactElement}
21 21
      */
22 22
     render() {
23
+        const { visible } = this.props;
24
+
25
+        if (typeof visible !== 'undefined' && !visible) {
26
+            return null;
27
+        }
28
+
23 29
         return this._render('div');
24 30
     }
25 31
 }

Loading…
取消
儲存