diff --git a/example/src/App.tsx b/example/src/App.tsx index 326cb7e8..38190927 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -2,6 +2,7 @@ import { useActionSheet } from '@expo/react-native-action-sheet' import { Chat, MessageType } from '@flyerhq/react-native-chat-ui' import { PreviewData } from '@flyerhq/react-native-link-preview' import React, { useState } from 'react' +import {Dimensions, View} from 'react-native' import DocumentPicker from 'react-native-document-picker' import FileViewer from 'react-native-file-viewer' import { launchImageLibrary } from 'react-native-image-picker' @@ -126,6 +127,23 @@ const App = () => { onPreviewDataFetched={handlePreviewDataFetched} onSendPress={handleSendPress} user={user} + + // onAttachmentPress={() => { + // this.setState ({bShowOption : true}) + // }} + + renderOptionPanel={() => { + + // if (!this.state.bShowOption) return ; + + // we can show it now + return ( + + {/* render anything you want */} + + ) + }} + /> ) } diff --git a/src/components/Avatar/Avatar.tsx b/src/components/Avatar/Avatar.tsx index 0128e454..ff241203 100644 --- a/src/components/Avatar/Avatar.tsx +++ b/src/components/Avatar/Avatar.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { Image, StyleSheet, Text, View } from 'react-native' +import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native' import { MessageType, Theme } from '../../types' import { getUserAvatarNameColor, getUserInitials } from '../../utils' @@ -11,12 +11,14 @@ export const Avatar = React.memo( showAvatar, showUserAvatars, theme, + onAvatarPress, }: { author: MessageType.Any['author'] currentUserIsAuthor: boolean showAvatar: boolean showUserAvatars?: boolean - theme: Theme + theme: Theme, + onAvatarPress?: () => void }) => { const renderAvatar = () => { const color = getUserAvatarNameColor( @@ -27,15 +29,17 @@ export const Avatar = React.memo( if (author.imageUrl) { return ( - + + + ) } diff --git a/src/components/Chat/Chat.tsx b/src/components/Chat/Chat.tsx index 4ac5eaf2..3e430ea6 100644 --- a/src/components/Chat/Chat.tsx +++ b/src/components/Chat/Chat.tsx @@ -122,6 +122,14 @@ export const Chat = ({ onPreviewDataFetched, onSendPress, renderBubble, + + renderInputPanel, + renderOptionPanel, + renderLeftPanel, + renderMidPanel, + renderRightPanel, + onAvatarPress, + renderCustomMessage, renderFileMessage, renderImageMessage, @@ -294,6 +302,14 @@ export const Chat = ({ onMessagePress: handleMessagePress, onPreviewDataFetched, renderBubble, + + renderInputPanel, + renderOptionPanel, + renderLeftPanel, + renderMidPanel, + renderRightPanel, + onAvatarPress, + renderCustomMessage, renderFileMessage, renderImageMessage, @@ -314,6 +330,14 @@ export const Chat = ({ onMessageLongPress, onPreviewDataFetched, renderBubble, + + renderInputPanel, + renderOptionPanel, + renderLeftPanel, + renderMidPanel, + renderRightPanel, + onAvatarPress, + renderCustomMessage, renderFileMessage, renderImageMessage, @@ -423,6 +447,11 @@ export const Chat = ({ isAttachmentUploading, onAttachmentPress, onSendPress, + renderInputPanel, + renderOptionPanel, + renderLeftPanel, + renderMidPanel, + renderRightPanel, renderScrollable, sendButtonVisibilityMode, textInputProps, diff --git a/src/components/Input/Input.tsx b/src/components/Input/Input.tsx index c23da2ea..aaf9eccb 100644 --- a/src/components/Input/Input.tsx +++ b/src/components/Input/Input.tsx @@ -29,6 +29,20 @@ export interface InputTopLevelProps { * `TextInput` state. Defaults to `editing`. */ sendButtonVisibilityMode?: 'always' | 'editing' textInputProps?: TextInputProps + + renderInputPanel?: () => React.ReactNode + + /** Render a optional panel */ + renderOptionPanel?: () => React.ReactNode + + /** Render left panel */ + renderLeftPanel?: () => React.ReactNode + + /** Render middle panel */ + renderMidPanel?: () => React.ReactNode + + /** Render right panel */ + renderRightPanel?: () => React.ReactNode } export interface InputAdditionalProps { @@ -46,6 +60,13 @@ export const Input = ({ isAttachmentUploading, onAttachmentPress, onSendPress, + + renderInputPanel, + renderOptionPanel, + renderLeftPanel, + renderMidPanel, + renderRightPanel, + sendButtonVisibilityMode, textInputProps, }: InputProps) => { @@ -77,40 +98,58 @@ export const Input = ({ } } + if (renderInputPanel) { + return ( + + {renderInputPanel ()} + + ); + } + return ( - - {user && - (isAttachmentUploading ? ( - - ) : ( - !!onAttachmentPress && ( - + + {user && + (isAttachmentUploading ? ( + - ) - ))} - - {sendButtonVisibilityMode === 'always' || - (sendButtonVisibilityMode === 'editing' && user && value.trim()) ? ( - - ) : null} + ) : ( + renderLeftPanel ? renderLeftPanel () : + !!onAttachmentPress && ( + + ) + )) + } + { + renderMidPanel ? renderMidPanel () : + () + } + {sendButtonVisibilityMode === 'always' || + (sendButtonVisibilityMode === 'editing' && user && value.trim()) ? ( + renderRightPanel ? renderRightPanel () : + ) : null} + + + {(() => {return renderOptionPanel && renderOptionPanel ()})()} + ) } diff --git a/src/components/Message/Message.tsx b/src/components/Message/Message.tsx index d96ff21b..f70b2a35 100644 --- a/src/components/Message/Message.tsx +++ b/src/components/Message/Message.tsx @@ -53,6 +53,8 @@ export interface MessageTopLevelProps extends TextMessageTopLevelProps { ) => React.ReactNode /** Show user avatars for received messages. Useful for a group chat. */ showUserAvatars?: boolean + + onAvatarPress? :() => void } export interface MessageProps extends MessageTopLevelProps { @@ -81,6 +83,7 @@ export const Message = React.memo( renderFileMessage, renderImageMessage, renderTextMessage, + onAvatarPress, roundBorder, showAvatar, showName, @@ -189,6 +192,7 @@ export const Message = React.memo( showAvatar, showUserAvatars, theme, + onAvatarPress, }} />