Skip to content

Commit

Permalink
Calculate nick width based on 8 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed Mar 14, 2024
1 parent ff43f93 commit 81342b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/usecase/buffers/ui/Buffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Header: React.FC<HeaderProps> = ({ bufferId, lines, fetchMoreLines }) => {
};

interface State {
letterWidth: number;
nickWidth: number;
}

export default class Buffer extends React.PureComponent<Props, State> {
Expand All @@ -57,7 +57,7 @@ export default class Buffer extends React.PureComponent<Props, State> {
linesList = React.createRef<FlashList<WeechatLine>>();

state = {
letterWidth: 0
nickWidth: 0
};

componentDidUpdate(prevProps: Props) {
Expand All @@ -82,7 +82,7 @@ export default class Buffer extends React.PureComponent<Props, State> {
line={item}
onLongPress={onLongPress}
parseArgs={parseArgs}
letterWidth={this.state.letterWidth}
nickWidth={this.state.nickWidth}
lastReadLine={lastReadLine}
lastMessageDate={lastMessage?.date}
/>
Expand All @@ -92,15 +92,15 @@ export default class Buffer extends React.PureComponent<Props, State> {
render() {
const { bufferId, lines, fetchMoreLines } = this.props;

if (!this.state.letterWidth) {
if (!this.state.nickWidth) {
return (
<Text
onLayout={(layout) => {
this.setState({ letterWidth: layout.nativeEvent.layout.width });
this.setState({ nickWidth: layout.nativeEvent.layout.width });
}}
style={[lineStyles.text, { opacity: 0, position: 'absolute' }]}
>
a
aaaaaaaa
</Text>
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/usecase/buffers/ui/BufferLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Props {
line: WeechatLine;
onLongPress: (line: WeechatLine) => void;
parseArgs: ParseShape[];
letterWidth: number;
nickWidth: number;
lastReadLine?: string;
lastMessageDate?: string;
}
Expand All @@ -19,7 +19,7 @@ const BufferLine: React.FC<Props> = ({
line,
onLongPress,
parseArgs,
letterWidth,
nickWidth,
lastReadLine,
lastMessageDate
}) => {
Expand All @@ -42,7 +42,7 @@ const BufferLine: React.FC<Props> = ({
line={line}
onLongPress={onLongPress}
parseArgs={parseArgs}
letterWidth={letterWidth}
nickWidth={nickWidth}
/>
</>
)}
Expand Down
12 changes: 5 additions & 7 deletions src/usecase/buffers/ui/themes/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ interface Props {
line: WeechatLine;
onLongPress: (line: WeechatLine) => void;
parseArgs: ParseShape[];
letterWidth: number;
nickWidth: number;
}

const BufferLine: React.FC<Props> = ({
line,
onLongPress,
parseArgs,
letterWidth
nickWidth
}) => {
return (
<TouchableHighlight onLongPress={() => onLongPress(line)}>
Expand All @@ -27,8 +27,7 @@ const BufferLine: React.FC<Props> = ({
style={[
styles.text,
{
width: letterWidth * 8,
paddingRight: letterWidth,
width: nickWidth,
textAlign: 'right'
}
]}
Expand All @@ -44,6 +43,7 @@ const BufferLine: React.FC<Props> = ({
);
})}
</Text>
<Text style={styles.text}> </Text>

<View style={[styles.messageContainer]}>
<Text style={styles.text}>
Expand All @@ -53,9 +53,7 @@ const BufferLine: React.FC<Props> = ({
</Text>
</View>

<Text style={[styles.text, { paddingLeft: letterWidth }]}>
{formatDate(line.date)}
</Text>
<Text style={[styles.text]}> {formatDate(line.date)}</Text>
</View>
</TouchableHighlight>
);
Expand Down

0 comments on commit 81342b6

Please sign in to comment.