Skip to content

Commit

Permalink
Merge pull request #4 from NDKien349/main
Browse files Browse the repository at this point in the history
feat: render other message
  • Loading branch information
vokhuyetOz authored May 17, 2024
2 parents c178b85 + cacb08f commit 1be9adc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 48 deletions.
98 changes: 50 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# react-native-messy

Chat ui for React Native

<p>
<img src="preview/demo_1.png" width="200px">
<img src="preview/demo_2.png" width="200px">
Expand Down Expand Up @@ -74,10 +75,10 @@ import { Messy } from '@vokhuyet/react-native-messy';
### TMessyMessageLocation

```typescript
name: string;
image: ImageProps['source'];
latitude: string;
longitude: string;
name: string;
image: ImageProps['source'];
latitude: string;
longitude: string;
```

### TMessyMessage
Expand All @@ -102,31 +103,31 @@ import { Messy } from '@vokhuyet/react-native-messy';
### TColor

```ts
background: string;
primary: string;
accent: string;
placeholder: string;
shadow: string;
success: string;
message_left: {
background: string;
primary: string;
accent: string;
placeholder: string;
shadow: string;
success: string;
message_left: {
background: string;
text: string;
link: string;
email: string;
phone: string;
audio: string;
};
message_right: {
background: string;
text: string;
link: string;
email: string;
phone: string;
audio: string;
};
input: {
text: string; //text color in TextInput
};
text: string;
link: string;
email: string;
phone: string;
audio: string;
}
message_right: {
background: string;
text: string;
link: string;
email: string;
phone: string;
audio: string;
}
input: {
text: string; //text color in TextInput
}
```

### TUser
Expand Down Expand Up @@ -173,26 +174,27 @@ import { Messy } from '@vokhuyet/react-native-messy';

## Props

- ```loading```(boolean): loading status
- **```messages```**([TMessyMessage[]](#tmessymessage)): list of messages
- ```user```([TUser](#tuser)): sender information;
- ```theme```: ([TColor](#tcolor)): custom theme for message;
- ```footerProps```([TMessyFooterProps](#tmessyfooterprops)): Custom props for Element below list messages;
- ```listProps```(TListProps): custom flatlist props;
- ```messageProps```([TMessageProps](#tmessageprops)): ;
- ```parsedShape```([ParseShape[]](https://github.com/taskrabbit/react-native-parsed-text)): Custom parse patterns for react-native-parsed-text ;
- ```showDateTime```(boolean): show created time of message;
- ```renderLoading```(FC<{}>): component when loading list message;
- ```renderMessageSystem```(FC<{ data?: TMessyMessage }>): custom system message;
- ```renderMessage```((data: TMessyMessageProps) => JSX.Element): custom whole message item view;
- ```renderAvatar```FC<{ user?: TUser }>: custom ;
- ```renderMessageText```((data: TMessyMessageProps) => JSX.Element): custom text message;
- ```renderMessageAudio```(data: TMessyMessageProps) => JSX.Element;
- ```renderMessageImage```(data: TMessyMessageProps) => JSX.Element;
- ```renderMessageVideo```(data: TMessyMessageProps) => JSX.Element;
- ```renderMessageDateTime```((data: TMessyMessage) => JSX.Element): custom datetime value in message item
- ```renderMessageLocation```: (data: TMessyMessageProps) => JSX.Element;
- ```BaseModule```([TBaseModule](#tbasemodule));
- `loading`(boolean): loading status
- **`messages`**([TMessyMessage[]](#tmessymessage)): list of messages
- `user`([TUser](#tuser)): sender information;
- `theme`: ([TColor](#tcolor)): custom theme for message;
- `footerProps`([TMessyFooterProps](#tmessyfooterprops)): Custom props for Element below list messages;
- `listProps`(TListProps): custom flatlist props;
- `messageProps`([TMessageProps](#tmessageprops)): ;
- `parsedShape`([ParseShape[]](https://github.com/taskrabbit/react-native-parsed-text)): Custom parse patterns for react-native-parsed-text ;
- `showDateTime`(boolean): show created time of message;
- `renderLoading`(FC<{}>): component when loading list message;
- `renderMessageSystem`(FC<{ data?: TMessyMessage }>): custom system message;
- `renderMessage`((data: TMessyMessageProps) => JSX.Element): custom whole message item view;
- `renderAvatar`FC<{ user?: TUser }>: custom ;
- `renderMessageText`((data: TMessyMessageProps) => JSX.Element): custom text message;
- `renderMessageAudio`(data: TMessyMessageProps) => JSX.Element;
- `renderMessageImage`(data: TMessyMessageProps) => JSX.Element;
- `renderMessageVideo`(data: TMessyMessageProps) => JSX.Element;
- `renderMessageDateTime`((data: TMessyMessage) => JSX.Element): custom datetime value in message item
- `renderMessageLocation`: (data: TMessyMessageProps) => JSX.Element;
- `renderMessageOther`(data: TMessyMessageProps) => JSX.Element: Customize other message types that the library does not yet support
- `BaseModule`([TBaseModule](#tbasemodule));

## Contributing

Expand Down
2 changes: 2 additions & 0 deletions src/MessyMessage/MessyMessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MessyMessageContentStatus } from './MessyMessageContentStatus';
import { MessyMessageContentLocation } from './MessyMessageContentLocation';
import { MessyMessageContentVideo } from './MessyMessageContentVideo';
import { MText } from '../elements/MText/MText';
import { MessyMessageContentOther } from './MessyMessageContentOther';

export function MessyMessageContent(props: TMessyMessageProps) {
const Sizes = useSizes();
Expand Down Expand Up @@ -95,6 +96,7 @@ export function MessyMessageContent(props: TMessyMessageProps) {
<MessyMessageContentImage {...props} />
<MessyMessageContentLocation {...props} />
<MessyMessageContentVideo {...props} />
<MessyMessageContentOther {...props} />
</View>
<View
style={{
Expand Down
20 changes: 20 additions & 0 deletions src/MessyMessage/MessyMessageContentOther.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { TMessyMessageProps } from '../types';

export function MessyMessageContentOther(props: TMessyMessageProps) {
const { renderMessageOther, value } = props;
if (
value?.text ||
value?.audio ||
value?.image ||
value?.video ||
value?.location
) {
return null;
}

if (typeof renderMessageOther === 'function') {
return renderMessageOther(props);
}

return null;
}
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type TMessyProps = Readonly<{
renderMessageVideo?: (data: TMessyMessageProps) => JSX.Element;
renderMessageDateTime?: (data: TMessyMessage) => JSX.Element;
renderMessageLocation?: (data: TMessyMessageProps) => JSX.Element;
renderMessageOther?: (data: TMessyMessageProps) => JSX.Element;
BaseModule?: TBaseModule;
}>;

Expand Down

0 comments on commit 1be9adc

Please sign in to comment.