react-native-acoustic-connect-beta 18.0.14 → 18.0.16

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.
Files changed (97) hide show
  1. package/Examples/SampleUI/.detoxrc.js +83 -0
  2. package/Examples/SampleUI/ConnectConfig.json +2 -2
  3. package/Examples/SampleUI/android/app/build.gradle +3 -0
  4. package/Examples/SampleUI/android/app/src/main/java/com/sampleui/MainActivity.kt +0 -35
  5. package/Examples/SampleUI/android/settings.gradle +1 -1
  6. package/Examples/SampleUI/package.json +8 -6
  7. package/Examples/SampleUI/scripts/integration-test-android.sh +292 -0
  8. package/Examples/SampleUI/src/Examples/DialogExample.tsx +88 -2
  9. package/Examples/SampleUI/src/Examples/Dialogs/DialogTrackingTest.tsx +307 -0
  10. package/Examples/SampleUI/src/Examples/Dialogs/index.tsx +37 -0
  11. package/Examples/SampleUI/src/index.native.tsx +4 -5
  12. package/android/build.gradle +2 -2
  13. package/android/src/main/assets/ConnectAdvancedConfig.json +1 -1
  14. package/android/src/main/java/com/acousticconnectrn/HybridAcousticConnectRN.kt +787 -490
  15. package/ios/HybridAcousticConnectRN.swift +75 -0
  16. package/lib/commonjs/TLTRN.js +69 -0
  17. package/lib/commonjs/TLTRN.js.map +1 -1
  18. package/lib/commonjs/components/Connect.js +5 -1
  19. package/lib/commonjs/components/Connect.js.map +1 -1
  20. package/lib/commonjs/docs/DialogTracking.md +252 -0
  21. package/lib/commonjs/docs/NativeImplementation.md +176 -0
  22. package/lib/commonjs/examples/DialogTrackingExample.js +175 -0
  23. package/lib/commonjs/examples/DialogTrackingExample.js.map +1 -0
  24. package/lib/commonjs/examples/HOCDialogExample.js +296 -0
  25. package/lib/commonjs/examples/HOCDialogExample.js.map +1 -0
  26. package/lib/commonjs/index.js +28 -0
  27. package/lib/commonjs/index.js.map +1 -1
  28. package/lib/commonjs/utils/DialogDebugger.js +216 -0
  29. package/lib/commonjs/utils/DialogDebugger.js.map +1 -0
  30. package/lib/commonjs/utils/DialogListener.js +203 -0
  31. package/lib/commonjs/utils/DialogListener.js.map +1 -0
  32. package/lib/commonjs/utils/useDialogTracking.js +107 -0
  33. package/lib/commonjs/utils/useDialogTracking.js.map +1 -0
  34. package/lib/commonjs/utils/withAcousticAutoDialog.js +282 -0
  35. package/lib/commonjs/utils/withAcousticAutoDialog.js.map +1 -0
  36. package/lib/module/TLTRN.js +69 -0
  37. package/lib/module/TLTRN.js.map +1 -1
  38. package/lib/module/components/Connect.js +5 -1
  39. package/lib/module/components/Connect.js.map +1 -1
  40. package/lib/module/docs/DialogTracking.md +252 -0
  41. package/lib/module/docs/NativeImplementation.md +176 -0
  42. package/lib/module/examples/DialogTrackingExample.js +172 -0
  43. package/lib/module/examples/DialogTrackingExample.js.map +1 -0
  44. package/lib/module/examples/HOCDialogExample.js +292 -0
  45. package/lib/module/examples/HOCDialogExample.js.map +1 -0
  46. package/lib/module/index.js +5 -1
  47. package/lib/module/index.js.map +1 -1
  48. package/lib/module/utils/DialogDebugger.js +211 -0
  49. package/lib/module/utils/DialogDebugger.js.map +1 -0
  50. package/lib/module/utils/DialogListener.js +199 -0
  51. package/lib/module/utils/DialogListener.js.map +1 -0
  52. package/lib/module/utils/useDialogTracking.js +102 -0
  53. package/lib/module/utils/useDialogTracking.js.map +1 -0
  54. package/lib/module/utils/withAcousticAutoDialog.js +275 -0
  55. package/lib/module/utils/withAcousticAutoDialog.js.map +1 -0
  56. package/lib/typescript/src/TLTRN.d.ts +7 -0
  57. package/lib/typescript/src/TLTRN.d.ts.map +1 -1
  58. package/lib/typescript/src/components/Connect.d.ts +1 -0
  59. package/lib/typescript/src/components/Connect.d.ts.map +1 -1
  60. package/lib/typescript/src/examples/DialogTrackingExample.d.ts +17 -0
  61. package/lib/typescript/src/examples/DialogTrackingExample.d.ts.map +1 -0
  62. package/lib/typescript/src/examples/HOCDialogExample.d.ts +21 -0
  63. package/lib/typescript/src/examples/HOCDialogExample.d.ts.map +1 -0
  64. package/lib/typescript/src/index.d.ts +5 -1
  65. package/lib/typescript/src/index.d.ts.map +1 -1
  66. package/lib/typescript/src/specs/react-native-acoustic-connect.nitro.d.ts +4 -0
  67. package/lib/typescript/src/specs/react-native-acoustic-connect.nitro.d.ts.map +1 -1
  68. package/lib/typescript/src/utils/DialogDebugger.d.ts +58 -0
  69. package/lib/typescript/src/utils/DialogDebugger.d.ts.map +1 -0
  70. package/lib/typescript/src/utils/DialogListener.d.ts +85 -0
  71. package/lib/typescript/src/utils/DialogListener.d.ts.map +1 -0
  72. package/lib/typescript/src/utils/useDialogTracking.d.ts +25 -0
  73. package/lib/typescript/src/utils/useDialogTracking.d.ts.map +1 -0
  74. package/lib/typescript/src/utils/withAcousticAutoDialog.d.ts +37 -0
  75. package/lib/typescript/src/utils/withAcousticAutoDialog.d.ts.map +1 -0
  76. package/nitrogen/generated/android/c++/JHybridAcousticConnectRNSpec.cpp +26 -0
  77. package/nitrogen/generated/android/c++/JHybridAcousticConnectRNSpec.hpp +4 -0
  78. package/nitrogen/generated/android/kotlin/com/margelo/nitro/acousticconnectrn/HybridAcousticConnectRNSpec.kt +16 -0
  79. package/nitrogen/generated/ios/c++/HybridAcousticConnectRNSpecSwift.hpp +32 -0
  80. package/nitrogen/generated/ios/swift/HybridAcousticConnectRNSpec.swift +4 -0
  81. package/nitrogen/generated/ios/swift/HybridAcousticConnectRNSpec_cxx.swift +71 -0
  82. package/nitrogen/generated/shared/c++/HybridAcousticConnectRNSpec.cpp +4 -0
  83. package/nitrogen/generated/shared/c++/HybridAcousticConnectRNSpec.hpp +4 -0
  84. package/package.json +1 -1
  85. package/scripts/ConnectConfig.json +1 -1
  86. package/src/TLTRN.ts +75 -0
  87. package/src/components/Connect.tsx +6 -1
  88. package/src/docs/DialogTracking.md +252 -0
  89. package/src/docs/NativeImplementation.md +176 -0
  90. package/src/examples/DialogTrackingExample.tsx +163 -0
  91. package/src/examples/HOCDialogExample.tsx +253 -0
  92. package/src/index.ts +5 -1
  93. package/src/specs/react-native-acoustic-connect.nitro.ts +5 -0
  94. package/src/utils/DialogDebugger.ts +224 -0
  95. package/src/utils/DialogListener.ts +238 -0
  96. package/src/utils/useDialogTracking.ts +102 -0
  97. package/src/utils/withAcousticAutoDialog.tsx +312 -0
