From 656127aaabb1a174c33b7dab2d6cc8005842ddf7 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 1 Apr 2021 10:32:03 -0300 Subject: [PATCH] [FIX] App crashing when attachment color is an invalid HEX (#3021) --- .../__snapshots__/Storyshots.test.js.snap | 79 +++++++++++++++++++ app/containers/message/Reply.js | 13 ++- storybook/stories/Message.js | 6 ++ 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/__tests__/__snapshots__/Storyshots.test.js.snap b/__tests__/__snapshots__/Storyshots.test.js.snap index 8b698bc08..ae844bbb5 100644 --- a/__tests__/__snapshots__/Storyshots.test.js.snap +++ b/__tests__/__snapshots__/Storyshots.test.js.snap @@ -41357,6 +41357,85 @@ exports[`Storyshots Message list message 1`] = ` + + + + + + Invalid color + + + + + diff --git a/app/containers/message/Reply.js b/app/containers/message/Reply.js index caa80039a..698eec945 100644 --- a/app/containers/message/Reply.js +++ b/app/containers/message/Reply.js @@ -158,6 +158,16 @@ const Reply = React.memo(({ openLink(url, theme); }; + let { borderColor, chatComponentBackground: backgroundColor } = themes[theme]; + try { + if (attachment.color) { + backgroundColor = transparentize(attachment.color, 0.80); + borderColor = attachment.color; + } + } catch (e) { + // fallback to default + } + return ( <> 0 && styles.marginTop, attachment.description && styles.marginBottom, { - backgroundColor: attachment.color ? transparentize(attachment.color, 0.80) : themes[theme].chatComponentBackground, - borderColor: attachment.color || themes[theme].borderColor + backgroundColor, borderColor } ]} background={Touchable.Ripple(themes[theme].bannerBackground)} diff --git a/storybook/stories/Message.js b/storybook/stories/Message.js index ac5181d8c..e4dbf6e25 100644 --- a/storybook/stories/Message.js +++ b/storybook/stories/Message.js @@ -775,6 +775,12 @@ export default ({ theme }) => { value: 'Value 2', short: true }] + }, { + color: 'ASDASD', + fields: [{ + title: 'Invalid color', + short: true + }] }]} />