瀏覽代碼

ref: change Chat to JitsiModal

j8
Bettenbuk Zoltan 5 年之前
父節點
當前提交
3a2081ffed

+ 13
- 70
react/features/chat/components/native/Chat.js 查看文件

@@ -1,18 +1,18 @@
1 1
 // @flow
2 2
 
3 3
 import React from 'react';
4
-import { KeyboardAvoidingView, SafeAreaView } from 'react-native';
4
+import { KeyboardAvoidingView } from 'react-native';
5 5
 
6
-import { ColorSchemeRegistry } from '../../../base/color-scheme';
7 6
 import { translate } from '../../../base/i18n';
8
-import { HeaderWithNavigation, SlidingView } from '../../../base/react';
7
+import { JitsiModal } from '../../../base/modal';
9 8
 import { connect } from '../../../base/redux';
10
-import { StyleType } from '../../../base/styles';
9
+
10
+import { CHAT_VIEW_MODAL_ID } from '../../constants';
11 11
 
12 12
 import AbstractChat, {
13 13
     _mapDispatchToProps,
14
-    _mapStateToProps as _abstractMapStateToProps,
15
-    type Props as AbstractProps
14
+    _mapStateToProps,
15
+    type Props
16 16
 } from '../AbstractChat';
17 17
 
18 18
 import ChatInputBar from './ChatInputBar';
@@ -20,88 +20,31 @@ import MessageContainer from './MessageContainer';
20 20
 import MessageRecipient from './MessageRecipient';
21 21
 import styles from './styles';
22 22
 
23
-type Props = AbstractProps & {
24
-
25
-    /**
26
-     * The color-schemed stylesheet of the feature.
27
-     */
28
-    _styles: StyleType
29
-};
30
-
31 23
 /**
32 24
  * Implements a React native component that renders the chat window (modal) of
33 25
  * the mobile client.
34 26
  */
35 27
 class Chat extends AbstractChat<Props> {
36
-    /**
37
-     * Instantiates a new instance.
38
-     *
39
-     * @inheritdoc
40
-     */
41
-    constructor(props: Props) {
42
-        super(props);
43
-
44
-        this._onClose = this._onClose.bind(this);
45
-    }
46
-
47 28
     /**
48 29
      * Implements React's {@link Component#render()}.
49 30
      *
50 31
      * @inheritdoc
51 32
      */
52 33
     render() {
53
-        const { _styles } = this.props;
54
-
55 34
         return (
56
-            <SlidingView
57
-                onHide = { this._onClose }
58
-                position = 'bottom'
59
-                show = { this.props._isOpen } >
35
+            <JitsiModal
36
+                headerLabelKey = 'chat.title'
37
+                modalId = { CHAT_VIEW_MODAL_ID }>
60 38
                 <KeyboardAvoidingView
61 39
                     behavior = 'padding'
62 40
                     style = { styles.chatContainer }>
63
-                    <HeaderWithNavigation
64
-                        headerLabelKey = 'chat.title'
65
-                        onPressBack = { this._onClose } />
66
-                    <SafeAreaView style = { _styles.backdrop }>
67
-                        <MessageContainer messages = { this.props._messages } />
68
-                        <MessageRecipient />
69
-                        <ChatInputBar onSend = { this.props._onSendMessage } />
70
-                    </SafeAreaView>
41
+                    <MessageContainer messages = { this.props._messages } />
42
+                    <MessageRecipient />
43
+                    <ChatInputBar onSend = { this.props._onSendMessage } />
71 44
                 </KeyboardAvoidingView>
72
-            </SlidingView>
45
+            </JitsiModal>
73 46
         );
74 47
     }
75
-
76
-    _onClose: () => boolean
77
-
78
-    /**
79
-     * Closes the chat window.
80
-     *
81
-     * @returns {boolean}
82
-     */
83
-    _onClose() {
84
-        if (this.props._isOpen) {
85
-            this.props._onToggleChat();
86
-
87
-            return true;
88
-        }
89
-
90
-        return false;
91
-    }
92
-}
93
-
94
-/**
95
- * Maps part of the redux state to the props of this component.
96
- *
97
- * @param {Object} state - The Redux state.
98
- * @returns {Props}
99
- */
100
-function _mapStateToProps(state) {
101
-    return {
102
-        ..._abstractMapStateToProps(state),
103
-        _styles: ColorSchemeRegistry.get(state, 'Chat')
104
-    };
105 48
 }
106 49
 
107 50
 export default translate(connect(_mapStateToProps, _mapDispatchToProps)(Chat));

+ 3
- 2
react/features/chat/components/native/ChatButton.js 查看文件

