@robono/messaging-react-native 0.20.3 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/media-ui.js CHANGED
@@ -12,7 +12,8 @@ import { MessageIcon, duration, fileSize } from './icons.js';
12
12
  /** Same chat controls on web, iOS and Android. Audio engines supply state, not a different UI. */
13
13
  export function VoicePlayback({ message, ink, accent, waveform, showWaveform = true, footer, onLongPress, mine = false, heard = false, onPlayed, background, playing = false, loading = false, positionMs = 0, durationMs = 0, error, onToggle, onSeek }) {
14
14
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
15
- const width = useRef(1), held = useRef(false), [played, setPlayed] = useState(false), progress = durationMs ? Math.max(0, Math.min(1, positionMs / durationMs)) : 0;
15
+ const width = useRef(1), held = useRef(false), [played, setPlayed] = useState(false);
16
+ const displayPosition = !playing && durationMs > 0 && positionMs >= durationMs ? 0 : positionMs, progress = durationMs ? Math.max(0, Math.min(1, displayPosition / durationMs)) : 0;
16
17
  useEffect(() => { if (playing && positionMs > 0) {
17
18
  setPlayed(true);
18
19
  onPlayed?.();
@@ -23,10 +24,10 @@ export function VoicePlayback({ message, ink, accent, waveform, showWaveform = t
23
24
  const buttonInk = buttonOverride ? messagingContrastInk(buttonOverride) : ink;
24
25
  const bars = showWaveform ? messengerVoiceWaveform(waveform, durationMs) : null, fill = voiceStyle?.waveform ?? (mine ? ink : accent);
25
26
  const hold = () => { held.current = true; onLongPress?.(); };
26
- return _jsxs(View, { testID: "voice-message-player", style: { width: 220, maxWidth: '100%', minHeight: 44, borderRadius: 24, borderWidth: 1, borderColor: ink + '24', backgroundColor: background ?? (mine ? '#1F5F7A' : '#1D1D1D'), paddingLeft: 5, paddingRight: 8, paddingVertical: 3, ...(message?.text ? { borderWidth: 0, paddingTop: 0, paddingBottom: 1 } : {}) }, children: [_jsxs(View, { style: { flexDirection: 'row', direction: 'ltr', alignItems: 'center', gap: 8 }, children: [_jsx(Pressable, { testID: "voice-play-control", accessibilityRole: "button", accessibilityLabel: playing ? uiText("Pause voice message") : uiText("Play voice message"), accessibilityState: { busy: loading }, disabled: loading, hitSlop: 6, delayLongPress: 360, onPressIn: () => { held.current = false; }, onPress: () => { if (!held.current)
27
+ return _jsxs(View, { testID: "voice-message-player", style: { width: 220, maxWidth: '100%', minHeight: 44, borderRadius: 24, borderWidth: 1, borderColor: ink + '24', backgroundColor: background ?? (mine ? '#1F5F7A' : '#1D1D1D'), paddingLeft: 5, paddingRight: 8, paddingVertical: 3 }, children: [_jsxs(View, { style: { flexDirection: 'row', direction: 'ltr', alignItems: 'center', gap: 8 }, children: [_jsx(Pressable, { testID: "voice-play-control", accessibilityRole: "button", accessibilityLabel: playing ? uiText("Pause voice message") : uiText("Play voice message"), accessibilityState: { busy: loading }, disabled: loading, hitSlop: 6, delayLongPress: 360, onPressIn: () => { held.current = false; }, onPress: () => { if (!held.current)
27
28
  onToggle(); }, onLongPress: hold, style: { width: 36, height: 36, borderRadius: 18, paddingLeft: playing ? 0 : 2, backgroundColor: buttonColor, alignItems: 'center', justifyContent: 'center' }, children: loading ? _jsx(ActivityIndicator, { size: "small", color: buttonInk }) : _jsx(MessageIcon, { name: playing ? 'pause' : 'play', color: buttonInk, size: 20 }) }), _jsxs(View, { style: { flex: 1, minWidth: 0, gap: 7 }, children: [_jsx(Pressable, { onLongPress: hold, accessibilityRole: "adjustable", accessibilityLabel: showWaveform ? uiText("Voice waveform") : uiText("Voice position"), accessibilityValue: { min: 0, max: Math.ceil(durationMs / 1000), now: Math.floor(positionMs / 1000) }, accessibilityActions: [{ name: 'increment', label: uiText("Forward five seconds") }, { name: 'decrement', label: uiText("Back five seconds") }], onAccessibilityAction: e => onSeek?.(Math.max(0, Math.min(durationMs, positionMs + (e.nativeEvent.actionName === 'increment' ? 5000 : -5000)))), onLayout: e => { width.current = e.nativeEvent.layout.width; }, onPressIn: () => { held.current = false; }, onPress: e => { if (held.current)
28
29
  return; const bounds = Platform.OS === 'web' ? e.currentTarget.getBoundingClientRect() : null; const x = bounds ? e.nativeEvent.clientX - bounds.left : e.nativeEvent.locationX; const total = bounds?.width ?? width.current; if (total > 0 && Number.isFinite(x))
29
- onSeek?.(Math.max(0, Math.min(1, x / total)) * durationMs); }, style: { height: bars ? 24 : 9, transform: [{ translateY: 4 }], flexDirection: 'row', alignItems: 'center', gap: 1 }, children: bars ? bars.map((sample, i) => _jsx(View, { pointerEvents: "none", style: { flex: 1, flexBasis: 0, borderRadius: 2, overflow: 'hidden', backgroundColor: ink + (mine ? '33' : '38'), height: 2 + sample * 18 }, children: _jsx(View, { style: { height: '100%', backgroundColor: fill, width: `${Math.max(0, Math.min(1, progress * bars.length - i)) * 100}%` } }) }, i)) : _jsx(View, { pointerEvents: "none", style: { flex: 1, height: 9, borderRadius: 5, overflow: 'hidden', backgroundColor: ink + '33' }, children: _jsx(View, { style: { height: 9, borderRadius: 5, backgroundColor: fill, width: `${progress * 100}%` } }) }) }), _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 4, paddingRight: footer ? 6 : 0 }, children: [_jsx(Text, { testID: "voice-duration", style: { color: ink, opacity: .75, fontSize: 11, fontWeight: '800', fontVariant: ['tabular-nums'] }, children: duration(playing || positionMs > 0 ? Math.max(0, durationMs - positionMs) : durationMs) }), footer && _jsx(View, { testID: "voice-message-actions", style: { flexShrink: 1, maxWidth: 112, alignItems: 'flex-end' }, children: footer })] })] })] }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: ink, fontSize: 12, marginTop: 6 }, children: error })] });
30
+ onSeek?.(Math.max(0, Math.min(1, x / total)) * durationMs); }, style: { height: bars ? 24 : 9, transform: [{ translateY: 4 }], flexDirection: 'row', alignItems: 'center', gap: 1 }, children: bars ? bars.map((sample, i) => _jsx(View, { pointerEvents: "none", style: { flex: 1, flexBasis: 0, borderRadius: 2, overflow: 'hidden', backgroundColor: ink + (mine ? '33' : '38'), height: 2 + sample * 18 }, children: _jsx(View, { style: { height: '100%', backgroundColor: fill, width: `${Math.max(0, Math.min(1, progress * bars.length - i)) * 100}%` } }) }, i)) : _jsx(View, { pointerEvents: "none", style: { flex: 1, height: 9, borderRadius: 5, overflow: 'hidden', backgroundColor: ink + '33' }, children: _jsx(View, { style: { height: 9, borderRadius: 5, backgroundColor: fill, width: `${progress * 100}%` } }) }) }), _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 4, paddingRight: footer ? 6 : 0 }, children: [_jsx(Text, { testID: "voice-duration", style: { color: ink, opacity: .75, fontSize: 11, fontWeight: '800', fontVariant: ['tabular-nums'] }, children: duration(playing || displayPosition > 0 ? Math.max(0, durationMs - displayPosition) : durationMs) }), footer && _jsx(View, { testID: "voice-message-actions", style: { flexShrink: 1, maxWidth: 112, alignItems: 'flex-end' }, children: footer })] })] })] }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: ink, fontSize: 12, marginTop: 6 }, children: error })] });
30
31
  }
