Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] UIKit crash when some app send a list #2117

Merged
merged 4 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions __tests__/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5161,6 +5161,25 @@ exports[`Storyshots UiKitMessage list uikitmessage 1`] = `
>
Section
</Text>
<Text
style={
Array [
Object {
"fontSize": 20,
"fontWeight": "300",
"marginLeft": 10,
"marginTop": 30,
},
Object {
"backgroundColor": "#ffffff",
"color": "#0d0e12",
},
undefined,
]
}
>
Section + Markdown List
</Text>
<Text
style={
Array [
Expand Down
9 changes: 2 additions & 7 deletions app/containers/UIKit/Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit';

import { themes } from '../../constants/colors';
import sharedStyles from '../../views/Styles';

const styles = StyleSheet.create({
content: {
Expand All @@ -18,11 +17,7 @@ const styles = StyleSheet.create({
},
text: {
flex: 1,
padding: 4,
fontSize: 16,
lineHeight: 22,
textAlignVertical: 'center',
...sharedStyles.textRegular
padding: 4
},
field: {
marginVertical: 6
Expand Down Expand Up @@ -54,7 +49,7 @@ export const Section = ({
accessory && accessoriesRight.includes(accessory.type) ? styles.row : styles.column
]}
>
{text ? <Text style={[styles.text, { color: themes[theme].bodyText }]}>{parser.text(text)}</Text> : null}
{text ? <View style={styles.text}>{parser.text(text)}</View> : null}
{fields ? <Fields fields={fields} theme={theme} parser={parser} /> : null}
{accessory ? <Accessory element={{ blockId, appId, ...accessory }} parser={parser} /> : null}
</View>
Expand Down
15 changes: 11 additions & 4 deletions app/containers/UIKit/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable class-methods-use-this */
import React, { useContext } from 'react';
import { StyleSheet } from 'react-native';
import { StyleSheet, Text } from 'react-native';
import {
uiKitMessage,
UiKitParserMessage,
Expand All @@ -13,8 +13,9 @@ import Markdown from '../markdown';
import Button from '../Button';
import TextInput from '../TextInput';

import { useBlockContext } from './utils';
import { useBlockContext, textParser } from './utils';
import { themes } from '../../constants/colors';
import sharedStyles from '../../views/Styles';

import { Divider } from './Divider';
import { Section } from './Section';
Expand All @@ -37,6 +38,12 @@ const styles = StyleSheet.create({
},
button: {
marginBottom: 16
},
text: {
fontSize: 16,
lineHeight: 22,
textAlignVertical: 'center',
...sharedStyles.textRegular
}
});

Expand All @@ -46,7 +53,7 @@ class MessageParser extends UiKitParserMessage {
text({ text, type } = { text: '' }, context) {
const { theme } = useContext(ThemeContext);
if (type !== 'mrkdwn') {
return text;
return <Text style={[styles.text, { color: themes[theme].bodyText }]}>{text}</Text>;
}

const isContext = context === BLOCK_CONTEXT.CONTEXT;
Expand All @@ -70,7 +77,7 @@ class MessageParser extends UiKitParserMessage {
<Button
key={actionId}
type={style}
title={this.text(text)}
title={textParser([text])}
loading={loading}
onPress={() => action({ value })}
style={styles.button}
Expand Down
38 changes: 11 additions & 27 deletions storybook/stories/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import messagesStatus from '../../app/constants/messagesStatus';
import MessageSeparator from '../../app/views/RoomView/Separator';

import { themes } from '../../app/constants/colors';
import MessageContext from '../../app/containers/message/Context';

let _theme = 'light';

Expand Down Expand Up @@ -42,32 +41,17 @@ const getCustomEmoji = (content) => {
};

const Message = props => (
<MessageContext.Provider
value={{
user,
baseUrl,
onPress: () => {},
onLongPress: () => {},
reactionInit: () => {},
onErrorPress: () => {},
replyBroadcast: () => {},
onReactionPress: () => {},
onDiscussionPress: () => {},
onReactionLongPress: () => {}
}}
>
<MessageComponent
baseUrl={baseUrl}
user={user}
author={author}
ts={date}
timeFormat='LT'
isHeader
getCustomEmoji={getCustomEmoji}
theme={_theme}
{...props}
/>
</MessageContext.Provider>
<MessageComponent
baseUrl={baseUrl}
user={user}
author={author}
ts={date}
timeFormat='LT'
isHeader
getCustomEmoji={getCustomEmoji}
theme={_theme}
{...props}
/>
);

// eslint-disable-next-line react/prop-types
Expand Down
11 changes: 11 additions & 0 deletions storybook/stories/UiKitMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ export default () => (
}])
}

<Separator title='Section + Markdown List' />
{
UiKitMessage([{
type: 'section',
text: {
type: 'mrkdwn',
text: '*List*:\n1. Item'
}
}])
}

<Separator title='Section + Overflow' />
{
UiKitMessage([
Expand Down
32 changes: 32 additions & 0 deletions storybook/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import UiKitModal from './UiKitModal';
import Markdown from './Markdown';
// import RoomViewHeader from './RoomViewHeader';

import MessageContext from '../../app/containers/message/Context';

// MessageProvider
const baseUrl = 'https://open.rocket.chat';
const user = {
id: '',
username: 'diego.mello',
token: ''
};

// Change here to see themed storybook
const theme = 'light';

Expand All @@ -26,15 +36,37 @@ const reducers = combineReducers({
});
const store = createStore(reducers);

const messageDecorator = story => (
<MessageContext.Provider
value={{
user,
baseUrl,
onPress: () => {},
onLongPress: () => {},
reactionInit: () => {},
onErrorPress: () => {},
replyBroadcast: () => {},
onReactionPress: () => {},
onDiscussionPress: () => {},
onReactionLongPress: () => {}
}}
>
{story()}
</MessageContext.Provider>
);

storiesOf('RoomItem', module)
.addDecorator(story => <Provider store={store}>{story()}</Provider>)
.add('list roomitem', () => <RoomItem theme={theme} />);
storiesOf('Message', module)
.addDecorator(messageDecorator)
.add('list message', () => <Message theme={theme} />);

storiesOf('UiKitMessage', module)
.addDecorator(messageDecorator)
.add('list uikitmessage', () => <UiKitMessage theme={theme} />);
storiesOf('UiKitModal', module)
.addDecorator(messageDecorator)
.add('list UiKitModal', () => <UiKitModal theme={theme} />);
storiesOf('Markdown', module)
.add('list Markdown', () => <Markdown theme={theme} />);
Expand Down