Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/containers/Header/components/HeaderContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { memo } from 'react';
import { useWindowDimensions, View, type ViewProps, StyleSheet } from 'react-native';
import { useWindowDimensions, View, type ViewProps, StyleSheet, Platform } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import { useTheme } from '../../../../theme';
Expand All @@ -17,6 +17,7 @@ const HeaderContainer = memo(

const insets = useSafeAreaInsets();
const { colors } = useTheme();
const isAndroid = Platform.OS === 'android';
const { height, width } = useWindowDimensions();
const isPortrait = height > width;
const paddingTop = isPortrait && !isMasterDetail ? 0 : 4;
Expand All @@ -27,6 +28,7 @@ const HeaderContainer = memo(
return (
<View
style={{
minHeight: isAndroid ? 56 : 44,
alignItems: 'center',
flexDirection: 'row',
paddingBottom,
Expand Down
18 changes: 12 additions & 6 deletions app/containers/Header/components/HeaderTitle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React, { memo, type ReactNode } from 'react';
import { Text, View } from 'react-native';
import { Text, type TextProps, View } from 'react-native';

import { isAndroid } from '../../../../lib/methods/helpers';
import { useTheme } from '../../../../theme';
import { styles } from './styles';

interface IHeaderTitle {
headerTitle?: string | ((props: { children: string; tintColor?: string }) => ReactNode);
position?: 'left' | 'center' | 'right';
}

const HeaderTitle = memo(({ headerTitle }: IHeaderTitle) => {
type HeaderTitleProps = IHeaderTitle & TextProps;
const HeaderTitle = memo(({ headerTitle, position, ...props }: HeaderTitleProps) => {
'use memo';

const { colors } = useTheme();
Expand All @@ -24,8 +26,10 @@ const HeaderTitle = memo(({ headerTitle }: IHeaderTitle) => {
numberOfLines={1}
style={{
...styles.androidTitle,
color: colors.fontTitlesLabels
}}>
color: colors.fontTitlesLabels,
alignSelf: position === 'left' ? 'flex-start' : 'center'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Handle all position values explicitly.

The current implementation only distinguishes between 'left' and everything else (defaulting to 'center'). The 'right' position value is accepted by the type but would incorrectly render as centered. Consider implementing all three position values explicitly.

Apply this diff to handle all position values:

 					...styles.androidTitle,
 					color: colors.fontTitlesLabels,
-					alignSelf: position === 'left' ? 'flex-start' : 'center'
+					alignSelf: position === 'left' ? 'flex-start' : position === 'right' ? 'flex-end' : 'center'
 				}}

And similarly for the non-Android branch:

 					...styles.title,
 					color: colors.fontTitlesLabels,
-					alignSelf: position === 'left' ? 'flex-start' : 'center'
+					alignSelf: position === 'left' ? 'flex-start' : position === 'right' ? 'flex-end' : 'center'
 				}}

Also applies to: 44-44

🤖 Prompt for AI Agents
In app/containers/Header/components/HeaderTitle/index.tsx around lines 30 and
44, the style sets alignSelf using a binary check (position === 'left' ?
'flex-start' : 'center') which misrenders position='right'; update both the
Android and non-Android branches to handle all three explicit values ('left' ->
'flex-start', 'center' -> 'center', 'right' -> 'flex-end') (use a switch or
explicit conditional chain) so each position maps to the correct alignSelf.

}}
{...props}>
{headerTitle}
</Text>
);
Expand All @@ -36,8 +40,10 @@ const HeaderTitle = memo(({ headerTitle }: IHeaderTitle) => {
numberOfLines={1}
style={{
...styles.title,
color: colors.fontTitlesLabels
}}>
color: colors.fontTitlesLabels,
alignSelf: position === 'left' ? 'flex-start' : 'center'
}}
{...props}>
{headerTitle}
</Text>
</View>
Expand Down
11 changes: 4 additions & 7 deletions app/containers/Header/components/HeaderTitle/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ export const styles = StyleSheet.create({
},
title: {
...sharedStyles.textBold,
fontSize: 18,
flex: 1,
lineHeight: 24,
paddingVertical: 6
fontSize: 16,
justifyContent: 'center',
alignItems: 'center'
},
androidTitle: {
...sharedStyles.textBold,
fontSize: 18,
flex: 1,
lineHeight: 24,
paddingVertical: 10
flex: 1
}
});
39 changes: 5 additions & 34 deletions app/containers/RoomHeader/RoomHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { StyleSheet, Text, useWindowDimensions, View } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';
import { Pressable } from 'react-native-gesture-handler';

import { useResponsiveLayout } from '../../lib/hooks/useResponsiveLayout/useResponsiveLayout';
import HeaderTitle from '../Header/components/HeaderTitle';
import I18n from '../../i18n';
import sharedStyles from '../../views/Styles';
import { MarkdownPreview } from '../markdown';
Expand All @@ -19,7 +19,6 @@ const HIT_SLOP = {
bottom: 5,
left: 5
};
const TITLE_SIZE = 16;
const SUBTITLE_SIZE = 12;

const getSubTitleSize = (scale: number) => SUBTITLE_SIZE * scale;
Expand All @@ -33,10 +32,6 @@ const styles = StyleSheet.create({
alignItems: 'center',
flexDirection: 'row'
},
title: {
flexShrink: 1,
...sharedStyles.textSemibold
},
subtitle: {
flexShrink: 1,
...sharedStyles.textRegular
Expand All @@ -53,14 +48,6 @@ type TRoomHeaderSubTitle = {
scale: number;
};

type TRoomHeaderHeaderTitle = {
title?: string;
tmid?: string;
prid?: string;
scale: number;
testID?: string;
};

interface IRoomHeader {
title?: string;
subtitle?: string;
Expand Down Expand Up @@ -115,22 +102,6 @@ const SubTitle = React.memo(({ usersTyping, subtitle, renderFunc, scale }: TRoom
return null;
});

const HeaderTitle = React.memo(({ title, tmid, prid, scale, testID }: TRoomHeaderHeaderTitle) => {
const { colors } = useTheme();
const { isLargeFontScale } = useResponsiveLayout();

const titleStyle = { fontSize: TITLE_SIZE * scale, color: colors.fontTitlesLabels };
if (!tmid && !prid) {
return (
<Text style={[styles.title, titleStyle]} numberOfLines={isLargeFontScale ? 2 : 1} testID={testID}>
{title}
</Text>
);
}

return <MarkdownPreview msg={title} style={[styles.title, titleStyle]} testID={testID} />;
});

const Header = React.memo(
({
title,
Expand Down Expand Up @@ -201,7 +172,7 @@ const Header = React.memo(
accessible
accessibilityLabel={accessibilityLabel}
accessibilityRole='header'>
<TouchableOpacity testID='room-header' onPress={handleOnPress} disabled={disabled} hitSlop={HIT_SLOP}>
<Pressable testID='room-header' onPress={handleOnPress} disabled={disabled} hitSlop={HIT_SLOP}>
<View style={styles.titleContainer}>
{tmid ? null : (
<RoomTypeIcon
Expand All @@ -214,10 +185,10 @@ const Header = React.memo(
abacAttributes={abacAttributes}
/>
)}
<HeaderTitle title={title} tmid={tmid} prid={prid} scale={scale} testID={testID} />
<HeaderTitle headerTitle={title ?? ''} testID={testID} position='left' />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Hard-coded position='left' contradicts platform-specific requirement.

The PR description states "On Android the headerTitle is left-aligned; on iOS it is centered," but the position prop is hard-coded to 'left'. This means the title will be left-aligned on both platforms.

📱 Proposed fix for platform-specific alignment
+import { Platform } from 'react-native';
+
 // ... inside the component
-						<HeaderTitle headerTitle={title ?? ''} testID={testID} position='left' />
+						<HeaderTitle headerTitle={title ?? ''} testID={testID} position={Platform.OS === 'ios' ? 'center' : 'left'} />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<HeaderTitle headerTitle={title ?? ''} testID={testID} position='left' />
import { Platform } from 'react-native';
// ... rest of imports and component code ...
<HeaderTitle headerTitle={title ?? ''} testID={testID} position={Platform.OS === 'ios' ? 'center' : 'left'} />
🤖 Prompt for AI Agents
In @app/containers/RoomHeader/RoomHeader.tsx at line 188, HeaderTitle is
currently forced to position='left', breaking the stated platform behavior;
change the prop to set position conditionally (e.g., position={Platform.OS ===
'android' ? 'left' : 'center'} or use your existing isIos/isAndroid helper) and
import Platform from 'react-native' if not already imported, keeping
headerTitle={title ?? ''} and testID={testID} intact.

</View>
<SubTitle usersTyping={tmid ? [] : usersTyping} subtitle={subtitle} renderFunc={renderFunc} scale={scale} />
</TouchableOpacity>
</Pressable>
</View>
);
}
Expand Down
Loading