Kaynağa Gözat

rn: refactor aspect ratio and reduced UI detectors

master
Saúl Ibarra Corretgé 5 yıl önce
ebeveyn
işleme
fe2b1f3d9f

+ 1
- 20
react/features/app/components/App.native.js Dosyayı Görüntüle

@@ -9,10 +9,7 @@ import { DialogContainer } from '../../base/dialog';
9 9
 import { CALL_INTEGRATION_ENABLED, updateFlags } from '../../base/flags';
10 10
 import '../../base/jwt';
11 11
 import { Platform } from '../../base/react';
12
-import {
13
-    AspectRatioDetector,
14
-    ReducedUIDetector
15
-} from '../../base/responsive-ui';
12
+import '../../base/responsive-ui';
16 13
 import { updateSettings } from '../../base/settings';
17 14
 import '../../google-api';
18 15
 import '../../mobile/audio-mode';
@@ -110,22 +107,6 @@ export class App extends AbstractApp {
110 107
         });
111 108
     }
112 109
 
113
-    /**
114
-     * Injects {@link AspectRatioDetector} in order to detect the aspect ratio
115
-     * of this {@code App}'s user interface and afford {@link AspectRatioAware}.
116
-     *
117
-     * @override
118
-     */
119
-    _createMainElement(component, props) {
120
-        return (
121
-            <AspectRatioDetector>
122
-                <ReducedUIDetector>
123
-                    { super._createMainElement(component, props) }
124
-                </ReducedUIDetector>
125
-            </AspectRatioDetector>
126
-        );
127
-    }
128
-
129 110
     /**
130 111
      * Attempts to disable the use of React Native
131 112
      * {@link ExceptionsManager#handleException} on platforms and in

+ 0
- 1
react/features/app/components/App.web.js Dosyayı Görüntüle

@@ -5,7 +5,6 @@ import React from 'react';
5 5
 
6 6
 import { DialogContainer } from '../../base/dialog';
7 7
 import '../../base/user-interaction';
8
-import '../../base/responsive-ui';
9 8
 import '../../chat';
10 9
 import '../../external-api';
11 10
 import '../../power-monitor';

+ 1
- 3
react/features/base/responsive-ui/actions.js Dosyayı Görüntüle

@@ -12,9 +12,7 @@ import type { Dispatch } from 'redux';
12 12
  * very brittle because it's completely disconnected from the UI which wants to
13 13
  * be rendered and, naturally, it broke on iPad where even the secondary Toolbar
14 14
  * didn't fit in the height. We do need to measure the actual UI at runtime and
15
- * determine whether and how to render it. I'm bumping from 240 to 300 because I
16
- * don't have the time now to refactor {@code ReducedUIDetector} or rip it out
17
- * completely.
15
+ * determine whether and how to render it.
18 16
  */
19 17
 const REDUCED_UI_THRESHOLD = 300;
20 18
 

+ 0
- 73
react/features/base/responsive-ui/components/AspectRatioDetector.js Dosyayı Görüntüle

@@ -1,73 +0,0 @@
1
-// @flow
2
-
3
-import React, { Component, type Node } from 'react';
4
-import { type Dispatch } from 'redux';
5
-
6
-import { connect } from '../../redux';
7
-
8
-import { setAspectRatio } from '../actions';
9
-import DimensionsDetector from './DimensionsDetector';
10
-
11
-/**
12
- * AspectRatioDetector component's property types.
13
- */
14
-type Props = {
15
-
16
-    /**
17
-     * The "onDimensionsHandler" handler.
18
-     */
19
-    _onDimensionsChanged: Function,
20
-
21
-    /**
22
-     * Any nested components.
23
-     */
24
-    children: Node
25
-};
26
-
27
-/**
28
- * A root {@link View} which captures the 'onLayout' event and figures out
29
- * the aspect ratio of the app.
30
- */
31
-class AspectRatioDetector extends Component<Props> {
32
-    /**
33
-     * Renders the root view and it's children.
34
-     *
35
-     * @returns {Component}
36
-     */
37
-    render() {
38
-        return (
39
-            <DimensionsDetector
40
-                onDimensionsChanged = { this.props._onDimensionsChanged } >
41
-                { this.props.children }
42
-            </DimensionsDetector>
43
-        );
44
-    }
45
-}
46
-
47
-/**
48
- * Maps dispatching of the aspect ratio actions to React component props.
49
- *
50
- * @param {Function} dispatch - Redux action dispatcher.
51
- * @private
52
- * @returns {{
53
- *     _onDimensionsChanged: Function
54
- * }}
55
- */
56
-function _mapDispatchToProps(dispatch: Dispatch<any>) {
57
-    return {
58
-        /**
59
-         * Handles the "on dimensions changed" event and dispatches aspect ratio
60
-         * changed action.
61
-         *
62
-         * @param {number} width - The new width for the component.
63
-         * @param {number} height - The new height for the component.
64
-         * @private
65
-         * @returns {void}
66
-         */
67
-        _onDimensionsChanged(width: number, height: number) {
68
-            dispatch(setAspectRatio(width, height));
69
-        }
70
-    };
71
-}
72
-
73
-export default connect(undefined, _mapDispatchToProps)(AspectRatioDetector);

