Browse Source

[RN] Make full-screen more resilient on Android (Coding style: consistency)

master
Lyubo Marinov 7 years ago
parent
commit
e2cf7a788d

+ 7
- 7
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java View File

@@ -416,20 +416,20 @@ public class JitsiMeetView extends FrameLayout {
416 416
     }
417 417
 
418 418
     /**
419
-     * Handler for focus changes which the window where this view is attached to
420
-     * is experiencing. Here we call into the Immersive mode plugin, so it
421
-     * triggers an event.
419
+     * Called when the window containing this view gains or loses focus.
422 420
      *
423
-     * @param hasFocus - Whether the window / view has focus or not.
421
+     * @param hasFocus If the window of this view now has focus, {@code true};
422
+     * otherwise, {@code false}.
424 423
      */
425 424
     @Override
426 425
     public void onWindowFocusChanged(boolean hasFocus) {
427 426
         super.onWindowFocusChanged(hasFocus);
428 427
 
429
-        RNImmersiveModule module = RNImmersiveModule.getInstance();
428
+        // https://github.com/mockingbot/react-native-immersive#restore-immersive-state
429
+        RNImmersiveModule immersive = RNImmersiveModule.getInstance();
430 430
 
431
-        if (hasFocus && module != null) {
432
-            module.emitImmersiveStateChangeEvent();
431
+        if (hasFocus && immersive != null) {
432
+            immersive.emitImmersiveStateChangeEvent();
433 433
         }
434 434
     }
435 435
 

+ 4
- 4
react/features/base/jwt/reducer.js View File

@@ -5,7 +5,7 @@ import { equals, set, ReducerRegistry } from '../redux';
5 5
 import { SET_CALLEE_INFO_VISIBLE, SET_JWT } from './actionTypes';
6 6
 
7 7
 /**
8
- * The initial redux state of the feature jwt.
8
+ * The default/initial redux state of the feature jwt.
9 9
  *
10 10
  * @private
11 11
  * @type {{
@@ -13,7 +13,7 @@ import { SET_CALLEE_INFO_VISIBLE, SET_JWT } from './actionTypes';
13 13
  *     isGuest: boolean
14 14
  * }}
15 15
  */
16
-const _INITIAL_STATE = {
16
+const DEFAULT_STATE = {
17 17
     /**
18 18
      * The indicator which determines whether (the) {@code CalleeInfo} is
19 19
      * visible.
@@ -42,7 +42,7 @@ const _INITIAL_STATE = {
42 42
  */
43 43
 ReducerRegistry.register(
44 44
     'features/base/jwt',
45
-    (state = _INITIAL_STATE, action) => {
45
+    (state = DEFAULT_STATE, action) => {
46 46
         switch (action.type) {
47 47
         case SET_CALLEE_INFO_VISIBLE:
48 48
             return set(state, 'calleeInfoVisible', action.calleeInfoVisible);
@@ -51,7 +51,7 @@ ReducerRegistry.register(
51 51
             // eslint-disable-next-line no-unused-vars
52 52
             const { type, ...payload } = action;
53 53
             const nextState = {
54
-                ..._INITIAL_STATE,
54
+                ...DEFAULT_STATE,
55 55
                 ...payload
56 56
             };
57 57
 

+ 6
- 4
react/features/base/lib-jitsi-meet/reducer.js View File

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 import { ReducerRegistry } from '../redux';
2 4
 
3 5
 import {
@@ -8,18 +10,18 @@ import {
8 10
 } from './actionTypes';
9 11
 
10 12
 /**
11
- * The initial state of the feature base/lib-jitsi-meet.
13
+ * The default/initial redux state of the feature base/lib-jitsi-meet.
12 14
  *
13 15
  * @type {Object}
14 16
  */
15
-const INITIAL_STATE = {};
17
+const DEFAULT_STATE = {};
16 18
 
17 19
 ReducerRegistry.register(
18 20
     'features/base/lib-jitsi-meet',
19
-    (state = INITIAL_STATE, action) => {
21
+    (state = DEFAULT_STATE, action) => {
20 22
         switch (action.type) {
21 23
         case LIB_DID_DISPOSE:
22
-            return INITIAL_STATE;
24
+            return DEFAULT_STATE;
23 25
 
24 26
         case LIB_DID_INIT:
25 27
             return {

+ 8
- 6
react/features/base/logging/reducer.js View File

@@ -1,18 +1,20 @@
1
+// @flow
2
+
1 3
 import { equals, ReducerRegistry } from '../redux';
2 4
 
3 5
 import { SET_LOGGING_CONFIG } from './actionTypes';
4 6
 
5 7
 /**
6
- * The initial state of the feature base/logging.
8
+ * The default/initial redux state of the feature base/logging.
7 9
  *
8
- * XXX When making any changes to the INITIAL_STATE make sure to also update
10
+ * XXX When making any changes to the DEFAULT_STATE make sure to also update
9 11
  * logging_config.js file located in the root directory of this project !!!
10 12
  *
11 13
  * @type {{
12 14
  *     config: Object
13 15
  * }}
14 16
  */
15
-const INITIAL_STATE = {
17
+const DEFAULT_STATE = {
16 18
     config: {
17 19
         defaultLogLevel: 'trace',
18 20
 
@@ -26,7 +28,7 @@ const INITIAL_STATE = {
26 28
 
27 29
 ReducerRegistry.register(
28 30
     'features/base/logging',
29
-    (state = INITIAL_STATE, action) => {
31
+    (state = DEFAULT_STATE, action) => {
30 32
         switch (action.type) {
31 33
         case SET_LOGGING_CONFIG:
32 34
             return _setLoggingConfig(state, action);
@@ -48,9 +50,9 @@ ReducerRegistry.register(
48 50
  */
49 51
 function _setLoggingConfig(state, action) {
50 52
     const config = {
51
-        // The config of INITIAL_STATE is the default configuration of the
53
+        // The config of DEFAULT_STATE is the default configuration of the
52 54
         // feature base/logging.
53
-        ...INITIAL_STATE.config,
55
+        ...DEFAULT_STATE.config,
54 56
         ...action.config
55 57
     };
56 58
 

+ 5
- 3
react/features/base/responsive-ui/reducer.js View File

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

+ 45
- 30
react/features/mobile/background/middleware.js View File

@@ -1,16 +1,13 @@
1
-/* @flow */
1
+// @flow
2 2
 
3 3
 import { AppState } from 'react-native';
4 4
 import type { Dispatch } from 'redux';
5 5
 
6
-import {
7
-    APP_WILL_MOUNT,
8
-    APP_WILL_UNMOUNT
9
-} from '../../app';
6
+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../app';
10 7
 import { MiddlewareRegistry } from '../../base/redux';
11 8
 
12 9
 import {
13
-    _setAppStateListener,
10
+    _setAppStateListener as _setAppStateListenerA,
14 11
     _setBackgroundVideoMuted,
15 12
     appStateChanged
16 13
 } from './actions';
@@ -25,39 +22,29 @@ import {
25 22
  * required to mute or unmute the local video in case the application goes to
26 23
  * the background or comes back from it.
27 24
  *
28
- * @param {Store} store - Redux store.
25
+ * @param {Store} store - The redux store.
29 26
  * @returns {Function}
30 27
  * @see {@link https://facebook.github.io/react-native/docs/appstate.html}
31 28
  */
32 29
 MiddlewareRegistry.register(store => next => action => {
33 30
     switch (action.type) {
34
-    case _SET_APP_STATE_LISTENER: {
35
-        // Remove the current/old AppState listener.
36
-        const { appStateListener } = store.getState()['features/background'];
37
-
38
-        if (appStateListener) {
39
-            AppState.removeEventListener('change', appStateListener);
40
-        }
41
-
42
-        // Add the new AppState listener.
43
-        if (action.listener) {
44
-            AppState.addEventListener('change', action.listener);
45
-        }
46
-        break;
47
-    }
31
+    case _SET_APP_STATE_LISTENER:
32
+        return _setAppStateListenerF(store, next, action);
48 33
 
49 34
     case APP_STATE_CHANGED:
50 35
         _appStateChanged(store.dispatch, action.appState);
51 36
         break;
52 37
 
53
-    case APP_WILL_MOUNT:
54
-        store.dispatch(
55
-            _setAppStateListener(
56
-                _onAppStateChange.bind(undefined, store.dispatch)));
38
+    case APP_WILL_MOUNT: {
39
+        const { dispatch } = store;
40
+
41
+        dispatch(
42
+            _setAppStateListenerA(_onAppStateChange.bind(undefined, dispatch)));
57 43
         break;
44
+    }
58 45
 
59 46
     case APP_WILL_UNMOUNT:
60
-        store.dispatch(_setAppStateListener(null));
47
+        store.dispatch(_setAppStateListenerA(undefined));
61 48
         break;
62 49
     }
63 50
 
@@ -65,11 +52,11 @@ MiddlewareRegistry.register(store => next => action => {
65 52
 });
66 53
 
67 54
 /**
68
- * Handles app state changes. Dispatches the necessary Redux actions for the
55
+ * Handles app state changes. Dispatches the necessary redux actions for the
69 56
  * local video to be muted when the app goes to the background, and to be
70 57
  * unmuted when the app comes back.
71 58
  *
72
- * @param {Dispatch} dispatch - Redux dispatch function.
59
+ * @param {Dispatch} dispatch - The redux {@code dispatch} function.
73 60
  * @param {string} appState - The current app state.
74 61
  * @private
75 62
  * @returns {void}
@@ -97,9 +84,9 @@ function _appStateChanged(dispatch: Function, appState: string) {
97 84
 
98 85
 /**
99 86
  * Called by React Native's AppState API to notify that the application state
100
- * has changed. Dispatches the change within the (associated) Redux store.
87
+ * has changed. Dispatches the change within the (associated) redux store.
101 88
  *
102
- * @param {Dispatch} dispatch - Redux dispatch function.
89
+ * @param {Dispatch} dispatch - The redux {@code dispatch} function.
103 90
  * @param {string} appState - The current application execution state.
104 91
  * @private
105 92
  * @returns {void}
@@ -107,3 +94,31 @@ function _appStateChanged(dispatch: Function, appState: string) {
107 94
 function _onAppStateChange(dispatch: Dispatch<*>, appState: string) {
108 95
     dispatch(appStateChanged(appState));
109 96
 }
97
+
98
+/**
99
+ * Notifies the feature filmstrip that the action
100
+ * {@link _SET_IMMERSIVE_LISTENER} is being dispatched within a specific redux
101
+ * store.
102
+ *
103
+ * @param {Store} store - The redux store in which the specified action is being
104
+ * dispatched.
105
+ * @param {Dispatch} next - The redux dispatch function to dispatch the
106
+ * specified action to the specified store.
107
+ * @param {Action} action - The redux action {@code _SET_IMMERSIVE_LISTENER}
108
+ * which is being dispatched in the specified store.
109
+ * @private
110
+ * @returns {Object} The value returned by {@code next(action)}.
111
+ */
112
+function _setAppStateListenerF({ getState }, next, action) {
113
+    // Remove the old AppState listener and add the new one.
114
+    const { appStateListener: oldListener } = getState()['features/background'];
115
+    const result = next(action);
116
+    const { appStateListener: newListener } = getState()['features/background'];
117
+
118
+    if (oldListener !== newListener) {
119
+        oldListener && AppState.removeEventListener('change', oldListener);
120
+        newListener && AppState.addEventListener('change', newListener);
121
+    }
122
+
123
+    return result;
124
+}

+ 7
- 2
react/features/mobile/background/reducer.js View File

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 import { ReducerRegistry } from '../../base/redux';
2 4
 
3 5
 import {
@@ -5,13 +7,16 @@ import {
5 7
     APP_STATE_CHANGED
6 8
 } from './actionTypes';
7 9
 
8
-const INITIAL_STATE = {
10
+/**
11
+ * The default/initial redux state of the feature background.
12
+ */
13
+const DEFAULT_STATE = {
9 14
     appState: 'active'
10 15
 };
11 16
 
12 17
 ReducerRegistry.register(
13 18
     'features/background',
14
-    (state = INITIAL_STATE, action) => {
19
+    (state = DEFAULT_STATE, action) => {
15 20
         switch (action.type) {
16 21
         case _SET_APP_STATE_LISTENER:
17 22
             return {

+ 2
- 1
react/features/mobile/full-screen/actionTypes.js View File

@@ -1,5 +1,6 @@
1 1
 /**
2
- * The type of redux action to set the Immersive change event listener.
2
+ * The type of (redux) action to set the react-native-immersive's change event
3
+ * listener.
3 4
  *
4 5
  * {
5 6
  *     type: _SET_IMMERSIVE_LISTENER,

+ 4
- 3
react/features/mobile/full-screen/actions.js View File

@@ -3,13 +3,14 @@
3 3
 import { _SET_IMMERSIVE_LISTENER } from './actionTypes';
4 4
 
5 5
 /**
6
- * Sets the listener to be used with React Native's Immersive API.
6
+ * Sets the change event listener to be used with react-native-immersive's API.
7 7
  *
8
- * @param {Function} listener - Function to be set as the change event listener.
8
+ * @param {Function} [listener] - The function to be used with
9
+ * react-native-immersive's API as the change event listener.
9 10
  * @protected
10 11
  * @returns {{
11 12
  *     type: _SET_IMMERSIVE_LISTENER,
12
- *     listener: Function
13
+ *     listener: ?Function
13 14
  * }}
14 15
  */
15 16
 export function _setImmersiveListener(listener: ?Function) {

+ 59
- 39
react/features/mobile/full-screen/middleware.js View File

@@ -14,7 +14,7 @@ import {
14 14
 import { Platform } from '../../base/react';
15 15
 import { MiddlewareRegistry } from '../../base/redux';
16 16
 
17
-import { _setImmersiveListener } from './actions';
17
+import { _setImmersiveListener as _setImmersiveListenerA } from './actions';
18 18
 import { _SET_IMMERSIVE_LISTENER } from './actionTypes';
19 19
 
20 20
 /**
@@ -28,59 +28,47 @@ import { _SET_IMMERSIVE_LISTENER } from './actionTypes';
28 28
  * @param {Store} store - The redux store.
29 29
  * @returns {Function}
30 30
  */
31
-MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
32
-    const result = next(action);
33
-
34
-    let fullScreen = null;
35
-
31
+MiddlewareRegistry.register(store => next => action => {
36 32
     switch (action.type) {
37 33
     case _SET_IMMERSIVE_LISTENER:
38
-        // XXX The React Native module Immersive is only implemented on Android
39
-        // and throws on other platforms.
40
-        if (Platform.OS === 'android') {
41
-            // Remove the current/old Immersive listener.
42
-            const { listener } = getState()['features/full-screen'];
43
-
44
-            listener && Immersive.removeImmersiveListener(listener);
45
-
46
-            // Add the new listener.
47
-            action.listener && Immersive.addImmersiveListener(action.listener);
48
-        }
49
-        break;
34
+        return _setImmersiveListenerF(store, next, action);
50 35
 
51 36
     case APP_WILL_MOUNT: {
52
-        const context = {
53
-            dispatch,
54
-            getState
55
-        };
37
+        const result = next(action);
56 38
 
57
-        dispatch(
58
-            _setImmersiveListener(_onImmersiveChange.bind(undefined, context)));
59
-        break;
39
+        store.dispatch(
40
+            _setImmersiveListenerA(_onImmersiveChange.bind(undefined, store)));
41
+
42
+        return result;
60 43
     }
44
+
61 45
     case APP_WILL_UNMOUNT:
62
-        _setImmersiveListener(undefined);
46
+        store.dispatch(_setImmersiveListenerA(undefined));
63 47
         break;
64 48
 
65 49
     case CONFERENCE_WILL_JOIN:
66 50
     case CONFERENCE_JOINED:
67 51
     case SET_AUDIO_ONLY: {
52
+        const result = next(action);
68 53
         const { audioOnly, conference, joining }
69
-            = getState()['features/base/conference'];
54
+            = store.getState()['features/base/conference'];
70 55
 
71
-        fullScreen = conference || joining ? !audioOnly : false;
72
-        break;
56
+        _setFullScreen(conference || joining ? !audioOnly : false);
57
+
58
+        return result;
73 59
     }
74 60
 
75 61
     case CONFERENCE_FAILED:
76
-    case CONFERENCE_LEFT:
77
-        fullScreen = false;
78
-        break;
79
-    }
62
+    case CONFERENCE_LEFT: {
63
+        const result = next(action);
80 64
 
81
-    fullScreen !== null && _setFullScreen(fullScreen);
65
+        _setFullScreen(false);
82 66
 
83
-    return result;
67
+        return result;
68
+    }
69
+    }
70
+
71
+    return next(action);
84 72
 });
85 73
 
86 74
 /**
@@ -119,11 +107,43 @@ function _setFullScreen(fullScreen: boolean) {
119 107
     // throws on other platforms.
120 108
     if (Platform.OS === 'android') {
121 109
         fullScreen ? Immersive.on() : Immersive.off();
110
+    } else {
111
+        // On platforms other than Android go with whatever React Native itself
112
+        // supports.
113
+        StatusBar.setHidden(fullScreen, 'slide');
114
+    }
115
+}
116
+
117
+/**
118
+ * Notifies the feature filmstrip that the action
119
+ * {@link _SET_IMMERSIVE_LISTENER} is being dispatched within a specific redux
120
+ * store.
121
+ *
122
+ * @param {Store} store - The redux store in which the specified action is being
123
+ * dispatched.
124
+ * @param {Dispatch} next - The redux dispatch function to dispatch the
125
+ * specified action to the specified store.
126
+ * @param {Action} action - The redux action {@code _SET_IMMERSIVE_LISTENER}
127
+ * which is being dispatched in the specified store.
128
+ * @private
129
+ * @returns {Object} The value returned by {@code next(action)}.
130
+ */
131
+function _setImmersiveListenerF({ getState }, next, action) {
132
+    // XXX The React Native module Immersive is only implemented on Android and
133
+    // throws on other platforms.
134
+    if (Platform.OS === 'android') {
135
+        // Remove the old Immersive listener and add the new one.
136
+        const { listener: oldListener } = getState()['features/full-screen'];
137
+        const result = next(action);
138
+        const { listener: newListener } = getState()['features/full-screen'];
139
+
140
+        if (oldListener !== newListener) {
141
+            oldListener && Immersive.removeImmersiveListener(oldListener);
142
+            newListener && Immersive.addImmersiveListener(newListener);
143
+        }
122 144
 
123
-        return;
145
+        return result;
124 146
     }
125 147
 
126
-    // On platforms other than Android go with whatever React Native itself
127
-    // supports.
128
-    StatusBar.setHidden(fullScreen, 'slide');
148
+    return next(action);
129 149
 }

+ 12
- 16
react/features/mobile/full-screen/reducer.js View File

@@ -1,21 +1,17 @@
1
+// @flow
2
+
1 3
 import { ReducerRegistry } from '../../base/redux';
2 4
 
3 5
 import { _SET_IMMERSIVE_LISTENER } from './actionTypes';
4 6
 
5
-const INITIAL_STATE = {
6
-    listener: undefined
7
-};
8
-
9
-ReducerRegistry.register(
10
-    'features/full-screen',
11
-    (state = INITIAL_STATE, action) => {
12
-        switch (action.type) {
13
-        case _SET_IMMERSIVE_LISTENER:
14
-            return {
15
-                ...state,
16
-                listener: action.listener
17
-            };
18
-        }
7
+ReducerRegistry.register('features/full-screen', (state = {}, action) => {
8
+    switch (action.type) {
9
+    case _SET_IMMERSIVE_LISTENER:
10
+        return {
11
+            ...state,
12
+            listener: action.listener
13
+        };
14
+    }
19 15
 
20
-        return state;
21
-    });
16
+    return state;
17
+});

+ 5
- 5
react/features/mobile/network-activity/reducer.js View File

@@ -1,4 +1,4 @@
1
-/* @flow */
1
+// @flow
2 2
 
3 3
 import { ReducerRegistry, set } from '../../base/redux';
4 4
 
@@ -9,13 +9,13 @@ import {
9 9
 } from './actionTypes';
10 10
 
11 11
 /**
12
- * The initial redux state of the feature network-activity.
12
+ * The default/initial redux state of the feature network-activity.
13 13
  *
14 14
  * @type {{
15 15
  *     requests: Map
16 16
  * }}
17 17
  */
18
-const _INITIAL_STATE = {
18
+const DEFAULT_STATE = {
19 19
     /**
20 20
      * The ongoing network requests i.e. the network request which have been
21 21
      * added to the redux store/state and have not been removed.
@@ -27,7 +27,7 @@ const _INITIAL_STATE = {
27 27
 
28 28
 ReducerRegistry.register(
29 29
     'features/network-activity',
30
-    (state = _INITIAL_STATE, action) => {
30
+    (state = DEFAULT_STATE, action) => {
31 31
         switch (action.type) {
32 32
         case _ADD_NETWORK_REQUEST: {
33 33
             const {
@@ -44,7 +44,7 @@ ReducerRegistry.register(
44 44
         }
45 45
 
46 46
         case _REMOVE_ALL_NETWORK_REQUESTS:
47
-            return set(state, 'requests', _INITIAL_STATE.requests);
47
+            return set(state, 'requests', DEFAULT_STATE.requests);
48 48
 
49 49
         case _REMOVE_NETWORK_REQUEST: {
50 50
             const { request: key } = action;

Loading…
Cancel
Save