Skip to content

Commit 1fd0457

Browse files
Merge pull request #99 from GetStream/vishal/message-text-styles-issue
CRNS-36: Adding custom style support for markdown
2 parents 0a7f694 + 9c0c2ee commit 1fd0457

File tree

5 files changed

+76
-35
lines changed

5 files changed

+76
-35
lines changed

src/components/MessageSimple/MessageContent.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ const Container = styled.TouchableOpacity`
3333
: theme.colors.transparent};
3434
border-bottom-left-radius: ${({ alignment, theme }) =>
3535
alignment === 'left'
36-
? theme.message.text.borderRadiusS
37-
: theme.message.text.borderRadiusL};
36+
? theme.message.content.container.borderRadiusS
37+
: theme.message.content.container.borderRadiusL};
3838
border-bottom-right-radius: ${({ alignment, theme }) =>
3939
alignment === 'left'
40-
? theme.message.text.borderRadiusL
41-
: theme.message.text.borderRadiusS};
42-
border-top-left-radius: ${({ theme }) => theme.message.text.borderRadiusL};
43-
border-top-right-radius: ${({ theme }) => theme.message.text.borderRadiusL};
40+
? theme.message.content.container.borderRadiusL
41+
: theme.message.content.container.borderRadiusS};
42+
border-top-left-radius: ${({ theme }) =>
43+
theme.message.content.container.borderRadiusL};
44+
border-top-right-radius: ${({ theme }) =>
45+
theme.message.content.container.borderRadiusL};
4446
${({ theme }) => theme.message.content.container.css};
4547
`;
4648

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import React from 'react';
2-
import styled from '@stream-io/styled-components';
2+
import styled, { withTheme } from '@stream-io/styled-components';
33

44
import { renderText, capitalize } from '../../utils';
55

