Notification Morph
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.
Install the needed dependencies
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>
| Prop | Type | Default | Description |
|---|---|---|---|
| anchorRight | number | 0 | Distance from the host's right edge to the card's right edge. |
| anchorTop | number | 0 | Distance from the host's top edge to the card's top edge. Ignored when centered is set. |
| centered | boolean | false | Centres the card and toast in the parent instead of anchoring them. |
| open | boolean | — | 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. |
| triggerIcon | ReactNode | built-in Bell | Replaces the collapsed badge icon. The red dot is still rendered. |
<NotifMorphExpanded>
| Prop | Type | Default | Description |
|---|---|---|---|
| active | boolean | — | Drives the staggered content reveal. |
| profile | Profile | — | Actor shown in the card. |
| width | number | — | 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>
| Prop | Type | Default | Description |
|---|---|---|---|
| active | boolean | — | Drives the staggered content reveal. |
| notification | Notification | — | Supplies the quoted reply text and selects reply vs. message copy. |
| profile | Profile | — | Actor shown in the header. |
| width | number | — | 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 / Option | Type | Default | Description |
|---|---|---|---|
| MorphContentLayer.active | boolean | — | Controls opacity, scale, touch, and accessibility visibility. |
| MorphContentLayer.contentKey | string | — | Key passed back with the measured size. |
| MorphContentLayer.onMeasure | (key: string, w: number, h: number) => void | — | Receives ceil-rounded dimensions from onLayout. |
| MorphStaggerItem.index | number | — | Stagger position: delay is 140 + 45 × index ms. |
| useMorphBox.activeKey | string | null | — | Key into sizes to open, or null to collapse. |
| useMorphContent.slideDistance | number | 65 | Horizontal 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;
};
};