31
32
  export function MediaPlaybackControls({ playing = false, loading = false, positionMs = 0, durationMs = 0, error, onToggle, onSeek, onFullscreen, fullscreen = false }) {
32
33
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
@@ -36,11 +37,11 @@ export function MediaPlaybackControls({ playing = false, loading = false, positi
36
37
  onSeek?.(Math.max(0, Math.min(1, x / total)) * durationMs); }, style: { flex: 1, height: 44, justifyContent: 'center' }, children: _jsx(View, { style: { height: 3, borderRadius: 2, backgroundColor: c.foreground + '44' }, children: _jsx(View, { style: { height: 3, borderRadius: 2, backgroundColor: appearance?.mediaViewer?.accent ?? '#ffffff', width: `${durationMs ? Math.min(100, positionMs / durationMs * 100) : 0}%` } }) }) }), _jsx(Text, { style: { color: c.foreground, fontSize: 12, fontVariant: ['tabular-nums'] }, children: duration(durationMs) }), onFullscreen && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: fullscreen ? uiText("Exit full screen") : uiText("Full screen video"), disabled: loading, onPress: onFullscreen, style: { width: 44, height: 44, alignItems: "center", justifyContent: "center" }, children: _jsx(MessageIcon, { name: fullscreen ? "close" : "open-in-new", color: c.foreground, size: 22 }) })] }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, fontSize: 13 }, children: error })] });