@@ -0,0 +1,238 @@
1
+ /********************************************************************************************
2
+ * Copyright (C) 2025 Acoustic, L.P. All rights reserved.
3
+ *
4
+ * NOTICE: This file contains material that is confidential and proprietary to
5
+ * Acoustic, L.P. and/or other developers. No license is granted under any intellectual or
6
+ * industrial property rights of Acoustic, L.P. except as may be provided in an agreement with
7
+ * Acoustic, L.P. Any unauthorized copying or distribution of content from this file is
8
+ * prohibited.
9
+ ********************************************************************************************/
10
+
11
+ import { Alert, Platform } from 'react-native';
12
+ import type { AlertButton, AlertOptions } from 'react-native';
13
+
14
+ export interface DialogEvent {
15
+ dialogId: string;
16
+ dialogTitle: string;
17
+ dialogType: 'alert' | 'custom' | 'modal';
18
+ timestamp: number;
19
+ buttons?: AlertButton[];
20
+ }
21
+
22
+ export interface DialogButtonClickEvent {
23
+ dialogId: string;
24
+ buttonText: string;
25
+ buttonIndex: number;
26
+ timestamp: number;
27
+ }
28
+
29
+ export interface DialogDismissEvent {
30
+ dialogId: string;
31
+ dialogTitle: string;
32
+ dialogType: 'alert' | 'custom' | 'modal';
33
+ dismissReason: string;
34
+ timestamp: number;
35
+ }
36
+
37
+ // Simple ID generator
38
+ function generateId(): string {
39
+ return Math.random().toString(36).substr(2, 9) + Date.now().toString(36);
40
+ }
41
+
42
+ class DialogListener {
43
+ private static instance: DialogListener;
44
+ private activeDialogs: Map<string, DialogEvent> = new Map();
45
+ private originalAlert: typeof Alert.alert;
46
+ private isIntercepting: boolean = false;
47
+ private eventCallbacks: Array<(event: DialogEvent | DialogButtonClickEvent | DialogDismissEvent) => void> = [];
48
+
49
+ private constructor() {
50
+ this.originalAlert = Alert.alert;
51
+ this.interceptAlertAPI();
52
+ }
53
+
54
+ static getInstance(): DialogListener {
55
+ if (!DialogListener.instance) {
56
+ DialogListener.instance = new DialogListener();
57
+ }
58
+ return DialogListener.instance;
59
+ }
60
+
61
+ /**
62
+ * Start intercepting dialog events
63
+ */
64
+ startIntercepting(): void {
65
+ if (this.isIntercepting) return;
66
+ this.isIntercepting = true;
67
+ console.log('DialogListener: Started intercepting dialog events');
68
+ }
69
+
70
+ /**
71
+ * Stop intercepting dialog events
72
+ */
73
+ stopIntercepting(): void {
74
+ if (!this.isIntercepting) return;
75
+ this.isIntercepting = false;
76
+ console.log('DialogListener: Stopped intercepting dialog events');
77
+ }
78
+
79
+ /**
80
+ * Add event callback for dialog events
81
+ */
82
+ addEventListener(callback: (event: DialogEvent | DialogButtonClickEvent | DialogDismissEvent) => void): () => void {
83
+ this.eventCallbacks.push(callback);
84
+ return () => {
85
+ const index = this.eventCallbacks.indexOf(callback);
86
+ if (index > -1) {
87
+ this.eventCallbacks.splice(index, 1);
88
+ }
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Intercept React Native's Alert.alert API
94
+ */
95
+ private interceptAlertAPI(): void {
96
+ const self = this;
97
+ Alert.alert = function(
98
+ title: string,
99
+ message?: string,
100
+ buttons?: AlertButton[],
101
+ options?: AlertOptions
102
+ ): void {
103
+ if (self.isIntercepting) {
104
+ const dialogId = generateId();
105
+ const dialogEvent: DialogEvent = {
106
+ dialogId,
107
+ dialogTitle: title,
108
+ dialogType: 'alert',
109
+ timestamp: Date.now(),
110
+ buttons: buttons || []
111
+ };
112
+
113
+ self.activeDialogs.set(dialogId, dialogEvent);
114
+ self.emitEvent(dialogEvent);
115
+
116
+ // Create wrapped buttons that log events
117
+ const wrappedButtons = buttons?.map((button, index) => ({
118
+ ...button,
119
+ onPress: () => {
120
+ const buttonClickEvent: DialogButtonClickEvent = {
121
+ dialogId,
122
+ buttonText: button.text || '',
123
+ buttonIndex: index,
124
+ timestamp: Date.now()
125
+ };
126
+ self.emitEvent(buttonClickEvent);
127
+ self.activeDialogs.delete(dialogId);
128
+
129
+ // Call original onPress if it exists
130
+ if (button.onPress) {
131
+ button.onPress();
132
+ }
133
+ }
134
+ }));
135
+
136
+ // Call original Alert.alert with wrapped buttons
137
+ self.originalAlert.call(Alert, title, message, wrappedButtons, options);
138
+ } else {
139
+ // Call original Alert.alert without interception
140
+ self.originalAlert.call(Alert, title, message, buttons, options);
141
+ }
142
+ };
143
+ }
144
+
145
+ /**
146
+ * Manually track custom dialog show event
147
+ */
148
+ trackCustomDialogShow(dialogId: string, title: string, buttons?: AlertButton[]): void {
149
+ if (!this.isIntercepting) return;
150
+
151
+ const dialogEvent: DialogEvent = {
152
+ dialogId,
153
+ dialogTitle: title,
154
+ dialogType: 'custom',
155
+ timestamp: Date.now(),
156
+ buttons: buttons || []
157
+ };
158
+
159
+ this.activeDialogs.set(dialogId, dialogEvent);
160
+ this.emitEvent(dialogEvent);
161
+ }
162
+
163
+ /**
164
+ * Manually track custom dialog dismiss event
165
+ */
166
+ trackCustomDialogDismiss(dialogId: string, reason: string = 'manual'): void {
167
+ if (!this.isIntercepting) return;
168
+
169
+ const dialogEvent = this.activeDialogs.get(dialogId);
170
+ if (dialogEvent) {
171
+ this.activeDialogs.delete(dialogId);
172
+ // Emit proper dismiss event
173
+ const dismissEvent: DialogDismissEvent = {
174
+ dialogId,
175
+ dialogTitle: dialogEvent.dialogTitle,
176
+ dialogType: dialogEvent.dialogType,
177
+ dismissReason: reason,
178
+ timestamp: Date.now()
179
+ };
180
+ this.emitEvent(dismissEvent);
181
+
182
+ // Log the dismiss reason for debugging
183
+ console.log(`Dialog ${dialogId} dismissed with reason: ${reason}`);
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Manually track custom dialog button click event
189
+ */
190
+ trackCustomDialogButtonClick(dialogId: string, buttonText: string, buttonIndex: number): void {
191
+ if (!this.isIntercepting) return;
192
+
193
+ const buttonClickEvent: DialogButtonClickEvent = {
194
+ dialogId,
195
+ buttonText,
196
+ buttonIndex,
197
+ timestamp: Date.now()
198
+ };
199
+
200
+ this.emitEvent(buttonClickEvent);
201
+ }
202
+
203
+ /**
204
+ * Get currently active dialogs
205
+ */
206
+ getActiveDialogs(): DialogEvent[] {
207
+ return Array.from(this.activeDialogs.values());
208
+ }
209
+
210
+ /**
211
+ * Clear all active dialogs
212
+ */
213
+ clearActiveDialogs(): void {
214
+ this.activeDialogs.clear();
215
+ }
216
+
217
+ /**
218
+ * Emit event to all registered callbacks
219
+ */
220
+ private emitEvent(event: DialogEvent | DialogButtonClickEvent | DialogDismissEvent): void {
221
+ this.eventCallbacks.forEach(callback => {
222
+ try {
223
+ callback(event);
224
+ } catch (error) {
225
+ console.error('DialogListener: Error in event callback:', error);
226
+ }
227
+ });
228
+ }
229
+
230
+ /**
231
+ * Restore original Alert.alert API
232
+ */
233
+ restoreOriginalAlert(): void {
234
+ Alert.alert = this.originalAlert;
235
+ }
236
+ }
237
+
238
+ export default DialogListener;
@@ -0,0 +1,102 @@
1
+ /********************************************************************************************
2
+ * Copyright (C) 2025 Acoustic, L.P. All rights reserved.
3
+ *
4
+ * NOTICE: This file contains material that is confidential and proprietary to
5
+ * Acoustic, L.P. and/or other developers. No license is granted under any intellectual or
6
+ * industrial property rights of Acoustic, L.P. except as may be provided in an agreement with
7
+ * Acoustic, L.P. Any unauthorized copying or distribution of content from this file is
8
+ * prohibited.
9
+ ********************************************************************************************/
10
+
11
+ import { useCallback, useRef } from 'react';
12
+ import type { AlertButton } from 'react-native';
13
+ import DialogListener from './DialogListener';
14
+ import TLTRN from '../TLTRN';
15
+
16
+ /**
17
+ * React hook for tracking custom dialog events
18
+ * Provides utilities to track dialog show, dismiss, and button click events
19
+ */
20
+ export const useDialogTracking = () => {
21
+ const dialogIds = useRef<Set<string>>(new Set());
22
+
23
+ /**
24
+ * Generate a unique dialog ID
25
+ */
26
+ const generateDialogId = useCallback((): string => {
27
+ const id = Math.random().toString(36).substr(2, 9) + Date.now().toString(36);
28
+ dialogIds.current.add(id);
29
+ return id;
30
+ }, []);
31
+
32
+ /**
33
+ * Track a custom dialog show event
34
+ */
35
+ const trackDialogShow = useCallback((dialogId: string, title: string, buttons?: AlertButton[]) => {
36
+ DialogListener.getInstance().trackCustomDialogShow(dialogId, title, buttons);
37
+ // Note: The actual native call is handled by the DialogListener event system
38
+ // No need to call TLTRN.logDialogShowEvent directly here
39
+ }, []);
40
+
41
+ /**
42
+ * Track a custom dialog dismiss event
43
+ */
44
+ const trackDialogDismiss = useCallback((dialogId: string, reason: string = 'manual') => {
45
+ DialogListener.getInstance().trackCustomDialogDismiss(dialogId, reason);
46
+ // Note: The actual native call is handled by the DialogListener event system
47
+ // No need to call TLTRN.logDialogDismissEvent directly here
48
+ }, []);
49
+
50
+ /**
51
+ * Track a custom dialog button click event
52
+ */
53
+ const trackDialogButtonClick = useCallback((dialogId: string, buttonText: string, buttonIndex: number) => {
54
+ DialogListener.getInstance().trackCustomDialogButtonClick(dialogId, buttonText, buttonIndex);
55
+ // Note: The actual native call is handled by the DialogListener event system
56
+ // No need to call TLTRN.logDialogButtonClickEvent directly here
57
+ }, []);
58
+
59
+ /**
60
+ * Track a custom dialog event
61
+ */
62
+ const trackDialogCustomEvent = useCallback((dialogId: string, eventName: string, values: Record<string, string | number | boolean>) => {
63
+ TLTRN.logDialogCustomEvent(dialogId, eventName, values);
64
+ }, []);
65
+
66
+ /**
67
+ * Create a wrapped button with automatic tracking
68
+ */
69
+ const createTrackedButton = useCallback((dialogId: string, button: AlertButton, buttonIndex: number): AlertButton => {
70
+ return {
71
+ ...button,
72
+ onPress: () => {
73
+ // Track the button click
74
+ trackDialogButtonClick(dialogId, button.text || '', buttonIndex);
75
+
76
+ // Call the original onPress if it exists
77
+ if (button.onPress) {
78
+ button.onPress();
79
+ }
80
+ }
81
+ };
82
+ }, [trackDialogButtonClick]);
83
+
84
+ /**
85
+ * Clean up dialog tracking
86
+ */
87
+ const cleanup = useCallback(() => {
88
+ dialogIds.current.clear();
89
+ }, []);
90
+
91
+ return {
92
+ generateDialogId,
93
+ trackDialogShow,
94
+ trackDialogDismiss,
95
+ trackDialogButtonClick,
96
+ trackDialogCustomEvent,
97
+ createTrackedButton,
98
+ cleanup
99
+ };
100
+ };
101
+
102
+ export default useDialogTracking;
@@ -0,0 +1,312 @@
1
+ /********************************************************************************************
2
+ * Copyright (C) 2025 Acoustic, L.P. All rights reserved.
3
+ *
4
+ * NOTICE: This file contains material that is confidential and proprietary to
5
+ * Acoustic, L.P. and/or other developers. No license is granted under any intellectual or
6
+ * industrial property rights of Acoustic, L.P. except as may be provided in an agreement with
7
+ * Acoustic, L.P. Any unauthorized copying or distribution of content from this file is
8
+ * prohibited.
9
+ *
10
+ * Created by Omar Hernandez on 5/9/25.
11
+ *
12
+ ********************************************************************************************/
13
+
14
+ import React, { forwardRef, useImperativeHandle, useRef, useEffect, useCallback } from 'react';
15
+ import { Alert } from 'react-native';
16
+ import { useDialogTracking } from './useDialogTracking';
17
+ import AcousticConnectRN from '../index';
18
+
19
+ /**
20
+ * HOC Wrapper that automatically tracks dialog show/dismiss events and button clicks
21
+ * Works with any dialog component that has 'visible' and 'onDismiss' props
22
+ *
23
+ * Supported Dialog Patterns:
24
+ * - react-native-paper Dialog components
25
+ * - Custom modal components with visible/onDismiss props
26
+ * - Components with different prop names (show/hide, open/close, etc.)
27
+ * - Components with custom button implementations
28
+ * - Components with nested dialog structures
29
+ */
30
+ export function withAcousticAutoDialog(
31
+ DialogComponent: React.ComponentType<any>
32
+ ): React.ComponentType<any> {
33
+ return forwardRef<any, any>((props, ref) => {
34
+ const { generateDialogId } = useDialogTracking();
35
+ const dialogIdRef = useRef<string | null>(null);
36
+ const isVisibleRef = useRef(false);
37
+
38
+ // Track button click event
39
+ const trackButtonClick = useCallback((buttonText: string, buttonIndex: number) => {
40
+ if (dialogIdRef.current) {
41
+ AcousticConnectRN.logDialogButtonClickEvent(dialogIdRef.current, buttonText, buttonIndex);
42
+ console.log(`🔍 withAcousticAutoDialog: Button clicked - ${buttonText} (${dialogIdRef.current})`);
43
+ }
44
+ }, []);
45
+
46
+ // Wrap button onPress handlers to track clicks
47
+ const wrapButtonOnPress = useCallback((originalOnPress: (() => void) | undefined, buttonText: string, buttonIndex: number) => {
48
+ return () => {
49
+ trackButtonClick(buttonText, buttonIndex);
50
+ if (originalOnPress) {
51
+ originalOnPress();
52
+ }
53
+ };
54
+ }, [trackButtonClick]);
55
+
56
+ // Recursively wrap buttons in children
57
+ const wrapButtonsInChildren = useCallback((children: any, buttonIndex: number = 0): any => {
58
+ if (!children) return children;
59
+
60
+ if (Array.isArray(children)) {
61
+ return children.map((child, index) => wrapButtonsInChildren(child, buttonIndex + index));
62
+ }
63
+
64
+ if (React.isValidElement(children)) {
65
+ const childProps = children.props as any;
66
+
67
+ // Check if this is a button component (supports various button types)
68
+ const isButton =
69
+ (typeof children.type === 'function' &&
70
+ ((children.type as any).displayName === 'Button' ||
71
+ (children.type as any).name === 'Button' ||
72
+ (children.type as any).displayName === 'DialogAction' ||
73
+ (children.type as any).name === 'DialogAction' ||
74
+ (children.type as any).displayName === 'TouchableOpacity' ||
75
+ (children.type as any).name === 'TouchableOpacity' ||
76
+ (children.type as any).displayName === 'Pressable' ||
77
+ (children.type as any).name === 'Pressable')) ||
78
+ (childProps && (childProps.onPress || childProps.onPressIn || childProps.onPressOut || childProps.onTouchEnd));
79
+
80
+ if (isButton && childProps?.onPress) {
81
+ const buttonText = childProps.children || childProps.title || 'Button';
82
+ return React.cloneElement(children, {
83
+ ...childProps,
84
+ onPress: wrapButtonOnPress(childProps.onPress, buttonText, buttonIndex)
85
+ } as any);
86
+ }
87
+
88
+ // Recursively wrap buttons in nested children
89
+ if (childProps?.children) {
90
+ return React.cloneElement(children, {
91
+ ...childProps,
92
+ children: wrapButtonsInChildren(childProps.children, buttonIndex)
93
+ } as any);
94
+ }
95
+ }
96
+
97
+ return children;
98
+ }, [wrapButtonOnPress]);
99
+
100
+ // Track dialog show event when visible changes to true
101
+ // Supports various visibility prop names: visible, show, open, isOpen, isVisible
102
+ const isVisible = props.visible || props.show || props.open || props.isOpen || props.isVisible;
103
+
104
+ useEffect(() => {
105
+ if (isVisible && !isVisibleRef.current) {
106
+ const dialogId = generateDialogId();
107
+ dialogIdRef.current = dialogId;
108
+ isVisibleRef.current = true;
109
+
110
+ // Get dialog title from various possible sources
111
+ const getDialogTitle = (): string => {
112
+ // Try to get title from props (supports various prop names)
113
+ if (props.title) return props.title;
114
+ if (props.dialogTitle) return props.dialogTitle;
115
+ if (props.header) return props.header;
116
+ if (props.heading) return props.heading;
117
+ if (props.name) return props.name;
118
+
119
+ // Try to get title from children (for react-native-paper Dialog)
120
+ if (props.children) {
121
+ console.log(`🔍 withAcousticAutoDialog: Starting title extraction from children`);
122
+ console.log(`🔍 withAcousticAutoDialog: Initial children:`, props.children);
123
+
124
+ const extractTitleFromChildren = (children: any, depth: number = 0): string | null => {
125
+ if (!children) return null;
126
+
127
+ if (Array.isArray(children)) {
128
+ for (const child of children) {
129
+ const title = extractTitleFromChildren(child, depth + 1);
130
+ if (title) return title;
131
+ }
132
+ return null;
133
+ }
134
+
135
+ if (React.isValidElement(children)) {
136
+ const childProps = children.props as any;
137
+
138
+ // Debug: Log component info for debugging
139
+ console.log(`🔍 withAcousticAutoDialog: Processing component at depth ${depth}:`, {
140
+ type: children.type,
141
+ displayName: (children.type as any)?.displayName,
142
+ name: (children.type as any)?.name,
143
+ hasChildren: !!childProps?.children,
144
+ childrenType: typeof childProps?.children
145
+ });
146
+
147
+ // Check if this is a Dialog component from react-native-paper
148
+ if (children.type &&
149
+ typeof children.type === 'function' &&
150
+ ((children.type as any).displayName === 'Dialog' ||
151
+ (children.type as any).name === 'Dialog')) {
152
+ console.log(`🔍 withAcousticAutoDialog: Found Dialog component at depth ${depth}`);
153
+ // Extract title from Dialog children
154
+ if (childProps?.children) {
155
+ return extractTitleFromChildren(childProps.children, depth + 1);
156
+ }
157
+ }
158
+
159
+ // Check if this is a Portal component (common wrapper for dialogs)
160
+ if (children.type &&
161
+ typeof children.type === 'function' &&
162
+ ((children.type as any).displayName === 'Portal' ||
163
+ (children.type as any).name === 'Portal')) {
164
+ console.log(`🔍 withAcousticAutoDialog: Found Portal component at depth ${depth}`);
165
+ // Extract title from Portal children
166
+ if (childProps?.children) {
167
+ return extractTitleFromChildren(childProps.children, depth + 1);
168
+ }
169
+ }
170
+
171
+ // Check if this is a DialogTitle component (supports various title component types)
172
+ if (children.type &&
173
+ typeof children.type === 'function' &&
174
+ ((children.type as any).displayName === 'DialogTitle' ||
175
+ (children.type as any).name === 'DialogTitle' ||
176
+ (children.type as any).displayName === 'Title' ||
177
+ (children.type as any).name === 'Title' ||
178
+ (children.type as any).displayName === 'Header' ||
179
+ (children.type as any).name === 'Header' ||
180
+ (children.type as any).displayName === 'Heading' ||
181
+ (children.type as any).name === 'Heading')) {
182
+ if (childProps?.children && typeof childProps.children === 'string') {
183
+ console.log(`🔍 withAcousticAutoDialog: Found title in title component: "${childProps.children}"`);
184
+ return childProps.children;
185
+ }
186
+ }
187
+
188
+ // Check if this component has title content
189
+ if (childProps?.title) {
190
+ return childProps.title;
191
+ }
192
+
193
+ // Recursively search in nested children
194
+ if (childProps?.children) {
195
+ return extractTitleFromChildren(childProps.children, depth + 1);
196
+ }
197
+ }
198
+
199
+ return null;
200
+ };
201
+
202
+ const title = extractTitleFromChildren(props.children);
203
+ if (title) {
204
+ console.log(`🔍 withAcousticAutoDialog: Found title from children: "${title}"`);
205
+ return title;
206
+ }
207
+ }
208
+
209
+ return 'Dialog';
210
+ };
211
+
212
+ const title = getDialogTitle();
213
+
214
+ // Log dialog show event
215
+ AcousticConnectRN.logDialogShowEvent(dialogId, title, 'custom');
216
+ console.log(`🔍 withAcousticAutoDialog: Dialog shown - ${title} (${dialogId})`);
217
+ } else if (!isVisible && isVisibleRef.current) {
218
+ // Track dialog dismiss event when visible changes to false
219
+ if (dialogIdRef.current) {
220
+ AcousticConnectRN.logDialogDismissEvent(dialogIdRef.current, 'user_action');
221
+ console.log(`🔍 withAcousticAutoDialog: Dialog dismissed - ${dialogIdRef.current}`);
222
+ dialogIdRef.current = null;
223
+ }
224
+ isVisibleRef.current = false;
225
+ }
226
+ }, [isVisible, generateDialogId]);
227
+
228
+ // Handle dismiss events (supports various dismiss prop names)
229
+ const handleDismiss = () => {
230
+ if (dialogIdRef.current) {
231
+ AcousticConnectRN.logDialogDismissEvent(dialogIdRef.current, 'user_action');
232
+ console.log(`🔍 withAcousticAutoDialog: Dialog dismissed via dismiss handler - ${dialogIdRef.current}`);
233
+ dialogIdRef.current = null;
234
+ }
235
+ isVisibleRef.current = false;
236
+
237
+ // Call original dismiss handler if it exists (supports various prop names)
238
+ if (props.onDismiss) {
239
+ props.onDismiss();
240
+ } else if (props.onClose) {
241
+ props.onClose();
242
+ } else if (props.onHide) {
243
+ props.onHide();
244
+ } else if (props.close) {
245
+ props.close();
246
+ } else if (props.hide) {
247
+ props.hide();
248
+ }
249
+ };
250
+
251
+ // Forward ref to the wrapped component
252
+ useImperativeHandle(ref, () => {
253
+ return {
254
+ ...ref,
255
+ // Add any additional methods if needed
256
+ };
257
+ }, [ref]);
258
+
259
+ // Wrap buttons in children to track clicks
260
+ const wrappedChildren = wrapButtonsInChildren(props.children);
261
+
262
+ // Determine which dismiss prop to use based on what the original component expects
263
+ const dismissProps: any = {};
264
+ if (props.onDismiss) {
265
+ dismissProps.onDismiss = handleDismiss;
266
+ } else if (props.onClose) {
267
+ dismissProps.onClose = handleDismiss;
268
+ } else if (props.onHide) {
269
+ dismissProps.onHide = handleDismiss;
270
+ } else if (props.close) {
271
+ dismissProps.close = handleDismiss;
272
+ } else if (props.hide) {
273
+ dismissProps.hide = handleDismiss;
274
+ } else {
275
+ // Default to onDismiss if no dismiss prop is found
276
+ dismissProps.onDismiss = handleDismiss;
277
+ }
278
+
279
+ return (
280
+ <DialogComponent
281
+ {...props}
282
+ {...dismissProps}
283
+ ref={ref}
284
+ children={wrappedChildren}
285
+ />
286
+ );
287
+ });
288
+ }
289
+
290
+ /**
291
+ * Convenience function to create tracked versions of common dialog components
292
+ */
293
+ export function createTrackedDialogComponents() {
294
+ // Note: These would need to be imported in the consuming app
295
+ // This is just a template for how to use the HOC
296
+
297
+ return {
298
+ // Example usage (uncomment when react-native-paper is available):
299
+ // TrackedDialog: withAcousticAutoDialog(require('react-native-paper').Dialog),
300
+ // TrackedPortal: withAcousticAutoDialog(require('react-native-paper').Portal),
301
+ };
302
+ }
303
+
304
+ /**
305
+ * Hook to get tracked dialog components
306
+ */
307
+ export function useTrackedDialogs() {
308
+ return {
309
+ withAcousticAutoDialog,
310
+ createTrackedDialogComponents,
311
+ };
312
+ }