@revrag-ai/embed-react-native 1.0.16 → 1.0.17
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/README.md +6 -108
- package/dist/commonjs/api/api.js +6 -5
- package/dist/commonjs/api/api.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedButton.js +138 -345
- package/dist/commonjs/components/Embed/EmbedButton.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedVoice.js +16 -4
- package/dist/commonjs/components/Embed/EmbedVoice.js.map +1 -1
- package/dist/commonjs/context/EmbedProvider.js +638 -0
- package/dist/commonjs/context/EmbedProvider.js.map +1 -0
- package/dist/commonjs/events/embed.event.js +141 -54
- package/dist/commonjs/events/embed.event.js.map +1 -1
- package/dist/commonjs/hooks/EmbedButton.animations.js +181 -0
- package/dist/commonjs/hooks/EmbedButton.animations.js.map +1 -0
- package/dist/commonjs/hooks/EmbedButton.helpers.js +90 -0
- package/dist/commonjs/hooks/EmbedButton.helpers.js.map +1 -0
- package/dist/commonjs/hooks/EmbedButton.hooks.js +165 -0
- package/dist/commonjs/hooks/EmbedButton.hooks.js.map +1 -0
- package/dist/commonjs/hooks/initialize.js +65 -25
- package/dist/commonjs/hooks/initialize.js.map +1 -1
- package/dist/commonjs/hooks/voiceagent.js +1 -18
- package/dist/commonjs/hooks/voiceagent.js.map +1 -1
- package/dist/commonjs/index.js +16 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/index.types.js +1 -2
- package/dist/commonjs/index.types.js.map +1 -1
- package/dist/commonjs/utils/constant.js +88 -0
- package/dist/commonjs/utils/constant.js.map +1 -0
- package/dist/commonjs/utils/reanimated.helper.js +2 -3
- package/dist/commonjs/utils/reanimated.helper.js.map +1 -1
- package/dist/module/api/api.js +6 -6
- package/dist/module/api/api.js.map +1 -1
- package/dist/module/components/Embed/EmbedButton.js +140 -347
- package/dist/module/components/Embed/EmbedButton.js.map +1 -1
- package/dist/module/components/Embed/EmbedVoice.js +16 -4
- package/dist/module/components/Embed/EmbedVoice.js.map +1 -1
- package/dist/module/context/EmbedProvider.js +626 -0
- package/dist/module/context/EmbedProvider.js.map +1 -0
- package/dist/module/events/embed.event.js +143 -53
- package/dist/module/events/embed.event.js.map +1 -1
- package/dist/module/hooks/EmbedButton.animations.js +172 -0
- package/dist/module/hooks/EmbedButton.animations.js.map +1 -0
- package/dist/module/hooks/EmbedButton.helpers.js +80 -0
- package/dist/module/hooks/EmbedButton.helpers.js.map +1 -0
- package/dist/module/hooks/EmbedButton.hooks.js +160 -0
- package/dist/module/hooks/EmbedButton.hooks.js.map +1 -0
- package/dist/module/hooks/initialize.js +66 -26
- package/dist/module/hooks/initialize.js.map +1 -1
- package/dist/module/hooks/voiceagent.js +1 -17
- package/dist/module/hooks/voiceagent.js.map +1 -1
- package/dist/module/index.js +4 -2
- package/dist/module/index.js.map +1 -1
- package/dist/module/index.types.js +1 -2
- package/dist/module/index.types.js.map +1 -1
- package/dist/module/utils/constant.js +82 -0
- package/dist/module/utils/constant.js.map +1 -0
- package/dist/module/utils/reanimated.helper.js +2 -3
- package/dist/module/utils/reanimated.helper.js.map +1 -1
- package/dist/typescript/src/api/api.d.ts +4 -3
- package/dist/typescript/src/api/api.d.ts.map +1 -1
- package/dist/typescript/src/api/types/embed.api.types.d.ts +1 -1
- package/dist/typescript/src/api/types/embed.api.types.d.ts.map +1 -1
- package/dist/typescript/src/components/Embed/EmbedButton.d.ts +5 -25
- package/dist/typescript/src/components/Embed/EmbedButton.d.ts.map +1 -1
- package/dist/typescript/src/components/Embed/EmbedVoice.d.ts.map +1 -1
- package/dist/typescript/src/context/EmbedProvider.d.ts +306 -0
- package/dist/typescript/src/context/EmbedProvider.d.ts.map +1 -0
- package/dist/typescript/src/events/embed.event.d.ts +74 -10
- package/dist/typescript/src/events/embed.event.d.ts.map +1 -1
- package/dist/typescript/src/hooks/EmbedButton.animations.d.ts +38 -0
- package/dist/typescript/src/hooks/EmbedButton.animations.d.ts.map +1 -0
- package/dist/typescript/src/hooks/EmbedButton.helpers.d.ts +49 -0
- package/dist/typescript/src/hooks/EmbedButton.helpers.d.ts.map +1 -0
- package/dist/typescript/src/hooks/EmbedButton.hooks.d.ts +49 -0
- package/dist/typescript/src/hooks/EmbedButton.hooks.d.ts.map +1 -0
- package/dist/typescript/src/hooks/initialize.d.ts.map +1 -1
- package/dist/typescript/src/hooks/types/initialize.types.d.ts +1 -1
- package/dist/typescript/src/hooks/types/initialize.types.d.ts.map +1 -1
- package/dist/typescript/src/hooks/voiceagent.d.ts.map +1 -1
- package/dist/typescript/src/index.d.ts +10 -4
- package/dist/typescript/src/index.d.ts.map +1 -1
- package/dist/typescript/src/index.types.d.ts +2 -3
- package/dist/typescript/src/index.types.d.ts.map +1 -1
- package/dist/typescript/src/utils/constant.d.ts +45 -0
- package/dist/typescript/src/utils/constant.d.ts.map +1 -0
- package/dist/typescript/src/utils/reanimated.helper.d.ts.map +1 -1
- package/package.json +6 -3
- package/react-native.config.js +1 -0
- package/dist/commonjs/events/eventEmitter.js +0 -43
- package/dist/commonjs/events/eventEmitter.js.map +0 -1
- package/dist/module/events/eventEmitter.js +0 -39
- package/dist/module/events/eventEmitter.js.map +0 -1
- package/dist/typescript/src/events/eventEmitter.d.ts +0 -9
- package/dist/typescript/src/events/eventEmitter.d.ts.map +0 -1
|
@@ -6,67 +6,159 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = exports.EventKeys = exports.AgentEvent = void 0;
|
|
7
7
|
var _storeKey = require("../store/store.key.js");
|
|
8
8
|
var _api = require("../api/api.js");
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
// Predefined event keys
|
|
9
|
+
var _constant = require("../utils/constant.js");
|
|
10
|
+
// Predefined event keys for sending data to the agent
|
|
12
11
|
let EventKeys = exports.EventKeys = /*#__PURE__*/function (EventKeys) {
|
|
13
12
|
EventKeys["USER_DATA"] = "user_data";
|
|
14
13
|
EventKeys["SCREEN_STATE"] = "screen_state";
|
|
15
14
|
EventKeys["OFFER_STATE"] = "offer_state";
|
|
16
|
-
EventKeys["
|
|
15
|
+
EventKeys["CUSTOM_EVENT"] = "custom_event";
|
|
17
16
|
EventKeys["FORM_STATE"] = "form_state";
|
|
17
|
+
EventKeys["ACTION_STATE"] = "action_state";
|
|
18
|
+
EventKeys["ERROR_STATE"] = "error_state";
|
|
19
|
+
EventKeys["SUCCESS_STATE"] = "success_state";
|
|
20
|
+
EventKeys["WARNING_STATE"] = "warning_state";
|
|
21
|
+
EventKeys["INFO_STATE"] = "info_state";
|
|
22
|
+
EventKeys["DEBUG_STATE"] = "debug_state";
|
|
18
23
|
return EventKeys;
|
|
19
|
-
}({});
|
|
24
|
+
}({}); // Agent event keys for listening to agent state changes
|
|
20
25
|
let AgentEvent = exports.AgentEvent = /*#__PURE__*/function (AgentEvent) {
|
|
21
26
|
AgentEvent["AGENT_CONNECTED"] = "agent_connected";
|
|
22
27
|
AgentEvent["AGENT_DISCONNECTED"] = "agent_disconnected";
|
|
23
28
|
AgentEvent["POPUP_MESSAGE_VISIBLE"] = "popup_message_visible";
|
|
24
29
|
return AgentEvent;
|
|
25
|
-
}({}); //
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
}({}); // Event data interfaces
|
|
31
|
+
/**
|
|
32
|
+
* Agent Event Emitter
|
|
33
|
+
* Handles listening to agent state changes (connection, disconnection, popup visibility)
|
|
34
|
+
* Also sends agent events to the backend API
|
|
35
|
+
*/
|
|
36
|
+
class AgentEventEmitter {
|
|
37
|
+
agentListeners = {};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Add an event listener for agent events
|
|
41
|
+
* @param eventKey - The agent event to listen for
|
|
42
|
+
* @param callback - Callback function to execute when event fires
|
|
43
|
+
*/
|
|
44
|
+
on(eventKey, callback) {
|
|
45
|
+
if (!this.agentListeners[eventKey]) {
|
|
46
|
+
this.agentListeners[eventKey] = [];
|
|
47
|
+
}
|
|
48
|
+
this.agentListeners[eventKey]?.push(callback);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Remove an event listener for agent events
|
|
53
|
+
* @param eventKey - The agent event to stop listening to
|
|
54
|
+
* @param callback - The callback function to remove
|
|
55
|
+
*/
|
|
56
|
+
off(eventKey, callback) {
|
|
57
|
+
if (!this.agentListeners[eventKey]) return;
|
|
58
|
+
const index = this.agentListeners[eventKey]?.indexOf(callback);
|
|
59
|
+
if (index !== undefined && index > -1) {
|
|
60
|
+
this.agentListeners[eventKey]?.splice(index, 1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Emit an agent event to all registered listeners AND send to backend
|
|
66
|
+
* @param eventKey - The agent event to emit
|
|
67
|
+
* @param data - Data to pass to listeners
|
|
68
|
+
* @internal - Used internally by the library
|
|
69
|
+
*/
|
|
70
|
+
async emit(eventKey, data) {
|
|
71
|
+
// Trigger local event listeners first
|
|
72
|
+
this.agentListeners[eventKey]?.forEach(callback => {
|
|
73
|
+
try {
|
|
74
|
+
callback(data);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error(`Error in agent event listener for ${eventKey}:`, error);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Send to backend API
|
|
81
|
+
await this.sendToBackend(eventKey, data);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Send agent event data to backend API
|
|
86
|
+
* @param eventKey - The agent event type
|
|
87
|
+
* @param data - Event data
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
async sendToBackend(eventKey, data) {
|
|
91
|
+
try {
|
|
92
|
+
// Get user identity to include app_user_id
|
|
93
|
+
const userIdentity = await (0, _storeKey.getAgentData)(EventKeys.USER_DATA);
|
|
94
|
+
if (!userIdentity?.app_user_id) {
|
|
95
|
+
console.warn(`[AgentEvent] Cannot send ${eventKey} to backend: User identity not found`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Prepare payload with app_user_id
|
|
100
|
+
const payload = {
|
|
101
|
+
...data,
|
|
102
|
+
app_user_id: userIdentity.app_user_id,
|
|
103
|
+
eventKey: eventKey,
|
|
104
|
+
eventType: 'agent_event'
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Send to API
|
|
108
|
+
const apiService = _api.APIService.getInstance();
|
|
109
|
+
const paramsData = (0, _constant.buildEventPayload)(payload);
|
|
110
|
+
const response = await apiService.updateUserData(paramsData);
|
|
111
|
+
if (!response.success) {
|
|
112
|
+
console.error(`[AgentEvent] Failed to send ${eventKey} to backend:`, response.error);
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error(`[AgentEvent] Error sending ${eventKey} to backend:`, error);
|
|
116
|
+
// Fail silently - agent events should not break the app
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Remove all listeners for a specific event
|
|
122
|
+
* @param eventKey - The agent event to clear listeners for
|
|
123
|
+
*/
|
|
124
|
+
removeAllListeners(eventKey) {
|
|
125
|
+
if (eventKey) {
|
|
126
|
+
delete this.agentListeners[eventKey];
|
|
127
|
+
} else {
|
|
128
|
+
this.agentListeners = {};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
41
132
|
class Embed {
|
|
42
133
|
events = {};
|
|
43
|
-
|
|
44
|
-
|
|
134
|
+
|
|
135
|
+
// Agent event emitter for listening to agent state changes
|
|
136
|
+
|
|
137
|
+
constructor() {
|
|
138
|
+
this.event = new AgentEventEmitter();
|
|
139
|
+
}
|
|
45
140
|
|
|
46
141
|
// Automatically adds a default listener if none exists
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// }
|
|
56
|
-
// }
|
|
142
|
+
ensureDefaultListener(eventKey) {
|
|
143
|
+
if (!this.events[eventKey]) {
|
|
144
|
+
this.events[eventKey] = [data => {
|
|
145
|
+
// todo: handle default event
|
|
146
|
+
console.info('default event this', data);
|
|
147
|
+
}];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
57
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Send an event to the AI agent
|
|
153
|
+
* @param eventKey - The event type to send
|
|
154
|
+
* @param data - Event data payload
|
|
155
|
+
*/
|
|
58
156
|
async Event(eventKey, data) {
|
|
59
|
-
console.log('eventKey', eventKey, data);
|
|
60
157
|
if (!Object.values(EventKeys).includes(eventKey)) {
|
|
61
158
|
// todo: handle invalid event key
|
|
62
159
|
throw new Error(`Invalid event key: ${eventKey}. Must be one of: ${Object.values(EventKeys).join(', ')}`);
|
|
63
160
|
}
|
|
64
161
|
const key = eventKey;
|
|
65
|
-
|
|
66
|
-
// Restrict all events except USER_DATA until USER_DATA is initialized
|
|
67
|
-
if (key !== EventKeys.USER_DATA && !this.userDataInitialized) {
|
|
68
|
-
throw new Error(`Cannot trigger ${eventKey} event. USER_DATA event must be triggered first to initialize user identity.`);
|
|
69
|
-
}
|
|
70
162
|
if (key !== EventKeys.USER_DATA) {
|
|
71
163
|
const userIdentity = await (0, _storeKey.getAgentData)(EventKeys.USER_DATA);
|
|
72
164
|
if (userIdentity) {
|
|
@@ -77,26 +169,23 @@ class Embed {
|
|
|
77
169
|
}
|
|
78
170
|
|
|
79
171
|
// Ensure a default listener is registered if not already
|
|
80
|
-
|
|
172
|
+
this.ensureDefaultListener(key);
|
|
81
173
|
|
|
82
174
|
// Trigger API call
|
|
83
175
|
try {
|
|
84
176
|
const apiService = _api.APIService.getInstance();
|
|
177
|
+
const paramsData = (0, _constant.buildEventPayload)({
|
|
178
|
+
...data,
|
|
179
|
+
eventKey: key
|
|
180
|
+
});
|
|
85
181
|
const response = await apiService.updateUserData({
|
|
86
|
-
|
|
87
|
-
data
|
|
182
|
+
...paramsData
|
|
88
183
|
});
|
|
89
184
|
if (!response.success) {
|
|
90
185
|
throw new Error(`Failed to trigger API for event: ${eventKey}`);
|
|
91
186
|
}
|
|
92
187
|
(0, _storeKey.setAgentData)(data, key);
|
|
93
|
-
|
|
94
|
-
// Mark USER_DATA as initialized after successful processing
|
|
95
|
-
if (key === EventKeys.USER_DATA) {
|
|
96
|
-
this.userDataInitialized = true;
|
|
97
|
-
}
|
|
98
188
|
} catch (error) {
|
|
99
|
-
console.log('data_Event_error', key, data);
|
|
100
189
|
throw new Error(`Failed to trigger API for event: ${eventKey}`);
|
|
101
190
|
// todo: handle error triggering API
|
|
102
191
|
}
|
|
@@ -105,18 +194,16 @@ class Embed {
|
|
|
105
194
|
this.events[key]?.forEach(callback => callback(data));
|
|
106
195
|
}
|
|
107
196
|
|
|
108
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Add listener for data events (legacy support)
|
|
199
|
+
* @deprecated Use event.on() for agent events instead
|
|
200
|
+
*/
|
|
109
201
|
on(eventKey, callback) {
|
|
110
202
|
if (!this.events[eventKey]) {
|
|
111
203
|
this.events[eventKey] = [];
|
|
112
204
|
}
|
|
113
205
|
this.events[eventKey]?.push(callback);
|
|
114
206
|
}
|
|
115
|
-
|
|
116
|
-
// Check if USER_DATA has been initialized
|
|
117
|
-
isUserDataInitialized() {
|
|
118
|
-
return this.userDataInitialized;
|
|
119
|
-
}
|
|
120
207
|
}
|
|
121
208
|
const embed = new Embed();
|
|
122
209
|
var _default = exports.default = embed;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_storeKey","require","_api","
|
|
1
|
+
{"version":3,"names":["_storeKey","require","_api","_constant","EventKeys","exports","AgentEvent","AgentEventEmitter","agentListeners","on","eventKey","callback","push","off","index","indexOf","undefined","splice","emit","data","forEach","error","console","sendToBackend","userIdentity","getAgentData","USER_DATA","app_user_id","warn","payload","eventType","apiService","APIService","getInstance","paramsData","buildEventPayload","response","updateUserData","success","removeAllListeners","Embed","events","constructor","event","ensureDefaultListener","info","Event","Object","values","includes","Error","join","key","setAgentData","embed","_default","default"],"sourceRoot":"../../../src","sources":["events/embed.event.ts"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAIA;AAAA,IACYG,SAAS,GAAAC,OAAA,CAAAD,SAAA,0BAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAAA,OAATA,SAAS;AAAA,OAcrB;AAAA,IACYE,UAAU,GAAAD,OAAA,CAAAC,UAAA,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA,OAMtB;AAmBA;AACA;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,CAAC;EACdC,cAAc,GAA8C,CAAC,CAAC;;EAEtE;AACF;AACA;AACA;AACA;EACEC,EAAEA,CAACC,QAAoB,EAAEC,QAAuB,EAAQ;IACtD,IAAI,CAAC,IAAI,CAACH,cAAc,CAACE,QAAQ,CAAC,EAAE;MAClC,IAAI,CAACF,cAAc,CAACE,QAAQ,CAAC,GAAG,EAAE;IACpC;IACA,IAAI,CAACF,cAAc,CAACE,QAAQ,CAAC,EAAEE,IAAI,CAACD,QAAQ,CAAC;EAC/C;;EAEA;AACF;AACA;AACA;AACA;EACEE,GAAGA,CAACH,QAAoB,EAAEC,QAAuB,EAAQ;IACvD,IAAI,CAAC,IAAI,CAACH,cAAc,CAACE,QAAQ,CAAC,EAAE;IAEpC,MAAMI,KAAK,GAAG,IAAI,CAACN,cAAc,CAACE,QAAQ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IAAI,CAAC+B,MAAM,CAAC/B,QAAQ,CAAC,GAAG,EAAE;IAC5B;IACA,IAAI,CAAC+B,MAAM,CAAC/B,QAAQ,CAAC,EAAEE,IAAI,CAACD,QAAQ,CAAC;EACvC;AACF;AAEA,MAAM2C,KAAK,GAAG,IAAId,KAAK,CAAC,CAAC;AAAC,IAAAe,QAAA,GAAAlD,OAAA,CAAAmD,OAAA,GACXF,KAAK","ignoreList":[]}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.usePopupAnimatedStyles = exports.useButtonAnimations = exports.useButtonAnimatedStyles = exports.useBreathingAnimation = exports.useAnimationValues = exports.createPanGesture = exports.Animated = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNativeGestureHandler = require("react-native-gesture-handler");
|
|
9
|
+
var _reanimatedHelper = require("../utils/reanimated.helper.js");
|
|
10
|
+
var _EmbedButtonHelpers = require("./EmbedButton.helpers.js");
|
|
11
|
+
/**
|
|
12
|
+
* @file EmbedButton.animations.ts
|
|
13
|
+
* @description Animation logic and hooks for the EmbedButton component
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// Get reanimated API with fallbacks
|
|
17
|
+
const {
|
|
18
|
+
useSharedValue,
|
|
19
|
+
useAnimatedStyle,
|
|
20
|
+
withTiming,
|
|
21
|
+
withSpring,
|
|
22
|
+
withRepeat,
|
|
23
|
+
withSequence,
|
|
24
|
+
runOnJS,
|
|
25
|
+
Easing,
|
|
26
|
+
Animated,
|
|
27
|
+
isAvailable: isReanimatedAvailable
|
|
28
|
+
} = (0, _reanimatedHelper.getReanimatedAPI)();
|
|
29
|
+
|
|
30
|
+
// Show warning if reanimated is not available
|
|
31
|
+
exports.Animated = Animated;
|
|
32
|
+
if (!isReanimatedAvailable) {
|
|
33
|
+
(0, _reanimatedHelper.showReanimatedSetupError)();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Export the Animated component for use in the main component
|
|
37
|
+
|
|
38
|
+
// ==================== ANIMATION VALUES HOOK ====================
|
|
39
|
+
/**
|
|
40
|
+
* Hook to initialize and manage all animation shared values
|
|
41
|
+
*/
|
|
42
|
+
const useAnimationValues = () => {
|
|
43
|
+
const isPressed = useSharedValue(false);
|
|
44
|
+
const offset = useSharedValue({
|
|
45
|
+
x: 0,
|
|
46
|
+
y: 0
|
|
47
|
+
});
|
|
48
|
+
const start = useSharedValue({
|
|
49
|
+
x: 0,
|
|
50
|
+
y: 0
|
|
51
|
+
});
|
|
52
|
+
const menuAnimation = useSharedValue(0);
|
|
53
|
+
const buttonWidth = useSharedValue(_EmbedButtonHelpers.BUTTON_DIMENSIONS.WIDTH);
|
|
54
|
+
const buttonScale = useSharedValue(1);
|
|
55
|
+
return {
|
|
56
|
+
isPressed,
|
|
57
|
+
offset,
|
|
58
|
+
start,
|
|
59
|
+
menuAnimation,
|
|
60
|
+
buttonWidth,
|
|
61
|
+
buttonScale
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// ==================== BUTTON ANIMATIONS ====================
|
|
66
|
+
/**
|
|
67
|
+
* Hook to handle button expand/collapse animations
|
|
68
|
+
*/
|
|
69
|
+
exports.useAnimationValues = useAnimationValues;
|
|
70
|
+
const useButtonAnimations = (isOpen, menuAnimation, buttonWidth) => {
|
|
71
|
+
(0, _react.useEffect)(() => {
|
|
72
|
+
menuAnimation.value = withTiming(isOpen ? 0.8 : 0, {
|
|
73
|
+
duration: 300
|
|
74
|
+
});
|
|
75
|
+
buttonWidth.value = withTiming(isOpen ? _EmbedButtonHelpers.BUTTON_DIMENSIONS.EXPANDED_WIDTH : _EmbedButtonHelpers.BUTTON_DIMENSIONS.WIDTH);
|
|
76
|
+
}, [isOpen, menuAnimation, buttonWidth]);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// ==================== BREATHING ANIMATION ====================
|
|
80
|
+
/**
|
|
81
|
+
* Hook to handle breathing animation when auto-popup is shown
|
|
82
|
+
*/
|
|
83
|
+
exports.useButtonAnimations = useButtonAnimations;
|
|
84
|
+
const useBreathingAnimation = (isOpen, isAutoOpen, buttonScale) => {
|
|
85
|
+
(0, _react.useEffect)(() => {
|
|
86
|
+
if (!isOpen && isAutoOpen) {
|
|
87
|
+
// Start breathing animation
|
|
88
|
+
buttonScale.value = withRepeat(withSequence(withTiming(1.1, {
|
|
89
|
+
duration: 1500,
|
|
90
|
+
easing: Easing.inOut(Easing.ease)
|
|
91
|
+
}), withTiming(1, {
|
|
92
|
+
duration: 1500,
|
|
93
|
+
easing: Easing.inOut(Easing.ease)
|
|
94
|
+
})), -1,
|
|
95
|
+
// Infinite repeat
|
|
96
|
+
false);
|
|
97
|
+
} else {
|
|
98
|
+
// Reset animation
|
|
99
|
+
buttonScale.value = withTiming(1, {
|
|
100
|
+
duration: 300
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}, [buttonScale, isAutoOpen, isOpen]);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// ==================== ANIMATED STYLES ====================
|
|
107
|
+
/**
|
|
108
|
+
* Hook to create animated styles for the button
|
|
109
|
+
*/
|
|
110
|
+
exports.useBreathingAnimation = useBreathingAnimation;
|
|
111
|
+
const useButtonAnimatedStyles = (isOpen, offset, buttonWidth, isPressed, buttonScale) => {
|
|
112
|
+
return useAnimatedStyle(() => {
|
|
113
|
+
const maxX = (0, _EmbedButtonHelpers.calculateMaxX)(isOpen);
|
|
114
|
+
const clampedX = (0, _EmbedButtonHelpers.clamp)(offset.value.x, -maxX, 0);
|
|
115
|
+
return {
|
|
116
|
+
width: buttonWidth.value,
|
|
117
|
+
height: _EmbedButtonHelpers.BUTTON_DIMENSIONS.HEIGHT,
|
|
118
|
+
transform: [{
|
|
119
|
+
translateX: clampedX
|
|
120
|
+
}, {
|
|
121
|
+
translateY: offset.value.y
|
|
122
|
+
}, {
|
|
123
|
+
scale: withSpring(isPressed.value ? 0.95 : buttonScale.value)
|
|
124
|
+
}],
|
|
125
|
+
justifyContent: isOpen ? 'space-between' : 'flex-start',
|
|
126
|
+
overflow: 'hidden'
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Hook to create animated styles for the popup text
|
|
133
|
+
*/
|
|
134
|
+
exports.useButtonAnimatedStyles = useButtonAnimatedStyles;
|
|
135
|
+
const usePopupAnimatedStyles = (offset, isPressed) => {
|
|
136
|
+
return useAnimatedStyle(() => {
|
|
137
|
+
const maxX = _EmbedButtonHelpers.SCREEN_WIDTH;
|
|
138
|
+
const clampedX = (0, _EmbedButtonHelpers.clamp)(offset.value.x, -maxX, 0);
|
|
139
|
+
return {
|
|
140
|
+
transform: [{
|
|
141
|
+
translateX: clampedX
|
|
142
|
+
}, {
|
|
143
|
+
translateY: offset.value.y
|
|
144
|
+
}, {
|
|
145
|
+
scale: withSpring(isPressed.value ? 1 : 1)
|
|
146
|
+
}]
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// ==================== GESTURE HANDLER ====================
|
|
152
|
+
/**
|
|
153
|
+
* Create pan gesture for drag functionality
|
|
154
|
+
*/
|
|
155
|
+
exports.usePopupAnimatedStyles = usePopupAnimatedStyles;
|
|
156
|
+
const createPanGesture = (isPressed, offset, start, isOpen, setIsAutoOpen) => {
|
|
157
|
+
return _reactNativeGestureHandler.Gesture.Pan().onBegin(() => {
|
|
158
|
+
isPressed.value = true;
|
|
159
|
+
if (setIsAutoOpen) {
|
|
160
|
+
runOnJS(setIsAutoOpen)(false);
|
|
161
|
+
}
|
|
162
|
+
}).onUpdate(e => {
|
|
163
|
+
const maxX = (0, _EmbedButtonHelpers.calculateMaxX)(isOpen);
|
|
164
|
+
const maxY = (0, _EmbedButtonHelpers.calculateMaxY)();
|
|
165
|
+
const newX = (0, _EmbedButtonHelpers.clamp)(e.translationX + start.value.x, -maxX, 0);
|
|
166
|
+
const newY = (0, _EmbedButtonHelpers.clamp)(e.translationY + start.value.y, -maxY, 0);
|
|
167
|
+
offset.value = {
|
|
168
|
+
x: newX,
|
|
169
|
+
y: newY
|
|
170
|
+
};
|
|
171
|
+
}).onEnd(() => {
|
|
172
|
+
start.value = {
|
|
173
|
+
x: offset.value.x,
|
|
174
|
+
y: offset.value.y
|
|
175
|
+
};
|
|
176
|
+
}).onFinalize(() => {
|
|
177
|
+
isPressed.value = false;
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
exports.createPanGesture = createPanGesture;
|
|
181
|
+
//# sourceMappingURL=EmbedButton.animations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNativeGestureHandler","_reanimatedHelper","_EmbedButtonHelpers","useSharedValue","useAnimatedStyle","withTiming","withSpring","withRepeat","withSequence","runOnJS","Easing","Animated","isAvailable","isReanimatedAvailable","getReanimatedAPI","exports","showReanimatedSetupError","useAnimationValues","isPressed","offset","x","y","start","menuAnimation","buttonWidth","BUTTON_DIMENSIONS","WIDTH","buttonScale","useButtonAnimations","isOpen","useEffect","value","duration","EXPANDED_WIDTH","useBreathingAnimation","isAutoOpen","easing","inOut","ease","useButtonAnimatedStyles","maxX","calculateMaxX","clampedX","clamp","width","height","HEIGHT","transform","translateX","translateY","scale","justifyContent","overflow","usePopupAnimatedStyles","SCREEN_WIDTH","createPanGesture","setIsAutoOpen","Gesture","Pan","onBegin","onUpdate","e","maxY","calculateMaxY","newX","translationX","newY","translationY","onEnd","onFinalize"],"sourceRoot":"../../../src","sources":["hooks/EmbedButton.animations.ts"],"mappings":";;;;;;AAKA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,0BAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAIA,IAAAG,mBAAA,GAAAH,OAAA;AAZA;AACA;AACA;AACA;;AAiBA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defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseDelayMs = exports.formatDuration = exports.clamp = exports.calculateMaxY = exports.calculateMaxX = exports.SCREEN_WIDTH = exports.SCREEN_HEIGHT = exports.ICON_URLS = exports.DEFAULT_POPUP_DELAY_MS = exports.DEFAULT_GRADIENT_COLORS = exports.BUTTON_DIMENSIONS = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
/**
|
|
9
|
+
* @file EmbedButton.helpers.ts
|
|
10
|
+
* @description Helper functions and utilities for the EmbedButton component
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// ==================== CONSTANTS ====================
|
|
14
|
+
const {
|
|
15
|
+
width: SCREEN_WIDTH,
|
|
16
|
+
height: SCREEN_HEIGHT
|
|
17
|
+
} = _reactNative.Dimensions.get('window');
|
|
18
|
+
exports.SCREEN_HEIGHT = SCREEN_HEIGHT;
|
|
19
|
+
exports.SCREEN_WIDTH = SCREEN_WIDTH;
|
|
20
|
+
const BUTTON_DIMENSIONS = exports.BUTTON_DIMENSIONS = {
|
|
21
|
+
WIDTH: 60,
|
|
22
|
+
HEIGHT: 60,
|
|
23
|
+
EXPANDED_WIDTH: SCREEN_WIDTH * 0.9
|
|
24
|
+
};
|
|
25
|
+
const ICON_URLS = exports.ICON_URLS = {
|
|
26
|
+
MIC_ON: 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/Mute+button.png',
|
|
27
|
+
MIC_OFF: 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/unmute.png',
|
|
28
|
+
END_CALL: 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/end+button.png',
|
|
29
|
+
AMPLIFY_ANIMATION: 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/amplify.json'
|
|
30
|
+
};
|
|
31
|
+
const DEFAULT_GRADIENT_COLORS = exports.DEFAULT_GRADIENT_COLORS = ['#1E0844', '#B391F3'];
|
|
32
|
+
const DEFAULT_POPUP_DELAY_MS = exports.DEFAULT_POPUP_DELAY_MS = 15000;
|
|
33
|
+
|
|
34
|
+
// ==================== TYPES ====================
|
|
35
|
+
|
|
36
|
+
// ==================== HELPER FUNCTIONS ====================
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Safely parse delay value to ensure it's a valid number
|
|
40
|
+
*/
|
|
41
|
+
const parseDelayMs = delay => {
|
|
42
|
+
if (typeof delay === 'number') {
|
|
43
|
+
return delay;
|
|
44
|
+
}
|
|
45
|
+
const parsed = Number(delay);
|
|
46
|
+
return Number.isFinite(parsed) ? parsed : DEFAULT_POPUP_DELAY_MS;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Format seconds to MM:SS format
|
|
51
|
+
*/
|
|
52
|
+
exports.parseDelayMs = parseDelayMs;
|
|
53
|
+
const formatDuration = seconds => {
|
|
54
|
+
const minutes = Math.floor(seconds / 60);
|
|
55
|
+
const remainingSeconds = seconds % 60;
|
|
56
|
+
return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Calculate the max X position for button drag constraints
|
|
61
|
+
*/
|
|
62
|
+
exports.formatDuration = formatDuration;
|
|
63
|
+
const calculateMaxX = isOpen => {
|
|
64
|
+
'worklet';
|
|
65
|
+
|
|
66
|
+
const width = isOpen ? BUTTON_DIMENSIONS.EXPANDED_WIDTH : BUTTON_DIMENSIONS.WIDTH;
|
|
67
|
+
return SCREEN_WIDTH - width - 35;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Calculate the max Y position for button drag constraints
|
|
72
|
+
*/
|
|
73
|
+
exports.calculateMaxX = calculateMaxX;
|
|
74
|
+
const calculateMaxY = () => {
|
|
75
|
+
'worklet';
|
|
76
|
+
|
|
77
|
+
return SCREEN_HEIGHT - 150;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Clamp a value between a min and max
|
|
82
|
+
*/
|
|
83
|
+
exports.calculateMaxY = calculateMaxY;
|
|
84
|
+
const clamp = (value, min, max) => {
|
|
85
|
+
'worklet';
|
|
86
|
+
|
|
87
|
+
return Math.min(Math.max(value, min), max);
|
|
88
|
+
};
|
|
89
|
+
exports.clamp = clamp;
|
|
90
|
+
//# sourceMappingURL=EmbedButton.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","width","SCREEN_WIDTH","height","SCREEN_HEIGHT","Dimensions","get","exports","BUTTON_DIMENSIONS","WIDTH","HEIGHT","EXPANDED_WIDTH","ICON_URLS","MIC_ON","MIC_OFF","END_CALL","AMPLIFY_ANIMATION","DEFAULT_GRADIENT_COLORS","DEFAULT_POPUP_DELAY_MS","parseDelayMs","delay","parsed","Number","isFinite","formatDuration","seconds","minutes","Math","floor","remainingSeconds","toString","padStart","calculateMaxX","isOpen","calculateMaxY","clamp","value","min","max"],"sourceRoot":"../../../src","sources":["hooks/EmbedButton.helpers.ts"],"mappings":";;;;;;AAKA,IAAAA,YAAA,GAAAC,OAAA;AALA;AACA;AACA;AACA;;AAIA;AACO,MAAM;EAAEC,KAAK,EAAEC,YAAY;EAAEC,MAAM,EAAEC;AAAc,CAAC,GACzDC,uBAAU,CAACC,GAAG,CAAC,QAAQ,CAAC;AAACC,OAAA,CAAAH,aAAA,GAAAA,aAAA;AAAAG,OAAA,CAAAL,YAAA,GAAAA,YAAA;AAEpB,MAAMM,iBAAiB,GAAAD,OAAA,CAAAC,iBAAA,GAAG;EAC/BC,KAAK,EAAE,EAAE;EACTC,MAAM,EAAE,EAAE;EACVC,cAAc,EAAET,YAAY,GAAG;AACjC,CAAU;AAEH,MAAMU,SAAS,GAAAL,OAAA,CAAAK,SAAA,GAAG;EACvBC,MAAM,EACJ,wEAAwE;EAC1EC,OAAO,EAAE,mEAAmE;EAC5EC,QAA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