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

* [FIX] StoryBook

* [FIX] UIKit crash when some app send a list

* [CHORE] Update snapshot

* [CHORE] Remove token & id
This commit is contained in:
Djorkaeff Alexandre 2020-05-18 13:25:13 -03:00 committed by GitHub
parent 5c99d8aa8d
commit 8c5538b148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 86 additions and 38 deletions

View File

@ -5161,6 +5161,25 @@ exports[`Storyshots UiKitMessage list uikitmessage 1`] = `
> >
Section Section
</Text> </Text>
<Text
style={
Array [
Object {
"fontSize": 20,
"fontWeight": "300",
"marginLeft": 10,
"marginTop": 30,
},
Object {
"backgroundColor": "#ffffff",
"color": "#0d0e12",
},
undefined,
]
}
>
Section + Markdown List
</Text>
<Text <Text
style={ style={
Array [ Array [

View File

@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit'; import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import sharedStyles from '../../views/Styles';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
content: { content: {
@ -18,11 +17,7 @@ const styles = StyleSheet.create({
}, },
text: { text: {
flex: 1, flex: 1,
padding: 4, padding: 4
fontSize: 16,
lineHeight: 22,
textAlignVertical: 'center',
...sharedStyles.textRegular
}, },
field: { field: {
marginVertical: 6 marginVertical: 6
@ -54,7 +49,7 @@ export const Section = ({
accessory && accessoriesRight.includes(accessory.type) ? styles.row : styles.column 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} {fields ? <Fields fields={fields} theme={theme} parser={parser} /> : null}
{accessory ? <Accessory element={{ blockId, appId, ...accessory }} parser={parser} /> : null} {accessory ? <Accessory element={{ blockId, appId, ...accessory }} parser={parser} /> : null}
</View> </View>

View File

@ -1,6 +1,6 @@
/* eslint-disable class-methods-use-this */ /* eslint-disable class-methods-use-this */
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import { StyleSheet } from 'react-native'; import { StyleSheet, Text } from 'react-native';
import { import {
uiKitMessage, uiKitMessage,
UiKitParserMessage, UiKitParserMessage,
@ -13,8 +13,9 @@ import Markdown from '../markdown';
import Button from '../Button'; import Button from '../Button';
import TextInput from '../TextInput'; import TextInput from '../TextInput';
import { useBlockContext } from './utils'; import { useBlockContext, textParser } from './utils';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import sharedStyles from '../../views/Styles';
import { Divider } from './Divider'; import { Divider } from './Divider';
import { Section } from './Section'; import { Section } from './Section';
@ -37,6 +38,12 @@ const styles = StyleSheet.create({
}, },
button: { button: {
marginBottom: 16 marginBottom: 16
},
text: {
fontSize: 16,
lineHeight: 22,
textAlignVertical: 'center',
...sharedStyles.textRegular
} }
}); });
@ -46,7 +53,7 @@ class MessageParser extends UiKitParserMessage {
text({ text, type } = { text: '' }, context) { text({ text, type } = { text: '' }, context) {
const { theme } = useContext(ThemeContext); const { theme } = useContext(ThemeContext);
if (type !== 'mrkdwn') { if (type !== 'mrkdwn') {
return text; return <Text style={[styles.text, { color: themes[theme].bodyText }]}>{text}</Text>;
} }
const isContext = context === BLOCK_CONTEXT.CONTEXT; const isContext = context === BLOCK_CONTEXT.CONTEXT;
@ -70,7 +77,7 @@ class MessageParser extends UiKitParserMessage {
<Button <Button
key={actionId} key={actionId}
type={style} type={style}
title={this.text(text)} title={textParser([text])}
loading={loading} loading={loading}
onPress={() => action({ value })} onPress={() => action({ value })}
style={styles.button} style={styles.button}

View File

@ -8,7 +8,6 @@ import messagesStatus from '../../app/constants/messagesStatus';
import MessageSeparator from '../../app/views/RoomView/Separator'; import MessageSeparator from '../../app/views/RoomView/Separator';
import { themes } from '../../app/constants/colors'; import { themes } from '../../app/constants/colors';
import MessageContext from '../../app/containers/message/Context';
let _theme = 'light'; let _theme = 'light';
@ -42,32 +41,17 @@ const getCustomEmoji = (content) => {
}; };
const Message = props => ( const Message = props => (
<MessageContext.Provider <MessageComponent
value={{ baseUrl={baseUrl}
user, user={user}
baseUrl, author={author}
onPress: () => {}, ts={date}
onLongPress: () => {}, timeFormat='LT'
reactionInit: () => {}, isHeader
onErrorPress: () => {}, getCustomEmoji={getCustomEmoji}
replyBroadcast: () => {}, theme={_theme}
onReactionPress: () => {}, {...props}
onDiscussionPress: () => {}, />
onReactionLongPress: () => {}
}}
>
<MessageComponent
baseUrl={baseUrl}
user={user}
author={author}
ts={date}
timeFormat='LT'
isHeader
getCustomEmoji={getCustomEmoji}
theme={_theme}
{...props}
/>
</MessageContext.Provider>
); );
// eslint-disable-next-line react/prop-types // eslint-disable-next-line react/prop-types

View File

@ -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' /> <Separator title='Section + Overflow' />
{ {
UiKitMessage([ UiKitMessage([

View File

@ -11,6 +11,16 @@ import UiKitModal from './UiKitModal';
import Markdown from './Markdown'; import Markdown from './Markdown';
// import RoomViewHeader from './RoomViewHeader'; // 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 // Change here to see themed storybook
const theme = 'light'; const theme = 'light';
@ -26,15 +36,37 @@ const reducers = combineReducers({
}); });
const store = createStore(reducers); 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) storiesOf('RoomItem', module)
.addDecorator(story => <Provider store={store}>{story()}</Provider>) .addDecorator(story => <Provider store={store}>{story()}</Provider>)
.add('list roomitem', () => <RoomItem theme={theme} />); .add('list roomitem', () => <RoomItem theme={theme} />);
storiesOf('Message', module) storiesOf('Message', module)
.addDecorator(messageDecorator)
.add('list message', () => <Message theme={theme} />); .add('list message', () => <Message theme={theme} />);
storiesOf('UiKitMessage', module) storiesOf('UiKitMessage', module)
.addDecorator(messageDecorator)
.add('list uikitmessage', () => <UiKitMessage theme={theme} />); .add('list uikitmessage', () => <UiKitMessage theme={theme} />);
storiesOf('UiKitModal', module) storiesOf('UiKitModal', module)
.addDecorator(messageDecorator)
.add('list UiKitModal', () => <UiKitModal theme={theme} />); .add('list UiKitModal', () => <UiKitModal theme={theme} />);
storiesOf('Markdown', module) storiesOf('Markdown', module)
.add('list Markdown', () => <Markdown theme={theme} />); .add('list Markdown', () => <Markdown theme={theme} />);