From 04b4bc4ad3c68fee98b58bf0b17561b4b619adfe Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 26 Oct 2026 22:22:48 +0200 Subject: [PATCH] =?UTF-8?q?[APP-3621]=20Notifications=20v2=20row=20polish:?= =?UTF-8?q?=20follow=20back=20alignment,=20+N=20count,=20=E2=80=9Creplied?= =?UTF-8?q?=20to=20you=E2=80=9D=20(#12209)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Claude Opus 5.5 --- .oxlintrc.json | 3 +- .../Notifications/__tests__/avatarRow.test.ts | 130 ++++++++++++++++-- .../NotificationItem/Item/avatarRow.ts | 60 ++++++-- .../NotificationItem/Item/group.tsx | 58 ++++---- .../components/NotificationItem/Item/post.tsx | 33 +++-- .../NotificationItem/Item/profile.tsx | 36 +++++ .../NotificationItem/LoadingSkeleton.tsx | 23 ++-- .../NotificationItem/kinds/profile.tsx | 45 +++--- 8 files changed, 287 insertions(+), 101 deletions(-) diff --git a/.oxlintrc.json b/.oxlintrc.json index d05dcca6b..971fdd0fd 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -230,7 +230,8 @@ "Toast.Action", "AgeAssuranceAdmonition", "Span", - "StackedButton" + "StackedButton", + "Strong" ], "impliedTextProps": [], "suggestedTextWrappers": { diff --git a/src/screens/Notifications/__tests__/avatarRow.test.ts b/src/screens/Notifications/__tests__/avatarRow.test.ts index d34eb53ed..9e643f23e 100644 --- a/src/screens/Notifications/__tests__/avatarRow.test.ts +++ b/src/screens/Notifications/__tests__/avatarRow.test.ts @@ -2,46 +2,150 @@ import {describe, expect, it} from '@jest/globals' import {fitAvatarCount} from '#/screens/Notifications/components/NotificationItem/Item/avatarRow' +/** + * Formats the "+N" as the app does in English, compacting thousands. + */ +function formatRemaining(remaining: number) { + return remaining >= 1000 + ? `+${Math.floor(remaining / 100) / 10}K` + : `+${remaining}` +} + /* * Each avatar takes 36 (28 and a gap of 8). The toggle takes 32 with just - * the chevron, or 56 with a "+N" chip. + * the chevron. With a "+N" it takes 36 and 10 for each character of the + * "+N", e.g. 66 for "+17" and 86 for "+1.2K". */ describe('fitAvatarCount', () => { - it('shows everyone, without a chip, when they all fit', () => { + it('shows everyone, without a "+N", when they all fit', () => { // 6 * 36 + 32 = 248 expect( - fitAvatarCount({width: 248, resolved: 6, total: 6, hasToggle: true}), + fitAvatarCount({ + width: 248, + resolved: 6, + total: 6, + hasToggle: true, + formatRemaining, + }), ).toBe(6) }) - it('makes room for the chip once everyone no longer fits', () => { - // 247 is too narrow for all 6 and the chevron, and (247 - 56) / 36 = 5.3 + it('makes room for the "+N" once everyone no longer fits', () => { + // 247 is too narrow for all 6 and the chevron. 5 and "+1" take 236 expect( - fitAvatarCount({width: 247, resolved: 6, total: 6, hasToggle: true}), + fitAvatarCount({ + width: 247, + resolved: 6, + total: 6, + hasToggle: true, + formatRemaining, + }), ).toBe(5) + // 235 is too narrow for that, and 4 and "+2" take 200 + expect( + fitAvatarCount({ + width: 235, + resolved: 6, + total: 6, + hasToggle: true, + formatRemaining, + }), + ).toBe(4) }) - it('always leaves room for the chip when some people are unresolved', () => { - // There's room for all 3 profiles, but 17 more people need the chip + it('always leaves room for the "+N" when some people are unresolved', () => { + // There's room for all 3 profiles, but 17 more people need the "+N" expect( - fitAvatarCount({width: 1000, resolved: 3, total: 20, hasToggle: true}), + fitAvatarCount({ + width: 1000, + resolved: 3, + total: 20, + hasToggle: true, + formatRemaining, + }), ).toBe(3) - // (148 - 56) / 36 = 2.5, a phone row beside a thumbnail + // 2 and "+18" take 138, a phone row beside a thumbnail expect( - fitAvatarCount({width: 148, resolved: 9, total: 20, hasToggle: true}), + fitAvatarCount({ + width: 148, + resolved: 9, + total: 20, + hasToggle: true, + formatRemaining, + }), ).toBe(2) }) + it('leaves more room for a longer "+N"', () => { + // 4 and "+16" take 210 + expect( + fitAvatarCount({ + width: 220, + resolved: 9, + total: 20, + hasToggle: true, + formatRemaining, + }), + ).toBe(4) + // 4 and "+1.2K" take 230, but 3 and "+1.2K" take 194 + expect( + fitAvatarCount({ + width: 220, + resolved: 9, + total: 1250, + hasToggle: true, + formatRemaining, + }), + ).toBe(3) + }) + + it('checks each count against the "+N" it would show', () => { + /* + * 3 leaves "+1K", but 4 leaves "+999", which is a character longer. 4 and + * "+999" take 220, and 3 and "+1K" take 174 + */ + expect( + fitAvatarCount({ + width: 220, + resolved: 9, + total: 1003, + hasToggle: true, + formatRemaining, + }), + ).toBe(4) + expect( + fitAvatarCount({ + width: 219, + resolved: 9, + total: 1003, + hasToggle: true, + formatRemaining, + }), + ).toBe(3) + }) + it('never shows more than fit, even if that means none', () => { expect( - fitAvatarCount({width: 60, resolved: 9, total: 20, hasToggle: true}), + fitAvatarCount({ + width: 60, + resolved: 9, + total: 20, + hasToggle: true, + formatRemaining, + }), ).toBe(0) }) it('needs no room for a toggle when there is none', () => { // A pair named in full: one avatar, 28 wide expect( - fitAvatarCount({width: 28, resolved: 1, total: 1, hasToggle: false}), + fitAvatarCount({ + width: 28, + resolved: 1, + total: 1, + hasToggle: false, + formatRemaining, + }), ).toBe(1) }) }) diff --git a/src/screens/Notifications/components/NotificationItem/Item/avatarRow.ts b/src/screens/Notifications/components/NotificationItem/Item/avatarRow.ts index f53c3c804..c18a13497 100644 --- a/src/screens/Notifications/components/NotificationItem/Item/avatarRow.ts +++ b/src/screens/Notifications/components/NotificationItem/Item/avatarRow.ts @@ -12,8 +12,8 @@ export const PREVIEW_AVATAR_SIZE = 28 export const AVATAR_GAP = space.sm /** - * Padding either side of the toggle's chevron. With a "+N" chip, the chip - * takes the place of the left padding. + * Padding either side of the toggle's contents, the "+N" count and the + * chevron. */ export const TOGGLE_PADDING = 8 @@ -23,40 +23,70 @@ export const TOGGLE_PADDING = 8 export const CHEVRON_SIZE = 16 /** - * Space between the toggle's "+N" chip and its chevron. + * Space between the toggle's "+N" count and its chevron. */ -export const CHIP_GAP = space.xs +export const COUNT_GAP = space.xs + +/** + * How much room each character of the toggle's "+N" count is allowed. The + * count doesn't scale with the font size, and this is wider than a digit, + * "+", "." or a compact suffix like "K" are at its size, so it errs on the + * side of room to spare. A wide character, e.g. the "万" in "+1.2万", can go + * over, but it's never the only one, and the narrow ones around it make up + * for it. + */ +export const COUNT_CHAR_WIDTH = 10 /** * How many avatars an `AvatarRow` that's `width` wide can show, out of the * `resolved` profiles it has for the group's `total` other people. It ends - * with the toggle, if `hasToggle`. + * with the toggle, if `hasToggle`. `formatRemaining` gives the toggle's "+N" + * for everyone the row leaves out, e.g. "+21" or "+1.2K". * * Shows as many as fit, never more, so the row can't overflow. When everyone - * fits there's no "+N" chip, so the toggle only needs room for the chevron. - * Otherwise it leaves room for the chip as well. + * fits there's no "+N", so the toggle only needs room for the chevron. + * Otherwise it leaves room for the "+N" it would show, which the text's + * length decides. */ export function fitAvatarCount({ width, resolved, total, hasToggle, + formatRemaining, }: { width: number resolved: number total: number hasToggle: boolean + formatRemaining: (remaining: number) => string }) { const perAvatar = PREVIEW_AVATAR_SIZE + AVATAR_GAP - const chevronOnly = hasToggle - ? TOGGLE_PADDING + CHEVRON_SIZE + TOGGLE_PADDING - : // No toggle, so no gap after the last avatar either - -AVATAR_GAP + if (!hasToggle) { + // No toggle, so no gap after the last avatar either + const fit = Math.floor((width + AVATAR_GAP) / perAvatar) + return Math.min(Math.max(fit, 0), resolved) + } + + const chevronOnly = TOGGLE_PADDING + CHEVRON_SIZE + TOGGLE_PADDING if (resolved >= total && resolved * perAvatar + chevronOnly <= width) { return resolved } - const withChip = - PREVIEW_AVATAR_SIZE + CHIP_GAP + CHEVRON_SIZE + TOGGLE_PADDING - const fit = Math.floor((width - withChip) / perAvatar) - return Math.min(Math.max(fit, 0), resolved) + /* + * Each avatar left out adds one to the "+N", which can make it longer, so + * each count is checked against the "+N" it would show + */ + for (let count = Math.min(resolved, total - 1); count > 0; count--) { + const label = formatRemaining(total - count) + const toggle = + TOGGLE_PADDING + + label.length * COUNT_CHAR_WIDTH + + COUNT_GAP + + CHEVRON_SIZE + + TOGGLE_PADDING + if (count * perAvatar + toggle <= width) { + return count + } + } + return 0 } diff --git a/src/screens/Notifications/components/NotificationItem/Item/group.tsx b/src/screens/Notifications/components/NotificationItem/Item/group.tsx index b1c3ac67e..401ba8ee6 100644 --- a/src/screens/Notifications/components/NotificationItem/Item/group.tsx +++ b/src/screens/Notifications/components/NotificationItem/Item/group.tsx @@ -9,10 +9,10 @@ import { type AccessibilityActionEvent, type AccessibilityProps, type GestureResponderEvent, - StyleSheet, View, } from 'react-native' import {moderateProfile} from '@bsky/sdk/moderation' +import {type I18n} from '@lingui/core' import {useLingui} from '@lingui/react/macro' import {HITSLOP_10} from '#/lib/constants' @@ -383,12 +383,13 @@ function GroupActorList({ * Renders nothing in a row about one person. * * Shows as many avatars as fit the row's width, each linking to its profile. - * Then, if the group expands, a "+N" chip for everyone else and a chevron + * Then, if the group expands, a "+N" count of everyone else and a chevron * saying whether it's expanded. The group may have resolved fewer profiles - * than it has people, in which case the avatars run out early and the chip - * counts the rest. + * than it has people, in which case the avatars run out early and the count + * covers the rest. */ export function AvatarRow() { + const {i18n} = useLingui() const moderationOpts = useModerationOpts() const group = useContext(GroupContext) const rowRef = useRef>(null) @@ -417,6 +418,7 @@ export function AvatarRow() { resolved: others.length, total: group.count - 1, hasToggle: !!group.expansion, + formatRemaining: remaining => formatRemaining(i18n, remaining), }) const shown = others.slice(0, count) const remaining = Math.max(group.count - 1 - shown.length, 0) @@ -449,7 +451,7 @@ export function AvatarRow() { } /** - * The end of an `AvatarRow`: a "+N" chip for anyone it didn't show, and the + * The end of an `AvatarRow`: a "+N" count of anyone it didn't show, and the * chevron. Unless pressing the row toggles the group already, they're a * button that does, with some slop around them. On native, screen readers * don't reach it inside the row's header, which they can expand instead. @@ -470,13 +472,11 @@ function GroupToggle({ a.align_center, a.gap_xs, a.rounded_full, - {height: PREVIEW_AVATAR_SIZE, paddingRight: TOGGLE_PADDING}, - // A chevron on its own is padded to a circle - remaining === 0 && {paddingLeft: TOGGLE_PADDING}, + {height: PREVIEW_AVATAR_SIZE, paddingHorizontal: TOGGLE_PADDING}, ] const contents = ( <> - {remaining > 0 && } + {remaining > 0 && } ) @@ -499,34 +499,28 @@ function GroupToggle({ } /** - * The "+N" in an `AvatarRow`, sized to match the avatars. + * The text of an `AvatarRow`'s "+N", e.g. "+21" or "+1.2K". */ -function OverflowChip({count}: {count: number}) { +function formatRemaining(i18n: I18n, count: number) { + return `+${formatCount(i18n, count)}` +} + +/** + * The "+N" in an `AvatarRow`, counting everyone it didn't show. It doesn't + * scale with the font size, so that `fitAvatarCount` knows how much room it + * takes. + */ +function OverflowCount({count}: {count: number}) { const t = useTheme() const {i18n} = useLingui() return ( - - {/* Fixed size, since it has to fit inside the circle */} - - {`+${formatCount(i18n, count)}`} - - + + {formatRemaining(i18n, count)} + ) } diff --git a/src/screens/Notifications/components/NotificationItem/Item/post.tsx b/src/screens/Notifications/components/NotificationItem/Item/post.tsx index bd256f329..870409257 100644 --- a/src/screens/Notifications/components/NotificationItem/Item/post.tsx +++ b/src/screens/Notifications/components/NotificationItem/Item/post.tsx @@ -194,15 +194,12 @@ function ReplyContextPost({ const {t: l} = useLingui() const {currentAccount} = useSession() const moderationOpts = useModerationOpts() - const name = forceLTR(useDisplayName(post.author)) + /* + * Who was replied to, when it isn't the viewer. The sentences name their + * placeholder after this, so it stays `subject` to keep their translations + */ + const subject = forceLTR(useDisplayName(post.author)) const isViewer = post.author.did === currentAccount?.did - const subject = isViewer - ? l({ - message: 'you', - comment: - 'Emphasised in “replied to you: ...”, in a notification where someone replied to the viewer’s own post', - }) - : name const isHidden = moderationOpts ? moderatePost(post, moderationOpts).ui('contentList').blur @@ -248,16 +245,28 @@ function ReplyContextPost({ ) + /* + * The viewer gets sentences of their own, rather than "you" filled in for + * `subject`, since some languages word the rest differently for "you" + */ if (variant === 'reply') { - return ( - + return isViewer ? ( + + replied to you: {previewNode} + + ) : ( + replied to {subject}: {previewNode} ) } - return ( - + return isViewer ? ( + + in reply to you: {previewNode} + + ) : ( + in reply to {subject}: {previewNode} ) diff --git a/src/screens/Notifications/components/NotificationItem/Item/profile.tsx b/src/screens/Notifications/components/NotificationItem/Item/profile.tsx index 1ce4ffc02..a5b0ff93c 100644 --- a/src/screens/Notifications/components/NotificationItem/Item/profile.tsx +++ b/src/screens/Notifications/components/NotificationItem/Item/profile.tsx @@ -116,6 +116,42 @@ function PillButton({ ) } +/** + * How far a pill reaches above and below the line of `Item.PrimaryText` + * beside it, at the default font size. The pill is the taller of the two, so + * this centres it on the line without making the line any taller. + */ +const PILL_OVERHANG = + (PILL_HEIGHT - Math.round(tokens.fontSize.md * tokens.lineHeight.snug)) / 2 + +/** + * A row's headline with a pill, e.g. `Item.FollowButton`, beside its first + * line. Whatever comes after it in `Item.Content` runs the full width of the + * row beneath the pill, rather than being cut short beside it. The pill is as + * far from the headline as `Item.Trailing` would put it, and centred on the + * headline's first line. + */ +export function HeadlineWithButton({ + button, + children, +}: { + /** + * The pill, e.g. `Item.FollowButton`. + */ + button: React.ReactNode + /** + * The headline, as an `Item.PrimaryText`. + */ + children: React.ReactNode +}) { + return ( + + {children} + {button} + + ) +} + /** * A compact follow pill for notification rows. Reads "Follow back" if they * already follow you, then "Following" once you follow them, and pressing it diff --git a/src/screens/Notifications/components/NotificationItem/LoadingSkeleton.tsx b/src/screens/Notifications/components/NotificationItem/LoadingSkeleton.tsx index 0dfe1ebd6..122a62d53 100644 --- a/src/screens/Notifications/components/NotificationItem/LoadingSkeleton.tsx +++ b/src/screens/Notifications/components/NotificationItem/LoadingSkeleton.tsx @@ -197,8 +197,8 @@ function ReactionSkeleton({index}: {index: number}) { } /** - * Stands in for a single follow: the headline, a short line of who you have - * in common, the time, and a follow button. + * Stands in for a single follow: the headline with a follow button beside + * it, a short line of who you have in common, and the time. */ function FollowSkeleton({index}: {index: number}) { const even = index % 2 === 0 @@ -207,13 +207,12 @@ function FollowSkeleton({index}: {index: number}) { - + }> + + - - - ) } @@ -360,8 +359,8 @@ function TimestampSkeleton() { } /** - * Stands in for `Item.AvatarRow` and its avatars. With `overflow`, a - * fainter circle at the end stands in for its "+N" chip. + * Stands in for `Item.AvatarRow` and its avatars. With `overflow`, a fainter + * bar at the end stands in for its "+N" count. */ function AvatarRowSkeleton({ count, @@ -375,7 +374,13 @@ function AvatarRowSkeleton({ {Array.from({length: count}, (_, index) => ( ))} - {overflow && } + {overflow && ( + + )} ) } diff --git a/src/screens/Notifications/components/NotificationItem/kinds/profile.tsx b/src/screens/Notifications/components/NotificationItem/kinds/profile.tsx index 4a33238b3..b0bb30b4b 100644 --- a/src/screens/Notifications/components/NotificationItem/kinds/profile.tsx +++ b/src/screens/Notifications/components/NotificationItem/kinds/profile.tsx @@ -67,11 +67,19 @@ function SingleFollowNotification({ - - - followed you - - + + }> + + + followed you + + + {starterPack && Item.getStarterPackName(starterPack) ? ( ) : ( @@ -80,9 +88,6 @@ function SingleFollowNotification({ - - - ) } @@ -337,19 +342,21 @@ export function ContactMatchNotification({ testID={`notification-contactMatch-${notification.id}`}> - - - Your contact is on Bluesky - - + + }> + + + Your contact is on Bluesky + + + - - - ) } -- knotmirror 0.0.1