+ 2
- 2
react/features/base/responsive-ui/components/DimensionsDetector.native.js Dosyayı Görüntüle

@@ -1,6 +1,6 @@
1 1
 // @flow
2 2
 
3
-import React, { Component } from 'react';
3
+import React, { PureComponent } from 'react';
4 4
 import { View } from 'react-native';
5 5
 
6 6
 import styles from './styles';
@@ -25,7 +25,7 @@ type Props = {
25 25
  * A {@link View} which captures the 'onLayout' event and calls a prop with the
26 26
  * component size.
27 27
  */
28
-export default class DimensionsDetector extends Component<Props> {
28
+export default class DimensionsDetector extends PureComponent<Props> {
29 29
     /**
30 30
      * Initializes a new DimensionsDetector instance.
31 31
      *

+ 0
- 74
react/features/base/responsive-ui/components/ReducedUIDetector.js Dosyayı Görüntüle

@@ -1,74 +0,0 @@
1
-// @flow
2
-
3
-import React, { Component, type Node } from 'react';
4
-import { type Dispatch } from 'redux';
5
-
6
-import { connect } from '../../redux';
7
-
8
-import { setReducedUI } from '../actions';
9
-import DimensionsDetector from './DimensionsDetector';
10
-
11
-
12
-/**
13
- * ReducedUIDetector component's property types.
14
- */
15
-type Props = {
16
-
17
-    /**
18
-     * The "onDimensionsHandler" handler.
19
-     */
20
-    _onDimensionsChanged: Function,
21
-
22
-    /**
23
-     * Any nested components.
24
-     */
25
-    children: Node
26
-};
27
-
28
-/**
29
- * A root {@link View} which captures the 'onLayout' event and figures out
30
- * if the UI is reduced.
31
- */
32
-class ReducedUIDetector extends Component<Props> {
33
-    /**
34
-     * Renders the root view and it's children.
35
-     *
36
-     * @returns {Component}
37
-     */
38
-    render() {
39
-        return (
40
-            <DimensionsDetector
41
-                onDimensionsChanged = { this.props._onDimensionsChanged } >
42
-                { this.props.children }
43
-            </DimensionsDetector>
44
-        );
45
-    }
46
-}
47
-
48
-/**
49
- * Maps dispatching of the reduced UI actions to React component props.
50
- *
51
- * @param {Function} dispatch - Redux action dispatcher.
52
- * @private
53
- * @returns {{
54
- *     _onDimensionsChanged: Function
55
- * }}
56
- */
57
-function _mapDispatchToProps(dispatch: Dispatch<any>) {
58
-    return {
59
-        /**
60
-         * Handles the "on dimensions changed" event and dispatches the
61
-         * reduced UI action.
62
-         *
63
-         * @param {number} width - The new width for the component.
64
-         * @param {number} height - The new height for the component.
65
-         * @private
66
-         * @returns {void}
67
-         */
68
-        _onDimensionsChanged(width: number, height: number) {
69
-            dispatch(setReducedUI(width, height));
70
-        }
71
-    };
72
-}
73
-
74
-export default connect(undefined, _mapDispatchToProps)(ReducedUIDetector);

+ 0
- 2
react/features/base/responsive-ui/components/index.js Dosyayı Görüntüle

@@ -1,4 +1,2 @@
1 1
 export * from './AspectRatioAware';
2
-export { default as AspectRatioDetector } from './AspectRatioDetector';
3 2
 export { default as DimensionsDetector } from './DimensionsDetector';
4
-export { default as ReducedUIDetector } from './ReducedUIDetector';

+ 1
- 0
react/features/base/responsive-ui/index.js Dosyayı Görüntüle

@@ -3,4 +3,5 @@ export * from './actionTypes';
3 3
 export * from './components';
4 4
 export * from './constants';
5 5
 
6
+import './middleware';
6 7
 import './reducer';

+ 83
- 0
react/features/base/responsive-ui/middleware.native.js Dosyayı Görüntüle

@@ -0,0 +1,83 @@
1
+// @flow
2
+
3
+import { Dimensions } from 'react-native';
4
+
5
+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../base/app';
6
+import { MiddlewareRegistry } from '../../base/redux';
7
+
8
+import { setAspectRatio, setReducedUI } from './actions';
9
+
10
+/**
11
+ * Dimensions change handler.
12
+ */
13
+let handler;
14
+
15
+/**
16
+ * Middleware that handles widnow dimension changes and updates the aspect ratio and
17
+ * reduced UI modes accordingly.
18
+ *
19
+ * @param {Store} store - The redux store.
20
+ * @returns {Function}
21
+ */
22
+MiddlewareRegistry.register(store => next => action => {
23
+    const result = next(action);
24
+
25
+    switch (action.type) {
26
+    case APP_WILL_UNMOUNT: {
27
+        _appWillUnmount();
28
+        break;
29
+    }
30
+    case APP_WILL_MOUNT:
31
+        _appWillMount(store);
32
+        break;
33
+
34
+    }
35
+
36
+    return result;
37
+});
38
+
39
+/**
40
+ * Notifies this feature that the action {@link APP_WILL_MOUNT} is being
41
+ * dispatched within a specific redux {@code store}.
42
+ *
43
+ * @param {Store} store - The redux store in which the specified {@code action}
44
+ * is being dispatched.
45
+ * @private
46
+ * @returns {void}
47
+ */
48
+function _appWillMount(store) {
49
+    handler = dim => {
50
+        _onDimensionsChange(dim, store);
51
+    };
52
+
53
+    Dimensions.addEventListener('change', handler);
54
+}
55
+
56
+/**
57
+ * Notifies this feature that the action {@link APP_WILL_UNMOUNT} is being
58
+ * dispatched within a specific redux {@code store}.
59
+ *
60
+ * @private
61
+ * @returns {void}
62
+ */
63
+function _appWillUnmount() {
64
+    Dimensions.removeEventListener('change', handler);
65
+
66
+    handler = undefined;
67
+}
68
+
69
+/**
70
+ * Handles window dimension changes.
71
+ *
72
+ * @param {Object} dimensions - The new dimensions.
73
+ * @param {Store} store - The redux store.
74
+ * @private
75
+ * @returns {void}
76
+ */
77
+function _onDimensionsChange(dimensions, store) {
78
+    const { width, height } = dimensions.window;
79
+    const { dispatch } = store;
80
+
81
+    dispatch(setAspectRatio(width, height));
82
+    dispatch(setReducedUI(width, height));
83
+}

+ 0
- 0
react/features/base/responsive-ui/middleware.web.js Dosyayı Görüntüle


+ 9
- 11
react/features/base/responsive-ui/reducer.js Dosyayı Görüntüle

@@ -13,16 +13,14 @@ const DEFAULT_STATE = {
13 13
     reducedUI: false
14 14
 };
15 15
 
16
-ReducerRegistry.register(
17
-    'features/base/responsive-ui',
18
-    (state = DEFAULT_STATE, action) => {
19
-        switch (action.type) {
20
-        case SET_ASPECT_RATIO:
21
-            return set(state, 'aspectRatio', action.aspectRatio);
16
+ReducerRegistry.register('features/base/responsive-ui', (state = DEFAULT_STATE, action) => {
17
+    switch (action.type) {
18
+    case SET_ASPECT_RATIO:
19
+        return set(state, 'aspectRatio', action.aspectRatio);
22 20
 
23
-        case SET_REDUCED_UI:
24
-            return set(state, 'reducedUI', action.reducedUI);
25
-        }
21
+    case SET_REDUCED_UI:
22
+        return set(state, 'reducedUI', action.reducedUI);
23
+    }
26 24
 
27
-        return state;
28
-    });
25
+    return state;
26
+});

Loading…
İptal
Kaydet