@smart-link/rn-im 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,14 +15,20 @@ import { ConversationActions } from '@smart-link/im-base';
15
15
  import { Checkbox, ListRow, NavigationPage, SearchInput } from '@smart-link/rn-ui';
16
16
  import React, { useEffect, useMemo, useState } from 'react';
17
17
  import { View, StyleSheet, FlatList, Text, TouchableOpacity } from 'react-native';
18
+ import { Event, EventName } from "../../../utils/event";
18
19
  const GroupTransfer = ({ navigation }) => {
19
20
  const { t } = useTranslation();
20
21
  const { allMembers } = useConversation();
21
22
  const [checkedMember, setCheckedMember] = useState(null);
22
23
  const [keyword, setKeyword] = useState('');
23
24
  const list = useMemo(() => {
24
- return allMembers === null || allMembers === void 0 ? void 0 : allMembers.filter(item => item.memberLevel !== 'owner');
25
- }, [allMembers]);
25
+ return allMembers === null || allMembers === void 0 ? void 0 : allMembers.filter(item => {
26
+ if (keyword) {
27
+ return item.memberName.indexOf(keyword) > -1 && item.memberLevel !== 'owner';
28
+ }
29
+ return item.memberLevel !== 'owner';
30
+ });
31
+ }, [allMembers, keyword]);
26
32
  useEffect(() => {
27
33
  navigation.setOptions({
28
34
  title: t('chooseNewOwner'),
@@ -32,6 +38,7 @@ const GroupTransfer = ({ navigation }) => {
32
38
  const imManager = getImManager();
33
39
  yield imManager.store.dispatch(ConversationActions.groupTransfer(imManager, checkedMember));
34
40
  navigation.goBack();
41
+ Event.emit(EventName.ON_GROUP_TRANSFER_DONE);
35
42
  }
36
43
  })} style={{ marginRight: 10 }}>
37
44
  <Text style={{ color: tintColor }}>{t('confirm')}</Text>
@@ -11,6 +11,7 @@ import OptionGroup from '../../../pages/conversation/setting/OptionGroup';
11
11
  import OptionCancelGroup from '../../../pages/conversation/setting/OptionCancelGroup';
12
12
  import { startAddMember, startCreateGroup } from '../../../slice/contact/contact.slice';
13
13
  import { StackActions } from '@react-navigation/native';
14
+ import { Event, EventName } from "../../../utils/event";
14
15
  const { MEMBER, MGR, OWNER } = MemberLevel;
15
16
  const { LIAISON } = GroupType;
16
17
  // 最大显示人数
@@ -60,11 +61,22 @@ const ConversationSetting = ({ navigation }) => {
60
61
  ConfirmActionSheets({
61
62
  title: t('leaveGroup'),
62
63
  confirm: () => {
63
- imManager.store.dispatch(ConversationActions.doLeaveGroup(imManager, { chatGroupId: id }, () => {
64
- navigation.dispatch(StackActions.popToTop());
65
- }, () => {
66
- Toast.error(t('leaveGroupFail'));
67
- }));
64
+ const doLeave = () => {
65
+ imManager.store.dispatch(ConversationActions.doLeaveGroup(imManager, { chatGroupId: id }, () => {
66
+ navigation.dispatch(StackActions.popToTop());
67
+ }, () => {
68
+ Toast.error(t('leaveGroupFail'));
69
+ }));
70
+ };
71
+ if (memberLevel === OWNER) {
72
+ // 群主离开群,需要先转让群
73
+ Event.on(EventName.ON_GROUP_TRANSFER_DONE, () => {
74
+ doLeave();
75
+ });
76
+ navigation.navigate("GroupTransfer");
77
+ return;
78
+ }
79
+ doLeave();
68
80
  },
69
81
  t,
70
82
  });
@@ -40,7 +40,7 @@ const ChooseMember = ({ navigation, route: { params } }) => {
40
40
  headerTitle: params.atOther ? t('selectRemainder') : t('selectContacts'),
41
41
  headerRight: ({ tintColor }) => {
42
42
  return (<TouchableOpacity activeOpacity={0.5} style={{ padding: dp(10) }} disabled={!checked.length} onPress={confirm}>
43
- <Text style={{ color: tintColor }}>{t('confirm')}</Text>
43
+ <Text style={{ color: tintColor }}>{checked.length ? `${t('confirm')}(${checked.length})` : t('confirm')}</Text>
44
44
  </TouchableOpacity>);
45
45
  },
46
46
  });
@@ -50,9 +50,11 @@ const ChooseMember = ({ navigation, route: { params } }) => {
50
50
  const members = list.filter(item => checked.includes(item.userId));
51
51
  if (params.atOther) {
52
52
  if ((_a = imManager.inputRef) === null || _a === void 0 ? void 0 : _a.current) {
53
- (_c = (_b = imManager.inputRef) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.inertText(`${members[0].memberName} `);
53
+ const text = members.map(item => `@${item.memberName}`)
54
+ .join(' ').slice(1) + ' ';
55
+ (_c = (_b = imManager.inputRef) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.inertText(text);
54
56
  }
55
- imManager.store.dispatch(MessageActions.addAtUser(members[0]));
57
+ imManager.store.dispatch(MessageActions.addAtUsers(members));
56
58
  }
57
59
  if (params.removeMember) {
58
60
  imManager.store.dispatch(ConversationActions.removeGroupMembers({
@@ -64,16 +66,11 @@ const ChooseMember = ({ navigation, route: { params } }) => {
64
66
  const renderItem = ({ item }) => {
65
67
  const enableTopStyles = item.enableTop === 'on' ? styles.enableTop : null;
66
68
  return (<TouchableOpacity activeOpacity={0.5} style={[styles.row, enableTopStyles]} onPress={() => {
67
- if (params.atOther) {
68
- setChecked([item.userId]);
69
+ if (checked.includes(item.userId)) {
70
+ setChecked(checked.filter(id => id !== item.userId));
69
71
  }
70
72
  else {
71
- if (checked.includes(item.userId)) {
72
- setChecked(checked.filter(id => id !== item.userId));
73
- }
74
- else {
75
- setChecked([...checked, item.userId]);
76
- }
73
+ setChecked([...checked, item.userId]);
77
74
  }
78
75
  }}>
79
76
  <View style={{ marginRight: dp(10) }}>
@@ -74,7 +74,7 @@ const MessageList = ({ navigation }) => {
74
74
  InteractionManager.runAfterInteractions(() => {
75
75
  imManager.store.dispatch(MessagePanelActions.saveDraftText(imManager));
76
76
  imManager.leaveConversation();
77
- imManager.store.dispatch(MessageActions.resetState({}));
77
+ imManager.store.dispatch(MessageActions.resetState());
78
78
  });
79
79
  }
80
80
  });
@@ -39,7 +39,10 @@ const UpdateManager = ({ payload }) => {
39
39
  const { t } = useTranslation();
40
40
  console.log('UpdateManager: ', payload);
41
41
  const { targetUserName, memberLevel, opUserName } = payload !== null && payload !== void 0 ? payload : {};
42
- const content = memberLevel === MemberLevel.MGR ? t('setToMgr', { userName: targetUserName }) : t('cancelMgr', { userName: targetUserName });
42
+ let content = memberLevel === MemberLevel.MGR ? t('setToMgr', { userName: targetUserName }) : t('cancelMgr', { userName: targetUserName });
43
+ if (memberLevel === MemberLevel.OWNER) {
44
+ content = t('setToOwner', { userName: targetUserName });
45
+ }
43
46
  return <Text style={styles.text}>{opUserName} {content}</Text>;
44
47
  };
45
48
  const PayloadNotify = ({ payload, payloadType }) => {
@@ -4,8 +4,8 @@ type EmojiPanelProps = {
4
4
  onBackspace: () => void;
5
5
  };
6
6
  export type EmojiPanelMethods = {
7
- show: (height: number) => void;
8
- hide: () => void;
7
+ show: (height: number, animated?: boolean) => void;
8
+ hide: (animated?: boolean) => void;
9
9
  };
10
10
  declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<EmojiPanelProps & React.RefAttributes<EmojiPanelMethods>>>;
11
11
  export default _default;
@@ -22,16 +22,33 @@ const EmojiPanel = forwardRef(({ onCheck, onBackspace }, ref) => {
22
22
  <Text style={{ fontSize: 22, color: '#333' }}>{item}</Text>
23
23
  </TouchableOpacity>);
24
24
  useImperativeHandle(ref, () => ({
25
- show: (height) => {
25
+ show: (height, animated) => {
26
26
  setVisible(true);
27
- heightAnim.setValue(height);
27
+ if (animated) {
28
+ Animated.timing(heightAnim, {
29
+ toValue: height,
30
+ duration: 300,
31
+ useNativeDriver: false,
32
+ }).start();
33
+ }
34
+ else {
35
+ heightAnim.setValue(height);
36
+ }
28
37
  },
29
- hide: () => {
38
+ hide: (animated) => {
30
39
  setVisible(false);
31
- heightAnim.setValue(0);
40
+ if (animated) {
41
+ Animated.timing(heightAnim, {
42
+ toValue: 0,
43
+ duration: 300,
44
+ useNativeDriver: false,
45
+ }).start();
46
+ }
47
+ else {
48
+ heightAnim.setValue(0);
49
+ }
32
50
  },
33
51
  }), []);
34
- console.log('EmojiPanel: ', heightAnim);
35
52
  return (<Animated.View style={{
36
53
  height: heightAnim,
37
54
  position: 'relative',
@@ -33,15 +33,14 @@ const MessageBar = forwardRef(({ onKeyboardAt }, ref) => {
33
33
  const lazy = useRef(false);
34
34
  const tempText = useRef('');
35
35
  const { currentConversation } = useConversation();
36
- const { quote, messageText } = useMessage();
36
+ const { quote } = useMessage();
37
37
  const [showSend, setShowSend] = useState(false);
38
- const keyboardDuration = useRef(100);
38
+ const keyboardDuration = useRef(150);
39
39
  const modeRef = useRef('text');
40
40
  const [inputMode, setInputMode] = useState('text');
41
41
  const keyboardHeight = useRef(240);
42
42
  const handleChange = useCallback((text) => {
43
43
  tempText.current = text;
44
- // const trimTxt = text.trim();
45
44
  if (text.length && !lazy.current) {
46
45
  setShowSend(true);
47
46
  lazy.current = true;
@@ -89,31 +88,41 @@ const MessageBar = forwardRef(({ onKeyboardAt }, ref) => {
89
88
  }, timeout);
90
89
  }, []);
91
90
  const switchEmojiInputMode = useCallback(() => {
92
- var _a, _b, _c;
91
+ const animated = modeRef.current !== 'option';
93
92
  modeRef.current = 'emoji';
94
93
  setInputMode('emoji');
95
94
  Keyboard.dismiss();
96
- (_a = optionPanelRef.current) === null || _a === void 0 ? void 0 : _a.hide();
97
- (_b = emojiPanelRef.current) === null || _b === void 0 ? void 0 : _b.show(keyboardHeight.current);
98
- (_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.focusNoSoftKeyboard();
95
+ setTimeout(() => {
96
+ var _a, _b, _c;
97
+ (_a = optionPanelRef.current) === null || _a === void 0 ? void 0 : _a.hide();
98
+ (_b = emojiPanelRef.current) === null || _b === void 0 ? void 0 : _b.show(keyboardHeight.current, animated);
99
+ (_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.focusNoSoftKeyboard();
100
+ }, keyboardDuration.current);
99
101
  }, []);
100
102
  const switchOptionPanelMode = useMemoizedFn(() => {
101
- var _a;
102
- if ((_a = optionPanelRef.current) === null || _a === void 0 ? void 0 : _a.getVisible()) {
103
+ if (modeRef.current === 'option') {
103
104
  switchKeyboardInputMode();
104
105
  return;
105
106
  }
107
+ const animated = modeRef.current !== 'emoji';
106
108
  setInputMode('option');
107
109
  modeRef.current = 'option';
108
110
  Keyboard.dismiss();
109
111
  setTimeout(() => {
110
112
  var _a, _b;
111
113
  (_a = emojiPanelRef.current) === null || _a === void 0 ? void 0 : _a.hide();
112
- (_b = optionPanelRef.current) === null || _b === void 0 ? void 0 : _b.show(keyboardHeight.current);
114
+ (_b = optionPanelRef.current) === null || _b === void 0 ? void 0 : _b.show(keyboardHeight.current, animated);
113
115
  }, keyboardDuration.current);
114
116
  });
117
+ const onFocus = useCallback(() => {
118
+ var _a, _b;
119
+ if (modeRef.current === 'text') {
120
+ (_a = emojiPanelRef.current) === null || _a === void 0 ? void 0 : _a.hide();
121
+ (_b = optionPanelRef.current) === null || _b === void 0 ? void 0 : _b.hide();
122
+ }
123
+ }, []);
115
124
  const onKeyPress = useCallback((e) => {
116
- if (['@', '@'].includes(e.nativeEvent.key)) {
125
+ if (['@'].includes(e.nativeEvent.key)) {
117
126
  if (!debounceAt.current) {
118
127
  debounceAt.current = debounce(() => {
119
128
  onKeyboardAt && onKeyboardAt();
@@ -155,14 +164,16 @@ const MessageBar = forwardRef(({ onKeyboardAt }, ref) => {
155
164
  reset: () => {
156
165
  var _a, _b, _c;
157
166
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
158
- (_b = emojiPanelRef.current) === null || _b === void 0 ? void 0 : _b.hide();
159
- (_c = optionPanelRef.current) === null || _c === void 0 ? void 0 : _c.hide();
167
+ (_b = emojiPanelRef.current) === null || _b === void 0 ? void 0 : _b.hide(true);
168
+ (_c = optionPanelRef.current) === null || _c === void 0 ? void 0 : _c.hide(true);
169
+ setInputMode('text');
170
+ modeRef.current = 'text';
160
171
  },
161
172
  focusTextInput: () => {
162
173
  var _a, _b, _c;
163
174
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
164
- (_b = emojiPanelRef.current) === null || _b === void 0 ? void 0 : _b.hide();
165
- (_c = optionPanelRef.current) === null || _c === void 0 ? void 0 : _c.hide();
175
+ (_b = emojiPanelRef.current) === null || _b === void 0 ? void 0 : _b.hide(true);
176
+ (_c = optionPanelRef.current) === null || _c === void 0 ? void 0 : _c.hide(true);
166
177
  },
167
178
  inertText: (text) => {
168
179
  var _a, _b, _c;
@@ -200,14 +211,15 @@ const MessageBar = forwardRef(({ onKeyboardAt }, ref) => {
200
211
  }
201
212
  const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', event => {
202
213
  var _a, _b;
203
- console.log(event.endCoordinates.height);
204
- keyboardHeight.current = Math.max(event.endCoordinates.height, 240);
205
- keyboardDuration.current = event.duration;
206
214
  (_a = emojiPanelRef.current) === null || _a === void 0 ? void 0 : _a.hide();
207
215
  (_b = optionPanelRef.current) === null || _b === void 0 ? void 0 : _b.hide();
208
216
  });
217
+ const keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', (event) => {
218
+ keyboardDuration.current = event.duration;
219
+ });
209
220
  return () => {
210
221
  keyboardDidShowListener.remove();
222
+ keyboardDidHideListener.remove();
211
223
  };
212
224
  }, []);
213
225
  return (<>
@@ -221,7 +233,7 @@ const MessageBar = forwardRef(({ onKeyboardAt }, ref) => {
221
233
  <VoiceSvg />
222
234
  </TouchableOpacity>)}
223
235
  </View>
224
- {inputMode === 'voice' ? <VoiceBar /> : <MessageInput ref={inputRef} onChangeText={handleChange} onKeyPress={onKeyPress}/>}
236
+ {inputMode === 'voice' ? <VoiceBar /> : <MessageInput ref={inputRef} onChangeText={handleChange} onFocus={onFocus} onKeyPress={onKeyPress}/>}
225
237
 
226
238
  <View style={[styles.switchInput, { paddingRight: 0 }]}>
227
239
  {inputMode === 'emoji' ? (<TouchableOpacity onPress={switchKeyboardInputMode}>
@@ -1,11 +1,6 @@
1
1
  import React from 'react';
2
- import { StyleProp, ViewStyle, NativeSyntheticEvent, TextInputKeyPressEventData } from 'react-native';
2
+ import { StyleProp, ViewStyle, TextInputProps } from 'react-native';
3
3
  export type InputMode = 'text' | 'emoji' | 'voice' | 'option';
4
- type MessageInputProps = {
5
- style?: StyleProp<ViewStyle>;
6
- onChangeText?: (text: string) => void;
7
- onKeyPress?: (e: NativeSyntheticEvent<TextInputKeyPressEventData>) => void;
8
- };
9
4
  export type MessageInputMethods = {
10
5
  isFocused: () => boolean;
11
6
  focus: () => void;
@@ -18,5 +13,8 @@ export type MessageInputMethods = {
18
13
  insertText: (text: string) => void;
19
14
  backspace: () => void;
20
15
  };
21
- declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<MessageInputProps & React.RefAttributes<MessageInputMethods>>>;
16
+ declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<{
17
+ style?: StyleProp<ViewStyle>;
18
+ onChangeText?: ((text: string) => void) | undefined;
19
+ } & Pick<TextInputProps, "onFocus" | "onKeyPress"> & React.RefAttributes<MessageInputMethods>>>;
22
20
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import { dp } from '@smart-link/rn-ui';
2
2
  import React, { forwardRef, memo, useImperativeHandle, useRef, useState, } from 'react';
3
3
  import { TextInput, View, StyleSheet, Platform } from 'react-native';
4
- const MessageInput = forwardRef(({ onChangeText, onKeyPress, style }, ref) => {
4
+ const MessageInput = forwardRef(({ onChangeText, onKeyPress, onFocus, style }, ref) => {
5
5
  const inputRef = useRef(null);
6
6
  const [text, setText] = useState('');
7
7
  const [showSoftInputOnFocus, setShowSoftInputOnFocus] = useState(true);
@@ -162,7 +162,7 @@ const MessageInput = forwardRef(({ onChangeText, onKeyPress, style }, ref) => {
162
162
  innerText.current = n;
163
163
  setText(n);
164
164
  onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(n);
165
- }} onSelectionChange={({ nativeEvent }) => {
165
+ }} onFocus={onFocus} onSelectionChange={({ nativeEvent }) => {
166
166
  setSelection(nativeEvent.selection);
167
167
  selectionIos.current = nativeEvent.selection;
168
168
  }}/>
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
2
  export type OptionPanelMethods = {
3
- getVisible: () => boolean;
4
- show: (height: number) => void;
5
- hide: () => void;
3
+ show: (height: number, animated?: boolean) => void;
4
+ hide: (animated?: boolean) => void;
6
5
  };
7
6
  declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<React.RefAttributes<OptionPanelMethods>>>;
8
7
  export default _default;
@@ -31,13 +31,30 @@ const OptionPanel = forwardRef((props, ref) => {
31
31
  const { t } = useTranslation();
32
32
  const imManager = getImManager();
33
33
  useImperativeHandle(ref, () => ({
34
- getVisible: () => visible,
35
- show: height => {
36
- heightAnim.setValue(height);
34
+ show: (height, animated) => {
35
+ if (animated) {
36
+ Animated.timing(heightAnim, {
37
+ toValue: height,
38
+ duration: 300,
39
+ useNativeDriver: false,
40
+ }).start();
41
+ }
42
+ else {
43
+ heightAnim.setValue(height);
44
+ }
37
45
  setVisible(true);
38
46
  },
39
- hide: () => {
40
- heightAnim.setValue(0);
47
+ hide: (animated) => {
48
+ if (animated) {
49
+ Animated.timing(heightAnim, {
50
+ toValue: 0,
51
+ duration: 300,
52
+ useNativeDriver: false,
53
+ }).start();
54
+ }
55
+ else {
56
+ heightAnim.setValue(0);
57
+ }
41
58
  setVisible(false);
42
59
  },
43
60
  }), [visible]);
@@ -0,0 +1,13 @@
1
+ export declare enum EventName {
2
+ ON_GROUP_TRANSFER_DONE = "ON_GROUP_TRANSFER_DONE"
3
+ }
4
+ declare class EventEmitter {
5
+ events: Map<string, Function[]>;
6
+ constructor();
7
+ on(eventName: EventName, callback: Function): () => void;
8
+ off(eventName: EventName, callback: Function): void;
9
+ removeAll(eventName: EventName): void;
10
+ emit(eventName: EventName, ...args: any[]): void;
11
+ }
12
+ export declare const Event: EventEmitter;
13
+ export {};
@@ -0,0 +1,32 @@
1
+ export var EventName;
2
+ (function (EventName) {
3
+ EventName["ON_GROUP_TRANSFER_DONE"] = "ON_GROUP_TRANSFER_DONE";
4
+ })(EventName || (EventName = {}));
5
+ class EventEmitter {
6
+ constructor() {
7
+ this.events = new Map();
8
+ }
9
+ on(eventName, callback) {
10
+ if (this.events.has(eventName)) {
11
+ this.events.get(eventName).push(callback);
12
+ }
13
+ else {
14
+ this.events.set(eventName, [callback]);
15
+ }
16
+ return () => {
17
+ this.off(eventName, callback);
18
+ };
19
+ }
20
+ off(eventName, callback) {
21
+ const index = this.events.get(eventName).indexOf(callback);
22
+ this.events.get(eventName).splice(index, 1);
23
+ }
24
+ removeAll(eventName) {
25
+ this.events.set(eventName, []);
26
+ }
27
+ emit(eventName, ...args) {
28
+ const tasks = this.events.get(eventName) || [];
29
+ tasks.forEach(fn => fn.call(null, ...args));
30
+ }
31
+ }
32
+ export const Event = new EventEmitter();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-link/rn-im",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "dependencies": {
@@ -62,8 +62,8 @@
62
62
  "react-redux": "^8.1.3",
63
63
  "redux": "^4.2.1",
64
64
  "redux-thunk": "^2.4.2",
65
- "@smart-link/rn-ui": "^1.1.0",
66
- "@smart-link/im-base": "^1.1.1"
65
+ "@smart-link/rn-ui": "^1.1.1",
66
+ "@smart-link/im-base": "^1.1.2"
67
67
  },
68
68
  "files": [
69
69
  "dist/**",