weechatRN

Weechat relay client for iOS using websockets https://github.com/mhoran/weechatRN
git clone http://git.hanabi.in/repos/weechatRN.git
Log | Files | Refs | README | LICENSE

commit 703801b1d3359ceda11c351788abbe62b1614dc9
parent e39a08dccaa0d47436a02206154bcc11855bbc0b
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date:   Sun,  1 Apr 2018 17:26:19 +0200

Move rendering to component

Diffstat:
Msrc/lib/weechat/color-formatter.tsx | 17++++++-----------
Msrc/usecase/buffers/ui/themes/Default.tsx | 12++++++++----
2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/lib/weechat/color-formatter.tsx b/src/lib/weechat/color-formatter.tsx @@ -1,5 +1,4 @@ -import * as React from "react"; -import { TextStyle, Text } from "react-native"; +import { TextStyle, TextProperties } from "react-native"; import { WeeChatProtocol } from "./parser"; import { ceb, cwb, cob, cef, cwf, cof } from "./colors"; @@ -39,19 +38,15 @@ const getFgColor = (colorAttr: WeechatColorAttribute): TextStyle => { } }; -export const renderWeechatFormat = (input: string): React.ReactNode => { +export const renderWeechatFormat = (input: string): TextProperties[] => { const formattedNode = WeeChatProtocol.rawText2Rich( input ) as AttributedStringNode[]; - return formattedNode.map((node, index) => ( - <Text - key={index} - style={[getBgColor(node.bgColor), getFgColor(node.fgColor)]} - > - {node.text} - </Text> - )); + return formattedNode.map(node => ({ + children: node.text, + style: [getBgColor(node.bgColor), getFgColor(node.fgColor)] + })); }; export const getHighlightedViewStyles = line => { diff --git a/src/usecase/buffers/ui/themes/Default.tsx b/src/usecase/buffers/ui/themes/Default.tsx @@ -30,7 +30,9 @@ export default class BufferLine extends React.Component<Props> { <View style={styles.metaContainer}> <View style={styles.userContainer}> <Text style={[styles.text, styles.meta]}> - {renderWeechatFormat(line.prefix)} + {renderWeechatFormat(line.prefix).map((props, index) => ( + <Text {...props} key={index} /> + ))} </Text> </View> <Text @@ -42,9 +44,11 @@ export default class BufferLine extends React.Component<Props> { <View style={[styles.messageContainer, getHighlightedViewStyles(line)]} > - <ParsedText style={[styles.text]} parse={parseArgs}> - {renderWeechatFormat(line.message)} - </ParsedText> + <Text style={styles.text}> + {renderWeechatFormat(line.message).map((props, index) => ( + <ParsedText {...props} key={index} parse={parseArgs} /> + ))} + </Text> </View> </View> </TouchableHighlight>