66
const TextContainer = styled.View`
77
border-bottom-left-radius: ${({ theme, groupStyle }) =>
88
groupStyle.indexOf('left') !== -1
9-
? theme.message.text.borderRadiusS
10-
: theme.message.text.borderRadiusL};
9+
? theme.message.content.textContainer.borderRadiusS
10+
: theme.message.content.textContainer.borderRadiusL};
1111
border-bottom-right-radius: ${({ theme, groupStyle }) =>
1212
groupStyle.indexOf('right') !== -1
13-
? theme.message.text.borderRadiusS
14-
: theme.message.text.borderRadiusL};
13+
? theme.message.content.textContainer.borderRadiusS
14+
: theme.message.content.textContainer.borderRadiusL};
1515
border-top-left-radius: ${({ theme, groupStyle }) =>
1616
groupStyle === 'leftBottom' || groupStyle === 'leftMiddle'
17-
? theme.message.text.borderRadiusS
18-
: theme.message.text.borderRadiusL};
17+
? theme.message.content.textContainer.borderRadiusS
18+
: theme.message.content.textContainer.borderRadiusL};
1919
border-top-right-radius: ${({ theme, groupStyle }) =>
2020
groupStyle === 'rightBottom' || groupStyle === 'rightMiddle'
21-
? theme.message.text.borderRadiusS
22-
: theme.message.text.borderRadiusL};
21+
? theme.message.content.textContainer.borderRadiusS
22+
: theme.message.content.textContainer.borderRadiusL};
2323
margin-top: 2;
2424
padding: 5px;
2525
padding-left: 8;
@@ -28,20 +28,20 @@ const TextContainer = styled.View`
2828
alignment === 'left' ? 'flex-start' : 'flex-end'};
2929
border-width: ${({ theme, alignment }) =>
3030
alignment === 'left'
31-
? theme.message.text.leftBorderWidth
32-
: theme.message.text.rightBorderWidth};
31+
? theme.message.content.textContainer.leftBorderWidth
32+
: theme.message.content.textContainer.rightBorderWidth};
3333
border-color: ${({ theme, alignment }) =>
3434
alignment === 'left'
35-
? theme.message.text.leftBorderColor
36-
: theme.message.text.rightBorderColor};
35+
? theme.message.content.textContainer.leftBorderColor
36+
: theme.message.content.textContainer.rightBorderColor};
3737
background-color: ${({ theme, alignment, type, status }) =>
3838
alignment === 'left' || type === 'error' || status === 'failed'
3939
? theme.colors.transparent
4040
: theme.colors.light};
41-
${({ theme }) => theme.message.text.css}
41+
${({ theme }) => theme.message.content.textContainer.css}
4242
`;
4343

44-
export const MessageTextContainer = (props) => {
44+
export const MessageTextContainer = withTheme((props) => {
4545
const {
4646
message,
4747
groupStyles = ['bottom'],
@@ -56,7 +56,9 @@ export const MessageTextContainer = (props) => {
5656
capitalize(hasAttachment ? 'bottom' : groupStyles[0]);
5757

5858
if (!message.text) return false;
59-
59+
const markdownStyles = props.theme
60+
? props.theme.message.content.markdown
61+
: {};
6062
return (
6163
<React.Fragment>
6264
<TextContainer
@@ -66,11 +68,11 @@ export const MessageTextContainer = (props) => {
6668
type={message.type}
6769
>
6870
{!MessageText ? (
69-
renderText(message)
71+
renderText(message, markdownStyles)
7072
) : (
7173
<MessageText {...props} renderText={renderText} />
7274
)}
7375
</TextContainer>
7476
</React.Fragment>
7577
);
76-
};
78+
});

src/components/docs/MessageSimple.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,31 @@ const data = require('./data');
5353
{...data.channelContext}
5454
/>;
5555
```
56+
57+
We use [markdown](https://github.com/CharlesMangwa/react-native-simple-markdown) to render the text in message.
58+
59+
You can customize the styles of message text by providing custom styles in theme object:
60+
61+
Available options for customization are: https://github.com/CharlesMangwa/react-native-simple-markdown/tree/next#styles-1
62+
63+
```json
64+
const theme = {
65+
message: {
66+
content: {
67+
markdown: {
68+
text: {
69+
fontFamily: 'AppleSDGothicNeo-Bold'
70+
},
71+
link: {
72+
color: 'pink'
73+
}
74+
}
75+
}
76+
}
77+
}
78+
79+
...
80+
<Chat client={client} style={theme}>
81+
...
82+
</Chat>
83+
```

src/styles/theme.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export const defaultTheme = {
5858
message: {
5959
container: {},
6060
content: {
61-
container: {},
61+
container: {
62+
borderRadiusL: 16,
63+
borderRadiusS: 2,
64+
},
6265
containerInner: {},
6366
metaContainer: {},
6467
metaText: {},
@@ -67,6 +70,16 @@ export const defaultTheme = {
6770
},
6871
deletedContainer: {},
6972
deletedText: {},
73+
textContainer: {
74+
borderRadiusL: 16,
75+
borderRadiusS: 2,
76+
leftBorderWidth: 0.5,
77+
leftBorderColor: 'rgba(0,0,0,0.08)',
78+
rightBorderWidth: 0,
79+
rightBorderColor: 'transparent',
80+
},
81+
// Available options for styling text: https://github.com/CharlesMangwa/react-native-simple-markdown/tree/next#styles-1
82+
markdown: {},
7083
},
7184
status: {
7285
spacer: {},
@@ -87,14 +100,6 @@ export const defaultTheme = {
87100
messageRepliesText: {},
88101
image: {},
89102
},
90-
text: {
91-
borderRadiusL: 16,
92-
borderRadiusS: 2,
93-
leftBorderWidth: 0.5,
94-
leftBorderColor: 'rgba(0,0,0,0.08)',
95-
rightBorderWidth: 0,
96-
rightBorderColor: 'transparent',
97-
},
98103
file: {
99104
container: {},
100105
details: {},

src/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CommandsItem } from './components/CommandsItem';
66

77
import Markdown from '@stream-io/react-native-simple-markdown';
88

9-
export const renderText = (message) => {
9+
export const renderText = (message, styles) => {
1010
// take the @ mentions and turn them into markdown?
1111
// translate links
1212
let { text } = message;
@@ -38,11 +38,15 @@ export const renderText = (message) => {
3838
}
3939

4040
newText = newText.replace(/[<&"'>]/g, '\\$&');
41+
const markdownStyles = {
42+
...defaultMarkdownStyles,
43+
...styles,
44+
};
4145

4246
return <Markdown styles={markdownStyles}>{newText}</Markdown>;
4347
};
4448

45-
const markdownStyles = {
49+
const defaultMarkdownStyles = {
4650
link: {
4751
color: 'blue',
4852
textDecorationLine: 'underline',

0 commit comments

Comments
 (0)