浏览代码

[RN] Add a "reduced UI" mode

It's detected based on a size threshold.
j8
Saúl Ibarra Corretgé 7 年前
父节点
当前提交
5305557ce5

+ 7
- 2
react/features/app/components/App.native.js 查看文件

@@ -7,7 +7,10 @@ import { Linking } from 'react-native';
7 7
 import '../../analytics';
8 8
 import '../../authentication';
9 9
 import { Platform } from '../../base/react';
10
-import { AspectRatioDetector } from '../../base/responsive-ui';
10
+import {
11
+    AspectRatioDetector,
12
+    ReducedUIDetector
13
+} from '../../base/responsive-ui';
11 14
 import '../../mobile/audio-mode';
12 15
 import '../../mobile/background';
13 16
 import '../../mobile/callkit';
@@ -97,7 +100,9 @@ export class App extends AbstractApp {
97 100
     _createElement(component, props) {
98 101
         return (
99 102
             <AspectRatioDetector>
100
-                { super._createElement(component, props) }
103
+                <ReducedUIDetector>
104
+                    { super._createElement(component, props) }
105
+                </ReducedUIDetector>
101 106
             </AspectRatioDetector>
102 107
         );
103 108
     }

+ 1
- 0
react/features/app/components/App.web.js 查看文件

@@ -1,6 +1,7 @@
1 1
 import { AtlasKitThemeProvider } from '@atlaskit/theme';
2 2
 import React from 'react';
3 3
 
4
+import '../../base/responsive-ui';
4 5
 import { getLocationContextRoot } from '../../base/util';
5 6
 import '../../room-lock';
6 7
 

+ 13
- 0
react/features/base/responsive-ui/actionTypes.js 查看文件

@@ -8,3 +8,16 @@
8 8
  * }
9 9
  */
10 10
 export const SET_ASPECT_RATIO = Symbol('SET_ASPECT_RATIO');
11
+
12
+/**
13
+ * The type of redux action which signals that the reduces UI mode was enabled
14
+ * or disabled.
15
+ *
16
+ * {
17
+ *     type: SET_REDUCED_UI,
18
+ *     reducedUI: boolean
19
+ * }
20
+ *
21
+ * @public
22
+ */
23
+export const SET_REDUCED_UI = Symbol('SET_REDUCED_UI');

+ 30
- 1
react/features/base/responsive-ui/actions.js 查看文件

@@ -1,10 +1,15 @@
1 1
 // @flow
2 2
 
3
-import { SET_ASPECT_RATIO } from './actionTypes';
3
+import { SET_ASPECT_RATIO, SET_REDUCED_UI } from './actionTypes';
4 4
 import { ASPECT_RATIO_NARROW, ASPECT_RATIO_WIDE } from './constants';
5 5
 
6 6
 import type { Dispatch } from 'redux';
7 7
 
8
+/**
9
+ * Size threshold for determining if we are in reduced UI mode or not.
10
+ */
11
+const REDUCED_UI_THRESHOLD = 240;
12
+
8 13
 /**
9 14
  * Sets the aspect ratio of the app's user interface based on specific width and
10 15
  * height.
@@ -34,3 +39,27 @@ export function setAspectRatio(width: number, height: number): Object {
34 39
         }
35 40
     };
36 41
 }
42
+
43
+/**
44
+ * Sets the "reduced UI" property. In reduced UI mode some components will
45
+ * be hidden if there is no space to render them.
46
+ *
47
+ * @param {number} width - Current usable width.
48
+ * @param {number} height - Current usable height.
49
+ * @returns {{
50
+ *     type: SET_REDUCED_UI,
51
+ *     reducedUI: boolean
52
+ * }}
53
+ */
54
+export function setReducedUI(width: number, height: number) {
55
+    return (dispatch: Dispatch<*>, getState: Function) => {
56
+        const reducedUI = Math.min(width, height) < REDUCED_UI_THRESHOLD;
57
+
58
+        if (reducedUI !== getState()['features/base/responsive-ui'].reducedUI) {
59
+            return dispatch({
60
+                type: SET_REDUCED_UI,
61
+                reducedUI
62
+            });
63
+        }
64
+    };
65
+}

+ 72
- 0
react/features/base/responsive-ui/components/ReducedUIDetector.js 查看文件

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

+ 1
- 0
react/features/base/responsive-ui/components/index.js 查看文件

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

+ 6
- 2
react/features/base/responsive-ui/reducer.js 查看文件

@@ -1,13 +1,14 @@
1 1
 import { ReducerRegistry, set } from '../redux';
2 2
 
3
-import { SET_ASPECT_RATIO } from './actionTypes';
3
+import { SET_ASPECT_RATIO, SET_REDUCED_UI } from './actionTypes';
4 4
 import { ASPECT_RATIO_NARROW } from './constants';
5 5
 
6 6
 /**
7 7
  * The initial redux state of the feature base/responsive-ui.
8 8
  */
9 9
 const _INITIAL_STATE = {
10
-    aspectRatio: ASPECT_RATIO_NARROW
10
+    aspectRatio: ASPECT_RATIO_NARROW,
11
+    reducedUI: false
11 12
 };
12 13
 
13 14
 ReducerRegistry.register(
@@ -16,6 +17,9 @@ ReducerRegistry.register(
16 17
         switch (action.type) {
17 18
         case SET_ASPECT_RATIO:
18 19
             return set(state, 'aspectRatio', action.aspectRatio);
20
+
21
+        case SET_REDUCED_UI:
22
+            return set(state, 'reducedUI', action.reducedUI);
19 23
         }
20 24
 
21 25
         return state;

正在加载...
取消
保存