Skip to content
Permalink
Browse files

Adds long press for user avatar (#1322)

  • Loading branch information...
walidvb authored and xcarpentier committed Jul 17, 2019
1 parent 061085f commit 25b23abb5c172ec7699b8575575053761f750666
Showing with 13 additions and 2 deletions.
  1. +2 −2 README.md
  2. +7 −0 src/Avatar.tsx
  3. +4 −0 src/GiftedChat.tsx
@@ -1,3 +1,4 @@
<p align="center" >
<p align="center" >
<a href="https://reactnative.gallery/FaridSafi/gifted-chat">
   <img alt="react-native-gifted-chat" src="https://thumbs.gfycat.com/AbsoluteSadDobermanpinscher-size_restricted.gif" width="260" height="510" />
@@ -285,6 +286,7 @@ interface QuickReplies {
- **`showUserAvatar`** _(Bool)_ - Whether to render an avatar for the current user; default is `false`, only show avatars for other users
- **`showAvatarForEveryMessage`** _(Bool)_ - When false, avatars will only be displayed when a consecutive message is from the same user on the same day; default is `false`
- **`onPressAvatar`** _(Function(`user`))_ - Callback when a message avatar is tapped
- **`onLongPressAvatar`** _(Function(`user`))_ - Callback when a message avatar is long-pressed
- **`renderAvatarOnTop`** _(Bool)_ - Render the message avatar at the top of consecutive messages, rather than the bottom; default is `false`
- **`renderBubble`** _(Function)_ - Custom message bubble
- **`renderSystemMessage`** _(Function)_ - Custom system message
@@ -434,5 +436,3 @@ Looking for a ReactNative freelance expert with more than 12 years experience? C


<img src="https://api.keen.io/3.0/projects/5ae31b61c9e77c0001cc2093/events/pageviews?api_key=55301C3E5BAB217E90A5867113C02506CE20385CD6F4C9C1CCDD4671B1A9DE374C3DF9DEF70C0BB3F5A9C5CA4CB1CCCFAF25FC3ED9CF63FB83102456A6881EFBAECD1C7D9718EE5402752DD8F6FA2DEC4D844BCB17FE6262570DB447D9A8CED2&data=eyJ0aXRsZSI6ICJnYyJ9" />


@@ -53,6 +53,7 @@ export interface AvatarProps<TMessage extends IMessage> {
containerStyle?: LeftRightStyle<ViewStyle>
renderAvatar?(props: Omit<AvatarProps<TMessage>, 'renderAvatar'>): ReactNode
onPressAvatar?(user: User): void
onLongPressAvatar?(user: User): void
}

export default class Avatar<
@@ -70,6 +71,7 @@ export default class Avatar<
containerStyle: {},
imageStyle: {},
onPressAvatar: () => {},
onLongPressAvatar: () => { },
}

static propTypes = {
@@ -80,6 +82,7 @@ export default class Avatar<
previousMessage: PropTypes.object,
nextMessage: PropTypes.object,
onPressAvatar: PropTypes.func,
onLongPressAvatar: PropTypes.func,
renderAvatar: PropTypes.func,
containerStyle: PropTypes.shape({
left: ViewPropTypes.style,
@@ -111,6 +114,10 @@ export default class Avatar<
this.props.onPressAvatar &&
this.props.onPressAvatar(this.props.currentMessage!.user)
}
onLongPress={() =>
this.props.onLongPressAvatar &&
this.props.onLongPressAvatar(this.props.currentMessage!.user)
}
/>
)
}
@@ -108,6 +108,8 @@ export interface GiftedChatProps<TMessage extends IMessage = IMessage> {
isCustomViewBottom?: boolean
/* Callback when a message avatar is tapped */
onPressAvatar?(user: User): void
/* Callback when a message avatar is tapped */
onLongPressAvatar?(user: User): void
/* Generate an id for new messages. Defaults to UUID v4, generated by uuid */
messageIdGenerator?(message?: TMessage): string
/* Callback when sending a message */
@@ -204,6 +206,7 @@ class GiftedChat<TMessage extends IMessage = IMessage> extends React.Component<
renderAvatar: undefined,
showUserAvatar: false,
onPressAvatar: null,
onLongPressAvatar: null,
renderUsernameOnMessage: false,
renderAvatarOnTop: false,
isCustomViewBottom: false,
@@ -265,6 +268,7 @@ class GiftedChat<TMessage extends IMessage = IMessage> extends React.Component<
renderAvatar: PropTypes.func,
showUserAvatar: PropTypes.bool,
onPressAvatar: PropTypes.func,
onLongPressAvatar: PropTypes.func,
renderUsernameOnMessage: PropTypes.bool,
renderAvatarOnTop: PropTypes.bool,
isCustomViewBottom: PropTypes.bool,

0 comments on commit 25b23ab

Please sign in to comment.
You can’t perform that action at this time.