@appilots/sdk 0.2.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.
@@ -0,0 +1,61 @@
1
+ import { useAppilotsContext, setNavigationRef, setCurrentScreen } from './chunk-HDLZGXNF.mjs';
2
+ import React, { useRef, useCallback, useEffect } from 'react';
3
+
4
+ function getActiveRouteName(state) {
5
+ if (!state) return void 0;
6
+ const route = state.routes?.[state.index ?? 0];
7
+ if (!route) return void 0;
8
+ if (route.state) return getActiveRouteName(route.state);
9
+ return route.name;
10
+ }
11
+ function AppilotsNavigationContainer({ children }) {
12
+ const { emit } = useAppilotsContext();
13
+ const internalRef = useRef(null);
14
+ const handleRef = useCallback((instance) => {
15
+ internalRef.current = instance;
16
+ setNavigationRef(instance);
17
+ const childRef = children.ref;
18
+ if (typeof childRef === "function") childRef(instance);
19
+ else if (childRef && typeof childRef === "object") childRef.current = instance;
20
+ if (instance) {
21
+ console.log("[Appilots] NavigationContainer ref captured");
22
+ }
23
+ }, [children]);
24
+ const handleStateChange = useCallback(
25
+ (state) => {
26
+ const routeName = getActiveRouteName(state);
27
+ if (routeName) {
28
+ console.log(`[Appilots] Screen changed \u2192 "${routeName}"`);
29
+ setCurrentScreen(routeName);
30
+ emit({
31
+ type: "navigation:change",
32
+ timestamp: Date.now(),
33
+ data: { screenName: routeName }
34
+ });
35
+ }
36
+ children.props.onStateChange?.(state);
37
+ },
38
+ [emit, children.props.onStateChange]
39
+ );
40
+ useEffect(() => {
41
+ const timer = setTimeout(() => {
42
+ const route = internalRef.current?.getCurrentRoute?.();
43
+ if (route?.name) {
44
+ console.log(`[Appilots] Initial screen \u2192 "${route.name}"`);
45
+ setCurrentScreen(route.name);
46
+ emit({
47
+ type: "navigation:change",
48
+ timestamp: Date.now(),
49
+ data: { screenName: route.name }
50
+ });
51
+ }
52
+ }, 100);
53
+ return () => clearTimeout(timer);
54
+ }, [emit]);
55
+ return React.cloneElement(children, {
56
+ ref: handleRef,
57
+ onStateChange: handleStateChange
58
+ });
59
+ }
60
+
61
+ export { AppilotsNavigationContainer };
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ var chunkSIBKF7AA_js = require('./chunk-SIBKF7AA.js');
4
+ var React = require('react');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var React__default = /*#__PURE__*/_interopDefault(React);
9
+
10
+ function getActiveRouteName(state) {
11
+ if (!state) return void 0;
12
+ const route = state.routes?.[state.index ?? 0];
13
+ if (!route) return void 0;
14
+ if (route.state) return getActiveRouteName(route.state);
15
+ return route.name;
16
+ }
17
+ function AppilotsNavigationContainer({ children }) {
18
+ const { emit } = chunkSIBKF7AA_js.useAppilotsContext();
19
+ const internalRef = React.useRef(null);
20
+ const handleRef = React.useCallback((instance) => {
21
+ internalRef.current = instance;
22
+ chunkSIBKF7AA_js.setNavigationRef(instance);
23
+ const childRef = children.ref;
24
+ if (typeof childRef === "function") childRef(instance);
25
+ else if (childRef && typeof childRef === "object") childRef.current = instance;
26
+ if (instance) {
27
+ console.log("[Appilots] NavigationContainer ref captured");
28
+ }
29
+ }, [children]);
30
+ const handleStateChange = React.useCallback(
31
+ (state) => {
32
+ const routeName = getActiveRouteName(state);
33
+ if (routeName) {
34
+ console.log(`[Appilots] Screen changed \u2192 "${routeName}"`);
35
+ chunkSIBKF7AA_js.setCurrentScreen(routeName);
36
+ emit({
37
+ type: "navigation:change",
38
+ timestamp: Date.now(),
39
+ data: { screenName: routeName }
40
+ });
41
+ }
42
+ children.props.onStateChange?.(state);
43
+ },
44
+ [emit, children.props.onStateChange]
45
+ );
46
+ React.useEffect(() => {
47
+ const timer = setTimeout(() => {
48
+ const route = internalRef.current?.getCurrentRoute?.();
49
+ if (route?.name) {
50
+ console.log(`[Appilots] Initial screen \u2192 "${route.name}"`);
51
+ chunkSIBKF7AA_js.setCurrentScreen(route.name);
52
+ emit({
53
+ type: "navigation:change",
54
+ timestamp: Date.now(),
55
+ data: { screenName: route.name }
56
+ });
57
+ }
58
+ }, 100);
59
+ return () => clearTimeout(timer);
60
+ }, [emit]);
61
+ return React__default.default.cloneElement(children, {
62
+ ref: handleRef,
63
+ onStateChange: handleStateChange
64
+ });
65
+ }
66
+
67
+ exports.AppilotsNavigationContainer = AppilotsNavigationContainer;