Changeset View
Changeset View
Standalone View
Standalone View
native/chat/inner-text-message.react.js
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | function InnerTextMessage(props: Props): React.Node { | ||||
const { item } = props; | const { item } = props; | ||||
const { text, creator } = item.messageInfo; | const { text, creator } = item.messageInfo; | ||||
const { isViewer } = creator; | const { isViewer } = creator; | ||||
const activeTheme = useSelector(state => state.globalThemeInfo.activeTheme); | const activeTheme = useSelector(state => state.globalThemeInfo.activeTheme); | ||||
const boundColors = useColors(); | const boundColors = useColors(); | ||||
const messageStyle = {}; | const messageStyle = {}; | ||||
const textStyle = {}; | |||||
let darkColor; | let darkColor; | ||||
if (isViewer) { | if (isViewer) { | ||||
const threadColor = item.threadInfo.color; | const threadColor = item.threadInfo.color; | ||||
messageStyle.backgroundColor = | messageStyle.backgroundColor = | ||||
props.threadColorOverride ?? `#${threadColor}`; | props.threadColorOverride ?? `#${threadColor}`; | ||||
darkColor = props.isThreadColorDarkOverride ?? colorIsDark(threadColor); | darkColor = props.isThreadColorDarkOverride ?? colorIsDark(threadColor); | ||||
} else { | } else { | ||||
messageStyle.backgroundColor = boundColors.listChatBubble; | messageStyle.backgroundColor = boundColors.listChatBubble; | ||||
darkColor = activeTheme === 'dark'; | darkColor = activeTheme === 'dark'; | ||||
} | } | ||||
textStyle.color = darkColor | |||||
? colors.dark.listForegroundLabel | |||||
: colors.light.listForegroundLabel; | |||||
const cornerStyle = getRoundedContainerStyle(filterCorners(allCorners, item)); | const cornerStyle = getRoundedContainerStyle(filterCorners(allCorners, item)); | ||||
if (!__DEV__) { | if (!__DEV__) { | ||||
// We don't force view height in dev mode because we | // We don't force view height in dev mode because we | ||||
// want to measure it in Message to see if it's correct | // want to measure it in Message to see if it's correct | ||||
messageStyle.height = item.contentHeight; | messageStyle.height = item.contentHeight; | ||||
} | } | ||||
const rules = useTextMessageMarkdownRules(darkColor); | const rules = useTextMessageMarkdownRules(darkColor); | ||||
const markdownStyles = React.useMemo(() => { | |||||
const textStyle = { | |||||
color: darkColor | |||||
? colors.dark.listForegroundLabel | |||||
: colors.light.listForegroundLabel, | |||||
}; | |||||
return [styles.text, textStyle]; | |||||
}, [darkColor]); | |||||
const message = ( | const message = ( | ||||
<TouchableWithoutFeedback> | <TouchableWithoutFeedback> | ||||
<View> | <View> | ||||
<GestureTouchableOpacity | <GestureTouchableOpacity | ||||
onPress={props.onPress} | onPress={props.onPress} | ||||
onLongPress={props.onPress} | onLongPress={props.onPress} | ||||
activeOpacity={0.6} | activeOpacity={0.6} | ||||
style={[styles.message, cornerStyle]} | style={[styles.message, cornerStyle]} | ||||
animatedStyle={messageStyle} | animatedStyle={messageStyle} | ||||
> | > | ||||
<Markdown style={[styles.text, textStyle]} rules={rules}> | <Markdown style={markdownStyles} rules={rules}> | ||||
{text} | {text} | ||||
</Markdown> | </Markdown> | ||||
</GestureTouchableOpacity> | </GestureTouchableOpacity> | ||||
</View> | </View> | ||||
</TouchableWithoutFeedback> | </TouchableWithoutFeedback> | ||||
); | ); | ||||
// We need to set onLayout in order to allow .measure() to be on the ref | // We need to set onLayout in order to allow .measure() to be on the ref | ||||
Show All 31 Lines |