37
38
  }
38
39
  /** A full-size photo surface. The same tap-to-hide-controls, pinch and pan handling runs in the preview and native app. */
39
- export function ZoomablePhoto({ uri, label, onTap, expanded = false }) {
40
+ export function ZoomablePhoto({ uri, previewUri, label, onTap, expanded = false }) {
40
41
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
41
42
  label ??= uiText('Photo');
42
43
  const mediaReady = useContext(MediaReadiness), appearance = useMessagingAppearance();
43
- const [transform, setTransform] = useState({ zoom: 1, x: 0, y: 0 }), [error, setError] = useState(false);
44
+ const [transform, setTransform] = useState({ zoom: 1, x: 0, y: 0 }), [error, setError] = useState(false), [loadedUri, setLoadedUri] = useState('');
44
45
  const [viewport, setViewport] = useState({ width: 1, height: 1 }), [imageSize, setImageSize] = useState({ width: 0, height: 0, uri: "" });
45
46
  const rotated = expanded && imageSize.width > imageSize.height && viewport.height > viewport.width;
46
47
  const rotation = useRef(rotated);
@@ -103,20 +104,19 @@ export function ZoomablePhoto({ uri, label, onTap, expanded = false }) {
103
104
  element.addEventListener('dragstart', prevent);
104
105
  return () => { active.clear(); controller.end([], true); element.removeEventListener('pointerdown', down); element.removeEventListener('pointermove', move); element.removeEventListener('pointerup', end); element.removeEventListener('pointercancel', end); element.removeEventListener('lostpointercapture', end); element.removeEventListener('wheel', wheel); element.removeEventListener('keydown', key); element.removeEventListener('dragstart', prevent); };
105
106
  }, [controller, uri]);
106
- useEffect(() => { let active = true; controller.reset(); setError(false); Image.getSize(uri, (width, height) => { if (active) {
107
- controller.image(width, height);
108
- setImageSize({ width, height, uri });
109
- } }, () => { if (active)
110
- setError(true); }); return () => { active = false; }; }, [uri, controller]);
107
+ useEffect(() => { controller.reset(); setError(false); }, [uri, controller]);
111
108
  useEffect(() => { controller.reset(); }, [expanded, controller]);
112
109
  useEffect(() => { controller.layout(stageWidth, stageHeight); }, [controller, stageWidth, stageHeight]);
113
110
  // Resize the actual image as Messenger does. A transform-only zoom can keep
114
111
  // Android's decoded bitmap at its small initial display resolution.
115
112
  const contain = imageSize.width && imageSize.height ? Math.min(stageWidth / imageSize.width, stageHeight / imageSize.height) : 1;
116
113
  const imageWidth = (imageSize.width || stageWidth) * contain * transform.zoom, imageHeight = (imageSize.height || stageHeight) * contain * transform.zoom;
117
- return _jsxs(View, { style: { flex: 1, minHeight: 0, overflow: 'hidden', alignItems: 'center', justifyContent: 'center' }, onLayout: e => setViewport(e.nativeEvent.layout), children: [_jsx(View, { testID: "photo-image-stage", style: { width: stageWidth, height: stageHeight, transform: rotated ? [{ rotate: '90deg' }] : [] }, children: _jsx(View, { ref: webRef, ...(Platform.OS === 'web' ? {} : pan.panHandlers), testID: "photo-gesture-surface", accessible: true, accessibilityRole: "button", accessibilityLabel: uiText("Toggle photo controls"), onAccessibilityTap: () => tap.current?.(), ...(Platform.OS === 'web' ? { tabIndex: 0 } : {}), style: { flex: 1, overflow: 'hidden', ...(Platform.OS === 'web' ? { touchAction: 'none', userSelect: 'none' } : {}) }, children: imageSize.uri === uri && viewport.width > 1 && viewport.height > 1 && _jsx(Image, { testID: "photo-zoom-image", accessibilityLabel: label, source: { uri }, resizeMode: "contain", onLoad: () => mediaReady('image-loaded', uri), onError: () => setError(true), style: { position: 'absolute', width: imageWidth, height: imageHeight, left: (stageWidth - imageWidth) / 2 + transform.x, top: (stageHeight - imageHeight) / 2 + transform.y } }) }) }), error && _jsx(Text, { accessibilityRole: "alert", style: { position: 'absolute', top: '50%', alignSelf: 'center', color: messagingMediaColors(appearance).foreground }, children: uiText("This photo could not be opened.") })] });
114
+ return _jsxs(View, { style: { flex: 1, minHeight: 0, overflow: 'hidden', alignItems: 'center', justifyContent: 'center' }, onLayout: e => setViewport(e.nativeEvent.layout), children: [_jsx(View, { testID: "photo-image-stage", style: { width: stageWidth, height: stageHeight, transform: rotated ? [{ rotate: '90deg' }] : [] }, children: _jsxs(View, { ref: webRef, ...(Platform.OS === 'web' ? {} : pan.panHandlers), testID: "photo-gesture-surface", accessible: true, accessibilityRole: "button", accessibilityLabel: uiText("Toggle photo controls"), onAccessibilityTap: () => tap.current?.(), ...(Platform.OS === 'web' ? { tabIndex: 0 } : {}), style: { flex: 1, overflow: 'hidden', ...(Platform.OS === 'web' ? { touchAction: 'none', userSelect: 'none' } : {}) }, children: [previewUri && loadedUri !== uri && _jsx(Image, { testID: "media-loading-preview", source: { uri: previewUri }, resizeMode: "contain", style: { position: 'absolute', width: '100%', height: '100%' } }), viewport.width > 1 && viewport.height > 1 && _jsx(Image, { testID: "photo-zoom-image", accessibilityLabel: label, source: { uri }, resizeMode: "contain", onLoad: event => { const target = event.nativeEvent.target; const { width, height } = event.nativeEvent.source ?? { width: target?.naturalWidth ?? 0, height: target?.naturalHeight ?? 0 }; if (width > 0 && height > 0) {
115
+ controller.image(width, height);
116
+ setImageSize({ width, height, uri });
117
+ } setLoadedUri(uri); mediaReady('image-loaded', uri); }, onError: () => setError(true), style: { position: 'absolute', width: imageWidth, height: imageHeight, left: (stageWidth - imageWidth) / 2 + transform.x, top: (stageHeight - imageHeight) / 2 + transform.y } })] }) }), error && _jsx(Text, { accessibilityRole: "alert", style: { position: 'absolute', top: '50%', alignSelf: 'center', color: messagingMediaColors(appearance).foreground }, children: uiText("This photo could not be opened.") })] });
118
118
  }
