Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 4925d34

Browse files
authored
Merge pull request #124 from pubnub/fix-emoji-focus
fix: focusing on MessageInput after selecting emoji
2 parents 36fe5c5 + 09e9d3c commit 4925d34

File tree

7 files changed

+86
-51
lines changed

7 files changed

+86
-51
lines changed

.pubnub.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
---
22
name: pubnub-react-chat-components
3-
version: v0.29.0
3+
version: v0.30.0
44
scm: github.com/pubnub/react-chat-components
55
schema: 1
66
files:
77
- lib/dist/index.js
88
- lib/dist/index.es.js
99
changelog:
10+
- date: 2023-07-20
11+
version: v0.30.0
12+
changes:
13+
- type: bug
14+
text: "Focusing on EmojiInput after selecting emoji only worked in certain cases."
15+
- type: bug
16+
text: "Console warnings about unknown attributes in MessageInput."
1017
- date: 2023-07-17
1118
version: v0.29.0
1219
changes:

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/common-chat-components",
3-
"version": "0.29.0",
3+
"version": "0.30.0",
44
"main": "src/index.ts",
55
"license": "MIT",
66
"scripts": {

packages/common/src/message-input/message-input.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ export interface CommonMessageInputProps {
4242
* Allows users to compose messages using text and emojis
4343
* and automatically publish them on PubNub channels upon sending.
4444
*/
45-
export const useMessageInputCore = <T extends CommonMessageInputProps>(props: T) => {
45+
export const useMessageInputCore = (props: CommonMessageInputProps) => {
4646
const pubnub = usePubNub();
47-
48-
const { draftMessage, senderInfo, onSend, onBeforeSend, typingIndicator, ...inputProps } = props;
47+
const { draftMessage, senderInfo, onSend, onBeforeSend, typingIndicator } = props;
4948

5049
const [text, setText] = useState(draftMessage || "");
5150
const [file, setFile] = useState<File | UriFileInput>(null);
@@ -155,6 +154,5 @@ export const useMessageInputCore = <T extends CommonMessageInputProps>(props: T)
155154
theme,
156155
startTypingIndicator,
157156
stopTypingIndicator,
158-
...inputProps,
159157
};
160158
};

packages/react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/react-native-chat-components",
3-
"version": "0.29.0",
3+
"version": "0.30.0",
44
"description": "PubNub Chat Components is a development kit of React Native components that aims to help you to easily build Chat applications using PubNub infrastructure. It removes the complexicity of picking an adequate Chat engine, learning its APIs and dealing with its low-level internals. As the same time it allows you to create apps of various use cases, with different functionalities and customizable looks.",
55
"author": "PubNub <[email protected]>",
66
"main": "dist/commonjs/index",

packages/react-native/src/message-input/message-input.tsx

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ export type MessageInputProps = CommonMessageInputProps & {
4444
* and automatically publish them on PubNub channels upon sending.
4545
*/
4646
export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) => {
47+
const {
48+
actionsAfterInput,
49+
disabled,
50+
draftMessage,
51+
extraActionsRenderer,
52+
fileModalRenderer,
53+
fileUpload,
54+
onBeforeSend,
55+
onChange,
56+
onKeyPress,
57+
onSend,
58+
placeholder,
59+
sendButton,
60+
sendMessageOnSubmitEditing,
61+
senderInfo,
62+
typingIndicator,
63+
...otherTextInputProps
64+
} = props;
65+
4766
const {
4867
startTypingIndicator,
4968
stopTypingIndicator,
@@ -56,8 +75,8 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
5675
file,
5776
setText,
5877
onError,
59-
...otherTextInputProps
60-
} = useMessageInputCore(props);
78+
} = useMessageInputCore({ draftMessage, senderInfo, onSend, onBeforeSend, typingIndicator });
79+
6180
const style = useStyle<MessageInputStyle>({
6281
theme,
6382
createDefaultStyle,
@@ -125,20 +144,20 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
125144

126145
const handleInputChange = (newText: string) => {
127146
try {
128-
if (props.typingIndicator) {
147+
if (typingIndicator) {
129148
newText.length ? startTypingIndicator() : stopTypingIndicator();
130149
}
131-
props.onChange && props.onChange(newText);
150+
onChange && onChange(newText);
132151
setText(newText);
133152
} catch (e) {
134153
onError(e);
135154
}
136155
};
137156

138157
const handleKeyPress = (e: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
139-
props.onKeyPress && props.onKeyPress(e);
158+
onKeyPress && onKeyPress(e);
140159

141-
if (e.nativeEvent.key == "Enter" && props.sendMessageOnSubmitEditing) {
160+
if (e.nativeEvent.key == "Enter" && sendMessageOnSubmitEditing) {
142161
sendMessage();
143162
}
144163
};
@@ -150,8 +169,8 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
150169
const renderSendButton = () => {
151170
return (
152171
<TouchableOpacity onPress={sendMessage} testID="message-input-send">
153-
{props.sendButton ? (
154-
props.sendButton
172+
{sendButton ? (
173+
sendButton
155174
) : isValidInputText() ? (
156175
<Image style={style.icon} source={{ uri: AirplaneActiveIcon }} />
157176
) : (
@@ -171,7 +190,7 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
171190
) : (
172191
<View>
173192
<>
174-
{props.fileUpload === "image" ? (
193+
{fileUpload === "image" ? (
175194
<TouchableOpacity
176195
style={style.messageInputFileLabel}
177196
onPress={pickPhoto}
@@ -196,8 +215,8 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
196215
};
197216

198217
const renderFileModal = () => {
199-
if (props.fileModalRenderer) {
200-
return props.fileModalRenderer({ pickDocument, pickPhoto, modalVisible, setModalVisible });
218+
if (fileModalRenderer) {
219+
return fileModalRenderer({ pickDocument, pickPhoto, modalVisible, setModalVisible });
201220
}
202221

203222
return (
@@ -213,32 +232,30 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
213232

214233
const renderActions = () => (
215234
<>
216-
{!props.disabled && props.fileUpload && renderFileUpload()}
217-
{props.extraActionsRenderer && (
218-
<View style={style.extraActions}>{props.extraActionsRenderer()}</View>
219-
)}
235+
{!disabled && fileUpload && renderFileUpload()}
236+
{extraActionsRenderer && <View style={style.extraActions}>{extraActionsRenderer()}</View>}
220237
</>
221238
);
222239

223240
return (
224241
<View style={style.messageInputWrapper}>
225242
{renderFileModal()}
226-
{!props.actionsAfterInput && renderActions()}
243+
{!actionsAfterInput && renderActions()}
227244
<TextInput
228245
{...otherTextInputProps}
229246
testID="message-input"
230247
autoComplete="off"
231248
multiline={true}
232249
onChangeText={handleInputChange}
233-
placeholder={props.placeholder}
250+
placeholder={placeholder}
234251
style={style.messageInput}
235252
placeholderTextColor={style.messageInputPlaceholder.color}
236-
editable={!props.disabled && file == null}
253+
editable={!disabled && file == null}
237254
value={text}
238255
onKeyPress={handleKeyPress}
239256
/>
240-
{props.actionsAfterInput && renderActions()}
241-
{!props.disabled && (
257+
{actionsAfterInput && renderActions()}
258+
{!disabled && (
242259
<View style={style.sendButton}>
243260
{loader ? (
244261
<Animated.Image

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pubnub/react-chat-components",
3-
"version": "0.29.0",
3+
"version": "0.30.0",
44
"description": "PubNub Chat Components is a development kit of React components that aims to help you to easily build Chat applications using PubNub infrastructure. It removes the complexicity of picking an adequate Chat engine, learning its APIs and dealing with its low-level internals. As the same time it allows you to create apps of various use cases, with different functionalities and customizable looks.",
55
"author": "PubNub <[email protected]>",
66
"main": "dist/index.js",

packages/react/src/message-input/message-input.tsx

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ export type MessageInputProps = CommonMessageInputProps & {
4848
* and automatically publish them on PubNub channels upon sending.
4949
*/
5050
export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) => {
51+
const {
52+
actionsAfterInput,
53+
disabled,
54+
draftMessage,
55+
emojiPicker,
56+
extraActionsRenderer,
57+
fileUpload,
58+
hideSendButton,
59+
onBeforeSend,
60+
onChange,
61+
onKeyPress,
62+
onSend,
63+
placeholder,
64+
sendButton,
65+
senderInfo,
66+
typingIndicator,
67+
...otherTextAreaProps
68+
} = props;
69+
5170
const {
5271
clearInput,
5372
file,
@@ -61,11 +80,7 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
6180
theme,
6281
startTypingIndicator,
6382
stopTypingIndicator,
64-
fileUpload,
65-
sendButton,
66-
hideSendButton,
67-
...otherTextAreaProps
68-
} = useMessageInputCore(props);
83+
} = useMessageInputCore({ draftMessage, senderInfo, onSend, onBeforeSend, typingIndicator });
6984

7085
const [emojiPickerShown, setEmojiPickerShown] = useState(false);
7186
const inputRef = useRef<HTMLTextAreaElement>(null);
@@ -98,10 +113,10 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
98113
const handleInputChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
99114
try {
100115
const { value: newText } = event.target;
101-
if (props.typingIndicator) {
116+
if (typingIndicator) {
102117
newText.length ? startTypingIndicator() : stopTypingIndicator();
103118
}
104-
props.onChange && props.onChange(event);
119+
onChange && onChange(event);
105120
setText(newText);
106121
} catch (e) {
107122
onError(e);
@@ -115,7 +130,7 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
115130
sendMessage();
116131
if (fileRef.current) fileRef.current.value = "";
117132
}
118-
props.onKeyPress && props.onKeyPress(event);
133+
onKeyPress && onKeyPress(event);
119134
} catch (e) {
120135
onError(e);
121136
}
@@ -142,7 +157,7 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
142157
if (!("native" in emoji)) return;
143158
setText((text) => text + emoji.native);
144159
setEmojiPickerShown(false);
145-
if (fileRef.current) inputRef.current.focus();
160+
if (inputRef.current) inputRef.current.focus();
146161
} catch (e) {
147162
onError(e);
148163
}
@@ -205,9 +220,9 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
205220
<div
206221
className="pn-msg-input__emoji-picker"
207222
ref={pickerRef}
208-
style={props.actionsAfterInput ? { left: "unset" } : { right: "unset" }}
223+
style={actionsAfterInput ? { left: "unset" } : { right: "unset" }}
209224
>
210-
{React.cloneElement(props.emojiPicker, { onEmojiSelect: handleEmojiInsertion })}
225+
{React.cloneElement(emojiPicker, { onEmojiSelect: handleEmojiInsertion })}
211226
</div>
212227
)}
213228
</>
@@ -217,39 +232,37 @@ export const MessageInput: FC<MessageInputProps> = (props: MessageInputProps) =>
217232
const renderActions = () => (
218233
<div className="pn-msg-input__icons">
219234
<div className="pn-msg-input__emoji-toggle">
220-
{!props.disabled && props.emojiPicker && renderEmojiPicker()}
235+
{!disabled && emojiPicker && renderEmojiPicker()}
221236
</div>
222-
{!props.disabled && fileUpload && renderFileUpload()}
223-
{props.extraActionsRenderer && props.extraActionsRenderer()}
237+
{!disabled && fileUpload && renderFileUpload()}
238+
{extraActionsRenderer && extraActionsRenderer()}
224239
</div>
225240
);
226241

227242
return (
228243
<div
229-
className={`pn-msg-input pn-msg-input--${theme} ${
230-
props.disabled ? "pn-msg-input--disabled" : ""
231-
}`}
244+
className={`pn-msg-input pn-msg-input--${theme} ${disabled ? "pn-msg-input--disabled" : ""}`}
232245
>
233246
<div className="pn-msg-input__wrapper">
234-
{!props.actionsAfterInput && renderActions()}
247+
{!actionsAfterInput && renderActions()}
235248
<textarea
236249
{...otherTextAreaProps}
237250
className="pn-msg-input__textarea"
238251
data-testid="message-input"
239-
disabled={props.disabled || !!file}
252+
disabled={disabled || !!file}
240253
onChange={handleInputChange}
241254
onKeyPress={handleKeyPress}
242-
placeholder={props.placeholder}
255+
placeholder={placeholder}
243256
ref={inputRef}
244257
rows={1}
245258
value={text}
246259
/>
247-
{props.actionsAfterInput && renderActions()}
248-
{!hideSendButton && !props.disabled && (
260+
{actionsAfterInput && renderActions()}
261+
{!hideSendButton && !disabled && (
249262
<button
250263
aria-label="Send"
251264
className={`pn-msg-input__send ${isValidInputText() && "pn-msg-input__send--active"}`}
252-
disabled={loader || props.disabled}
265+
disabled={loader || disabled}
253266
onClick={handleSendClick}
254267
title="Send"
255268
>

0 commit comments

Comments
 (0)