@@ -1,6 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import { IconChat, IconChatUnread } from '../../../base/icons';
4
+import { setActiveModalId } from '../../../base/modal';
4 5
 import { getLocalParticipant } from '../../../base/participants';
5 6
 import { connect } from '../../../base/redux';
6 7
 import {
@@ -9,7 +10,7 @@ import {
9 10
 } from '../../../base/toolbox';
10 11
 import { openDisplayNamePrompt } from '../../../display-name';
11 12
 
12
-import { toggleChat } from '../../actions';
13
+import { CHAT_VIEW_MODAL_ID } from '../../constants';
13 14
 import { getUnreadCount } from '../../functions';
14 15
 
15 16
 type Props = AbstractButtonProps & {
@@ -93,7 +94,7 @@ function _mapDispatchToProps(dispatch: Function) {
93 94
          * @returns {void}
94 95
          */
95 96
         _displayChat() {
96
-            dispatch(toggleChat());
97
+            dispatch(setActiveModalId(CHAT_VIEW_MODAL_ID));
97 98
         },
98 99
 
99 100
         /**

+ 1
- 2
react/features/chat/components/native/ChatInputBar.js 查看文件

@@ -5,7 +5,6 @@ import { TextInput, TouchableOpacity, View } from 'react-native';
5 5
 
6 6
 import { translate } from '../../../base/i18n';
7 7
 import { Icon, IconChatSend } from '../../../base/icons';
8
-import { Platform } from '../../../base/react';
9 8
 
10 9
 import styles from './styles';
11 10
 
@@ -136,7 +135,7 @@ class ChatInputBar extends Component<Props, State> {
136 135
      */
137 136
     _onFocused(focused) {
138 137
         return () => {
139
-            Platform.OS === 'android' && this.setState({
138
+            this.setState({
140 139
                 addPadding: focused
141 140
             });
142 141
         };

+ 2
- 0
react/features/chat/constants.js 查看文件

@@ -1,5 +1,7 @@
1 1
 // @flow
2 2
 
3
+export const CHAT_VIEW_MODAL_ID = 'chatView';
4
+
3 5
 /**
4 6
  * The audio ID of the audio element for which the {@link playAudio} action is
5 7
  * triggered when new chat message is received.

+ 25
- 7
react/features/chat/reducer.js 查看文件

@@ -1,5 +1,6 @@
1 1
 // @flow
2 2
 
3
+import { SET_ACTIVE_MODAL_ID } from '../base/modal';
3 4
 import { ReducerRegistry } from '../base/redux';
4 5
 
5 6
 import {
@@ -8,6 +9,7 @@ import {
8 9
     SET_PRIVATE_MESSAGE_RECIPIENT,
9 10
     TOGGLE_CHAT
10 11
 } from './actionTypes';
12
+import { CHAT_VIEW_MODAL_ID } from './constants';
11 13
 
12 14
 const DEFAULT_STATE = {
13 15
     isOpen: false,
@@ -56,6 +58,12 @@ ReducerRegistry.register('features/chat', (state = DEFAULT_STATE, action) => {
56 58
             messages: []
57 59
         };
58 60
 
61
+    case SET_ACTIVE_MODAL_ID:
62
+        if (action.activeModalId === CHAT_VIEW_MODAL_ID) {
63
+            return updateChatState(state);
64
+        }
65
+
66
+        break;
59 67
     case SET_PRIVATE_MESSAGE_RECIPIENT:
60 68
         return {
61 69
             ...state,
@@ -64,14 +72,24 @@ ReducerRegistry.register('features/chat', (state = DEFAULT_STATE, action) => {
64 72
         };
65 73
 
66 74
     case TOGGLE_CHAT:
67
-        return {
68
-            ...state,
69
-            isOpen: !state.isOpen,
70
-            lastReadMessage: state.messages[
71
-                navigator.product === 'ReactNative' ? 0 : state.messages.length - 1],
72
-            privateMessageRecipient: state.isOpen ? undefined : state.privateMessageRecipient
73
-        };
75
+        return updateChatState(state);
74 76
     }
75 77
 
76 78
     return state;
77 79
 });
80
+
81
+/**
82
+ * Updates the chat status on opening the chat view.
83
+ *
84
+ * @param {Object} state - The Redux state of the feature.
85
+ * @returns {Object}
86
+ */
87
+function updateChatState(state) {
88
+    return {
89
+        ...state,
90
+        isOpen: !state.isOpen,
91
+        lastReadMessage: state.messages[
92
+            navigator.product === 'ReactNative' ? 0 : state.messages.length - 1],
93
+        privateMessageRecipient: state.isOpen ? undefined : state.privateMessageRecipient
94
+    };
95
+}

Loading…
取消
儲存