ZAYX logo
XGitHubDiscordReddit

Notification Morph

A notification icon that unfolds into a notification tray, then reshapes itself into a profile card and a reply composer — all inside one measured, morphing container.

Open in Github
Open in ChatGPT
Open in Claude
Open in Cursor

Icon-to-tray morph

The badge grows into the notification tray while its width, height, corner radius, and the bell's fade/scale animate from shared values.

Three-stage morph

Tapping a notification reshapes the same container into that actor's profile card, then the message button opens a reply composer — no screen swap.

Measured content sizing

Every content layer reports its own layout, so the container animates between measured sizes instead of hard-coded heights.

Host-controlled visibility

open, onOpen, and onClose keep visibility in your screen's state; after the collapse settles, a post-send toast springs in below the badge.

Installation

Copy the command directly into your project.

npx degit ManasCodeXart/ZAYX/components/notif-morph components/notif-morph

Install the needed dependencies

npx expo install react-native-reanimated react-native-worklets && npm install phosphor-react-native@^3.0.6

Use in your app

Built to match the preview exactly — for the complete implementation, check the repo on GitHub.

import { useState } from "react"; import { Pressable, StyleSheet, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import NotifMorph from "../../components/notif-morph/components/NotifMorph"; import type { Notification } from "../constants/types"; export default function NotificationsScreen() { const [open, setOpen] = useState(false); const insets = useSafeAreaInsets(); return ( <View style={styles.root}> {open && ( <Pressable accessibilityLabel="Close notifications" onPress={() => setOpen(false)} style={styles.dismiss} /> )} <NotifMorph anchorRight={insets.right + 20} anchorTop={insets.top + 12} open={open} onOpen={() => setOpen(true)} onClose={() => setOpen(false)} onSend={(text: string, notification: Notification) => { console.log("send", text, notification.id); }} /> </View> ); } const styles = StyleSheet.create({ root: { flex: 1 }, dismiss: { bottom: 0, left: 0, position: "absolute", right: 0, top: 0, zIndex: 1, }, });

API

<NotifMorph>

PropTypeDefaultDescription
anchorRightnumber0Distance from the host's right edge to the card's right edge.
anchorTopnumber0Distance from the host's top edge to the card's top edge. Ignored when centered is set.
centeredbooleanfalseCentres the card and toast in the parent instead of anchoring them.
openboolean—Controlled visibility. true shows the tray; false collapses to the badge.
onOpen() => void—Fired when the collapsed bell is pressed. The component does not change open itself.
onClose() => void—Fired when the profile/reply card background is tapped or after the composer sends.
onSend(text: string, notification: Notification) => void—Fired after Send with the trimmed composer text and the active notification.
triggerIconReactNodebuilt-in BellReplaces the collapsed badge icon. The red dot is still rendered.

<NotifMorphExpanded>

PropTypeDefaultDescription
activeboolean—Drives the staggered content reveal.
profileProfile—Actor shown in the card.
widthnumber—Card width. NotifMorph caps it at 300 design units and clamps it to the space left of the anchor.
onPress() => void—Fired when the card background is pressed.
onReplyPress() => void—Fired by the message button; opens the composer.

<NotifMorphReply>

PropTypeDefaultDescription
activeboolean—Drives the staggered content reveal.
notificationNotification—Supplies the quoted reply text and selects reply vs. message copy.
profileProfile—Actor shown in the header.
widthnumber—Card width, using the same computed width as the profile card.
onPress() => void—Fired when the card background is pressed.
onSend(text: string) => void—Fired with trimmed text. The Send button only appears while the input contains non-whitespace.

Morph primitives

Prop / OptionTypeDefaultDescription
MorphContentLayer.activeboolean—Controls opacity, scale, touch, and accessibility visibility.
MorphContentLayer.contentKeystring—Key passed back with the measured size.
MorphContentLayer.onMeasure(key: string, w: number, h: number) => void—Receives ceil-rounded dimensions from onLayout.
MorphStaggerItem.indexnumber—Stagger position: delay is 140 + 45 × index ms.
useMorphBox.activeKeystring | null—Key into sizes to open, or null to collapse.
useMorphContent.slideDistancenumber65Horizontal travel distance in design units.

useMorphSizeMap

const { measure, sizes } = useMorphSizeMap();

measure(key, w, h) ignores non-positive sizes and returns the same state object when the stored size is unchanged. sizes is a plain Record<string, MorphSize>.

Types

interface MorphSize { readonly w: number; readonly h: number; } type MorphSizeMap = Record<string, MorphSize>; type MorphMode = "stack" | "replace"; interface UseMorphBoxOptions { activeKey: string | null; sizes: MorphSizeMap; collapsedSize: MorphSize; mode?: MorphMode; minWidth?: number; duration?: number; easing?: EasingFunctionFactory; onCollapseComplete?: () => void; } interface UseMorphContentOptions { active: boolean; direction?: -1 | 0 | 1; duration?: number; easing?: EasingFunctionFactory; slideDistance?: number; } type NotificationType = "like" | "follow" | "reply"; type Notification = | { id: string; actorId: string; timestamp: string; read: boolean; type: "like"; postSnippet: string; } | { id: string; actorId: string; timestamp: string; read: boolean; type: "follow"; } | { id: string; actorId: string; timestamp: string; read: boolean; type: "reply"; replyText: string; replyingToHandle: string; }; type Profile = { readonly id: string; readonly name: string; readonly handle: string; readonly avatarSource: ImageSourcePropType; readonly verified: boolean; readonly bio: string; readonly followers: number; readonly following: number; readonly isFollowing: boolean; readonly mutualFollowers: { readonly previewIds: readonly string[]; readonly totalCount: number; }; };

Project Structure

notif-morph/
├── components/
│ ├── NotifMorph.tsx # Root component — bell badge, tray, profile, and composer stages
│ ├── NotifMorphExpanded.tsx # Profile card — staggered header, bio, stats, mutuals, and actions
│ ├── NotifMorphReply.tsx # Reply/message composer with quoted notification text
│ ├── MorphContentLayer.tsx # Absolute morphing layer for tray, profile, and composer stages
│ └── MorphStaggerItem.tsx # Shared staggered fade-in primitive
├── hooks/
│ ├── useMorphBox.ts # Box width/height animation between measured sizes
│ ├── useMorphContent.ts # Layer opacity, translate, and scale animation
│ └── useMorphSizeMap.ts # Measured size registry keyed by content
├── constants/
│ ├── constants.ts # Morph timing and sizing constants
│ ├── scaling.ts # verticalScale helpers
│ ├── types.ts # Notification, Profile, and morph hook types
│ ├── mockNotifications.ts # Demo notification data
│ └── mockProfiles.ts # Demo profile data
└── assets/images/