119
- export function MediaViewer({ title, subtitle, kind, uri, fileName, byteSize, children, loading, error, onClose, onFileAction, reviewAction, onReview, onDownload, onShare, onForward, onDelete, showDelete = false, showForward = false, downloading = false, expanded, onExpandedChange, keepControlsVisible = false, status, transferProgress }) {
119
+ export function MediaViewer({ title, subtitle, kind, uri, previewUri, fileName, byteSize, children, loading, error, onClose, onFileAction, reviewAction, onReview, onDownload, onShare, onForward, onDelete, showDelete = false, showForward = false, downloading = false, expanded, onExpandedChange, keepControlsVisible = false, status, transferProgress }) {
120
120
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
121
121
  const appearance = useMessagingAppearance(), c = messagingMediaColors(appearance), actionBackground = appearance?.mediaViewer?.accent ?? '#ffffff';
122
122
  const [localExpanded, setLocalExpanded] = useState(false);
@@ -124,5 +124,5 @@ export function MediaViewer({ title, subtitle, kind, uri, fileName, byteSize, ch
124
124
  const setExpanded = (value) => { setLocalExpanded(value); onExpandedChange?.(value); };
125
125
  useEffect(() => { setLocalExpanded(false); }, [uri]);
126
126
  const visual = kind === 'image' || kind === 'video';
127
- return _jsxs(View, { testID: "messenger-media-viewer", accessibilityViewIsModal: true, style: { flex: 1, minHeight: 0, backgroundColor: appearance?.mediaViewer?.background ?? (controls ? 'rgba(0,0,0,0.94)' : '#000000') }, children: [_jsxs(View, { style: { flex: 1, minHeight: 0, justifyContent: 'center', paddingHorizontal: visual && controls ? 12 : 0 }, children: [controls && _jsxs(View, { testID: "media-action-toolbar", style: { position: 'absolute', top: 12, left: 12, right: 12, zIndex: 3, minHeight: 52, borderRadius: c.radius, borderWidth: 1, borderColor: c.foreground + '1f', backgroundColor: c.controls + 'eb', paddingLeft: 8, paddingRight: 4, flexDirection: 'row', alignItems: 'center', gap: 2 }, children: [[[onDownload, 'Download', 'download-outline', downloading, false], [onDelete, 'Delete', 'trash-outline', false, true], [onForward, 'Forward', 'arrow-redo-outline', false, false], [onShare, 'Share', 'share-social-outline', false, false]].filter(([action, label]) => !!action || label === 'Delete' && showDelete || label === 'Forward' && showForward).map(([action, label, icon, busy, destructive]) => _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("{value1} media", { value1: label }), accessibilityState: { busy }, disabled: !action || busy || downloading || loading, onPress: action, style: { opacity: !action ? .5 : 1, flex: 1, minWidth: 44, minHeight: 44, borderRadius: Math.min(22, c.radius), alignItems: 'center', justifyContent: 'center', gap: 1, paddingHorizontal: 2 }, children: [busy ? _jsx(ActivityIndicator, { size: "small", color: c.accent }) : _jsx(MessageIcon, { name: icon, size: 20, color: !action ? c.foreground + '88' : destructive ? c.danger : c.foreground }), _jsx(Text, { numberOfLines: 1, style: { color: !action ? c.foreground + '88' : destructive ? c.danger : c.foreground, fontSize: 10, fontWeight: '800' }, children: label })] }, label)), _jsx(View, { style: { flex: (!visual || !!reviewAction) && !onDownload && !onDelete && !onForward && !onShare ? 1 : 0, minWidth: 0 }, children: (!visual || !!reviewAction) && !onDownload && !onDelete && !onForward && !onShare && _jsx(Text, { numberOfLines: 1, style: { color: c.foreground, fontSize: 14, paddingLeft: 8 }, children: title }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Close media"), onPress: onClose, style: { width: 44, height: 44, borderRadius: Math.min(22, c.radius), backgroundColor: c.foreground + '14', alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "close", size: 24, color: c.foreground }) })] }), loading ? _jsx(View, { style: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 16 }, children: _jsx(ActivityIndicator, { accessibilityLabel: uiText("Loading attachment"), color: c.foreground }) }) : kind === 'image' && uri ? _jsx(View, { style: { height: controls ? '88%' : '100%', width: '100%' }, children: _jsx(ZoomablePhoto, { uri: uri, label: fileName, expanded: photoExpanded, onTap: () => setExpanded(!photoExpanded) }) }) : kind === 'document' && children ? _jsx(View, { style: { flex: 1, minHeight: 0, paddingTop: 76 }, children: children }) : kind === 'document' ? _jsxs(View, { style: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: 32, gap: 20 }, children: [_jsx(View, { style: { width: 88, height: 106, borderRadius: 16, backgroundColor: c.foreground + '12', alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "document", color: c.foreground, size: 40 }) }), _jsx(Text, { style: { color: c.foreground, fontSize: 19, fontWeight: '600', textAlign: 'center' }, children: fileName }), _jsxs(Text, { style: { color: c.foreground, fontSize: 13 }, children: [fileName?.split('.').pop()?.toUpperCase(), " \u00B7 ", fileSize(byteSize)] })] }) : kind === 'video' ? _jsx(View, { testID: "media-video-stage", style: { height: '72%', width: '100%' }, children: children }) : children] }), !controls && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Close media"), onPress: onClose, style: { position: "absolute", top: 12, right: 12, width: 44, height: 44, borderRadius: Math.min(22, c.radius), backgroundColor: c.controls + 'cc', alignItems: "center", justifyContent: "center" }, children: _jsx(MessageIcon, { name: "close", color: c.foreground, size: 24 }) }), downloading && transferProgress !== undefined && _jsx(View, { accessibilityRole: "progressbar", accessibilityValue: { min: 0, max: 100, now: Math.round(transferProgress * 100) }, style: { height: 3, backgroundColor: c.foreground + '22' }, children: _jsx(View, { style: { height: 3, width: `${Math.round(transferProgress * 100)}%`, backgroundColor: c.accent } }) }), !!status && _jsx(Text, { accessibilityLiveRegion: "polite", style: { color: c.foreground, padding: 12 }, children: status }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, padding: 16 }, children: error }), controls && reviewAction && onReview && _jsx(View, { style: { padding: 16, borderTopWidth: 1, borderTopColor: c.foreground + '15' }, children: _jsx(Pressable, { accessibilityRole: "button", onPress: onReview, style: { minHeight: 48, borderRadius: 24, backgroundColor: actionBackground, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { fontWeight: '600', color: messagingContrastInk(actionBackground) }, children: reviewAction }) }) })] });
127
+ return _jsxs(View, { testID: "messenger-media-viewer", accessibilityViewIsModal: true, style: { flex: 1, minHeight: 0, backgroundColor: appearance?.mediaViewer?.background ?? (controls ? 'rgba(0,0,0,0.94)' : '#000000') }, children: [_jsxs(View, { style: { flex: 1, minHeight: 0, justifyContent: 'center', paddingHorizontal: visual && controls ? 12 : 0 }, children: [controls && _jsxs(View, { testID: "media-action-toolbar", style: { position: 'absolute', top: 12, left: 12, right: 12, zIndex: 3, minHeight: 52, borderRadius: c.radius, borderWidth: 1, borderColor: c.foreground + '1f', backgroundColor: c.controls + 'eb', paddingLeft: 8, paddingRight: 4, flexDirection: 'row', alignItems: 'center', gap: 2 }, children: [[[onDownload, 'Download', 'download-outline', downloading, false], [onDelete, 'Delete', 'trash-outline', false, true], [onForward, 'Forward', 'arrow-redo-outline', false, false], [onShare, 'Share', 'share-social-outline', false, false]].filter(([action, label]) => !!action || label === 'Delete' && showDelete || label === 'Forward' && showForward).map(([action, label, icon, busy, destructive]) => _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("{value1} media", { value1: label }), accessibilityState: { busy }, disabled: !action || busy || downloading || loading, onPress: action, style: { opacity: !action ? .5 : 1, flex: 1, minWidth: 44, minHeight: 44, borderRadius: Math.min(22, c.radius), alignItems: 'center', justifyContent: 'center', gap: 1, paddingHorizontal: 2 }, children: [busy ? _jsx(ActivityIndicator, { size: "small", color: c.accent }) : _jsx(MessageIcon, { name: icon, size: 20, color: !action ? c.foreground + '88' : destructive ? c.danger : c.foreground }), _jsx(Text, { numberOfLines: 1, style: { color: !action ? c.foreground + '88' : destructive ? c.danger : c.foreground, fontSize: 10, fontWeight: '800' }, children: label })] }, label)), _jsx(View, { style: { flex: (!visual || !!reviewAction) && !onDownload && !onDelete && !onForward && !onShare ? 1 : 0, minWidth: 0 }, children: (!visual || !!reviewAction) && !onDownload && !onDelete && !onForward && !onShare && _jsx(Text, { numberOfLines: 1, style: { color: c.foreground, fontSize: 14, paddingLeft: 8 }, children: title }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Close media"), onPress: onClose, style: { width: 44, height: 44, borderRadius: Math.min(22, c.radius), backgroundColor: c.foreground + '14', alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "close", size: 24, color: c.foreground }) })] }), loading ? _jsxs(View, { style: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 16 }, children: [visual && previewUri && _jsx(Image, { testID: "media-loading-preview", source: { uri: previewUri }, resizeMode: "contain", style: { position: 'absolute', width: '100%', height: '88%' } }), _jsx(ActivityIndicator, { accessibilityLabel: uiText("Loading attachment"), color: c.foreground })] }) : kind === 'image' && uri ? _jsx(View, { style: { height: controls ? '88%' : '100%', width: '100%' }, children: _jsx(ZoomablePhoto, { uri: uri, previewUri: previewUri, label: fileName, expanded: photoExpanded, onTap: () => setExpanded(!photoExpanded) }) }) : kind === 'document' && children ? _jsx(View, { style: { flex: 1, minHeight: 0, paddingTop: 76 }, children: children }) : kind === 'document' ? _jsxs(View, { style: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: 32, gap: 20 }, children: [_jsx(View, { style: { width: 88, height: 106, borderRadius: 16, backgroundColor: c.foreground + '12', alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "document", color: c.foreground, size: 40 }) }), _jsx(Text, { style: { color: c.foreground, fontSize: 19, fontWeight: '600', textAlign: 'center' }, children: fileName }), _jsxs(Text, { style: { color: c.foreground, fontSize: 13 }, children: [fileName?.split('.').pop()?.toUpperCase(), " \u00B7 ", fileSize(byteSize)] })] }) : kind === 'video' ? _jsx(View, { testID: "media-video-stage", style: { height: '72%', width: '100%' }, children: children }) : children] }), downloading && transferProgress !== undefined && _jsx(View, { accessibilityRole: "progressbar", accessibilityValue: { min: 0, max: 100, now: Math.round(transferProgress * 100) }, style: { height: 3, backgroundColor: c.foreground + '22' }, children: _jsx(View, { style: { height: 3, width: `${Math.round(transferProgress * 100)}%`, backgroundColor: c.accent } }) }), !!status && _jsx(Text, { accessibilityLiveRegion: "polite", style: { color: c.foreground, padding: 12 }, children: status }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, padding: 16 }, children: error }), controls && reviewAction && onReview && _jsx(View, { style: { padding: 16, borderTopWidth: 1, borderTopColor: c.foreground + '15' }, children: _jsx(Pressable, { accessibilityRole: "button", onPress: onReview, style: { minHeight: 48, borderRadius: 24, backgroundColor: actionBackground, alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { style: { fontWeight: '600', color: messagingContrastInk(actionBackground) }, children: reviewAction }) }) })] });
128
128
  }
@@ -17,6 +17,7 @@ export declare class MessagingPreviewCache {
17
17
  timeoutMs: number;
18
18
  }, now?: () => number);
19
19
  get(key: string, load: (signal: AbortSignal) => Promise<Preview>): Promise<Preview>;
20
+ peek(key: string): Preview | undefined;
20
21
  invalidate(key: string): void;
21
22
  clear(): void;
22
23
  private drop;
@@ -29,6 +29,7 @@ export class MessagingPreviewCache {
29
29
  this.pump();
30
30
  return promise;
31
31
  }
32
+ peek(key) { const entry = this.entries.get(key); return entry && !entry.abort.signal.aborted && entry.expires > this.now() ? entry.value : undefined; }
32
33
  invalidate(key) { const entry = this.entries.get(key); if (entry)
33
34
  this.drop(entry); }
34
35
  clear() { for (const entry of this.entries.values())
@@ -51,6 +52,7 @@ export class MessagingPreviewCache {
51
52
  void Promise.race([Promise.resolve().then(() => entry.abort.signal.aborted ? {} : entry.load(entry.abort.signal)), cancelled]).then(value => {
52
53
  if (entry.abort.signal.aborted || this.entries.get(entry.key) !== entry)
53
54
  return;
55
+ entry.value = value;
54
56
  entry.expires = this.now() + this.options.ttlMs;
55
57
  entry.resolve(value);
56
58
  if (!value.uri && !value.waveform)
@@ -1,11 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { messengerRecordingWaveform } from './voice-waveform.js';
2
3
  import { Text } from './typography.js';
3
4
  import { useRobonoLocale } from './localization.js';
4
5
  import { ActivityIndicator, Pressable, View } from 'react-native';
5
6
  import { MessageIcon, duration, composerSurface } from './icons.js';
6
7
  function Waveform({ samples = [], color }) {
7
8
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
8
- return _jsx(View, { accessibilityLabel: uiText("Recording waveform"), style: { flex: 1, minWidth: 0, height: 24, flexDirection: 'row', alignItems: 'center', gap: 2, overflow: 'hidden' }, children: Array.from({ length: 28 }, (_, i) => { const value = samples[Math.floor(i * samples.length / 28)] ?? 0; return _jsx(View, { style: { flex: 1, borderRadius: 2, height: 3 + Math.max(0, Math.min(1, value)) * 21, backgroundColor: color, opacity: samples.length ? .8 : .25 } }, i); }) });
9
+ return _jsx(View, { accessibilityLabel: uiText("Recording waveform"), style: { flex: 1, minWidth: 0, height: 28, flexDirection: 'row', alignItems: 'center', gap: 2, overflow: 'hidden' }, children: messengerRecordingWaveform(samples).map((value, i) => _jsx(View, { testID: "recording-waveform-bar", style: { flex: 1, minWidth: 2, borderRadius: 2, height: 2 + value * 24, backgroundColor: color, opacity: samples.length ? 1 : .25 } }, i)) });
9
10
  }
10
11
  /** Messenger's inline recorder; adapters supply media state and the optional text composer. */
11
12
  export function VoiceMessageComposer({ appearance, maxSeconds, busy, onRecord, actions, phase = 'idle', elapsedMs = 0, waveform, error, review, onStop, onSend, onRemove, renderTextComposer, renderAttachments }) {
@@ -1,2 +1,4 @@
1
1
  /** Messenger playback display normalization; never changes the stored recording. */
2
2
  export declare function messengerVoiceWaveform(value: number[] | undefined, durationMs: number): number[];
3
+ /** Original Messenger's live meter emphasis, for display only. Silence stays flat. */
4
+ export declare function messengerRecordingWaveform(samples?: number[]): number[];
@@ -19,3 +19,12 @@ export function messengerVoiceWaveform(value, durationMs) {
19
19
  const factor = Math.max(.75, Math.min((durationMs || 2200) / 2800, 1.35));
20
20
  return Array.from({ length: count }, (_, i) => Math.max(.08, Math.min(.9, Math.sin(Math.PI * i / (count - 1)) * (.38 + .34 * Math.sin((i + 1) * 1.73 * factor) + .18 * Math.sin((i + 3) * .67)))));
21
21
  }
22
+ /** Original Messenger's live meter emphasis, for display only. Silence stays flat. */
23
+ export function messengerRecordingWaveform(samples = []) {
24
+ const levels = samples.slice(-56), count = 28;
25
+ return Array.from({ length: count }, (_, i) => {
26
+ const start = Math.floor(i * levels.length / count), end = Math.max(start + 1, Math.floor((i + 1) * levels.length / count));
27
+ const value = Math.max(0, ...levels.slice(start, end).filter(Number.isFinite));
28
+ return value <= .001 ? 0 : Math.max(.04, Math.min(1, Math.pow(value, .46) * 1.35));
29
+ });
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robono/messaging-react-native",
3
- "version": "0.20.3",
3
+ "version": "0.21.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Optional, composable direct and group messaging screens for Robono.",
@@ -82,7 +82,7 @@
82
82
  "expo-constants": ">=55 <57",
83
83
  "@robono/location": "^0.4.1",
84
84
  "expo-haptics": ">=55 <57",
85
- "@robono/calling": "^0.6.2",
85
+ "@robono/calling": "^0.6.3",
86
86
  "expo-media-library": ">=55 <57"
87
87
  },
88
88
  "license": "SEE LICENSE IN LICENSE",