Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
xcarpentier committed May 13, 2019
1 parent 36a2ccc commit 34d1084
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 17 deletions.
108 changes: 92 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
- InputToolbar avoiding keyboard
- Redux support
- System message
- **Bot message implementation [soon](https://github.com/FaridSafi/react-native-gifted-chat/pull/1211)**
- Quick Reply messages

## Dependency

Expand All @@ -102,35 +102,35 @@
## Example

```jsx
import React from "react";
import { GiftedChat } from "react-native-gifted-chat";
import React from 'react'
import { GiftedChat } from 'react-native-gifted-chat'

class Example extends React.Component {
state = {
messages: []
};
messages: [],
}

componentWillMount() {
this.setState({
messages: [
{
_id: 1,
text: "Hello developer",
text: 'Hello developer',
createdAt: new Date(),
user: {
_id: 2,
name: "React Native",
avatar: "https://placeimg.com/140/140/any"
}
}
]
});
name: 'React Native',
avatar: 'https://placeimg.com/140/140/any',
},
},
],
})
}

onSend(messages = []) {
this.setState(previousState => ({
messages: GiftedChat.append(previousState.messages, messages)
}));
messages: GiftedChat.append(previousState.messages, messages),
}))
}

render() {
Expand All @@ -139,10 +139,10 @@ class Example extends React.Component {
messages={this.state.messages}
onSend={messages => this.onSend(messages)}
user={{
_id: 1
_id: 1,
}}
/>
);
)
}
}
```
Expand Down Expand Up @@ -188,6 +188,80 @@ e.g. System Message
}
```

### e.g. Chat Message with Quick Reply options

See PR #[1211](https://github.com/FaridSafi/react-native-gifted-chat/pull/1211)

```ts
interface Reply {
title: string
value: string
messageId?: any
}

interface QuickReplies {
type: 'radio' | 'checkbox'
values: Reply[]
keepIt?: boolean
}
```

```js
{
_id: 1,
text: 'This is a quick reply. Do you love Gifted Chat? (radio) KEEP IT',
createdAt: new Date(),
quickReplies: {
type: 'radio', // or 'checkbox',
keepIt: true,
values: [
{
title: '😋 Yes',
value: 'yes',
},
{
title: '📷 Yes, let me show you with a picture!',
value: 'yes_picture',
},
{
title: '😞 Nope. What?',
value: 'no',
},
],
},
user: {
_id: 2,
name: 'React Native',
},
},
{
_id: 2,
text: 'This is a quick reply. Do you love Gifted Chat? (checkbox)',
createdAt: new Date(),
quickReplies: {
type: 'checkbox', // or 'radio',
values: [
{
title: 'Yes',
value: 'yes',
},
{
title: 'Yes, let me show you with a picture!',
value: 'yes_picture',
},
{
title: 'Nope. What?',
value: 'no',
},
],
},
user: {
_id: 2,
name: 'React Native',
},
}
```

## Props

- **`messages`** _(Array)_ - Messages to display
Expand Down Expand Up @@ -259,6 +333,8 @@ e.g. System Message
* **`scrollToBottomComponent`** _(Function)_ - Custom Scroll To Bottom Component container
* **`scrollToBottomOffset`** _(Integer)_ - Custom Height Offset upon which to begin showing Scroll To Bottom Component (Default is 200)
* **`alignTop`** _(Boolean)_ Controls whether or not the message bubbles appear at the top of the chat (Default is false - bubbles align to bottom)
* **`onQuickReply`** _(Function)_ - Callback when sending a quick reply (to backend server)
* **`renderQuickReply`** _(Function)_ - Custom quick reply view

## Imperative methods

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface User {
export interface Reply {
title: string
value: string
messageId?: string
messageId?: any
}

export interface QuickReplies {
Expand Down

0 comments on commit 34d1084

Please sign in to comment.