UNPKG

react-native-acoustic-connect-beta

Version:

BETA: React native plugin for Acoustic Connect

107 lines (102 loc) 4.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _TLTRN = _interopRequireDefault(require("../TLTRN")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } /******************************************************************************************** * Copyright (C) 2025 Acoustic, L.P. All rights reserved. * * NOTICE: This file contains material that is confidential and proprietary to * Acoustic, L.P. and/or other developers. No license is granted under any intellectual or * industrial property rights of Acoustic, L.P. except as may be provided in an agreement with * Acoustic, L.P. Any unauthorized copying or distribution of content from this file is * prohibited. ********************************************************************************************/ // Use type-only import for LayoutChangeEvent const Connect = ({ children, captureKeyboardEvents, captureDialogEvents = false }) => { const navigation = children.ref; // Type assertion for children with ref const currentRoute = (0, _react.useRef)(undefined); const initial = (0, _react.useRef)(false); (0, _react.useEffect)(() => { _TLTRN.default.interceptKeyboardEvents(captureKeyboardEvents); }, [captureKeyboardEvents]); (0, _react.useEffect)(() => { _TLTRN.default.interceptDialogEvents(captureDialogEvents); }, [captureDialogEvents]); (0, _react.useEffect)(() => { if (!navigation || typeof navigation.current.addListener !== "function" || typeof navigation.current.getCurrentRoute !== "function") { console.warn("Connect: The Connect component's first child must be a NavigationContainer with a ref."); return; } // Listen for the 'state' event to track navigation state changes const unsubscribeState = navigation.current.addListener("state", () => { currentRoute.current = extractName(navigation) || navigation.current.getCurrentRoute()?.name; console.log("State change - ", currentRoute.current); if (_reactNative.Platform.OS === "ios" && currentRoute && currentRoute.current) { _TLTRN.default.logScreenViewPageName(currentRoute.current); } else if (_reactNative.Platform.OS === "android") { _TLTRN.default.logScreenViewPageName(currentRoute.current); _TLTRN.default.logScreenLayout(currentRoute.current); } }); // Cleanup listeners when the component unmounts or dependencies change return () => { unsubscribeState(); }; }, [navigation]); const onStartShouldSetResponderCapture = (0, _react.useCallback)(event => { currentRoute.current = extractName(navigation) || navigation.current.getCurrentRoute()?.name; if (currentRoute && currentRoute.current) { _TLTRN.default.logScreenViewPageName(currentRoute.current); } _TLTRN.default.logClickEvent(event); return false; // Must be false; true means this component becomes the touch responder and events don't bubble }, []); const onLayout = (0, _react.useCallback)(event => { if (initial.current) { return false; } initial.current = true; console.log("event - ", event.nativeEvent); currentRoute.current = navigation.current.getCurrentRoute()?.name; if (_reactNative.Platform.OS === "ios" && currentRoute && currentRoute.current) { _TLTRN.default.logScreenViewPageName(currentRoute.current); } else if (_reactNative.Platform.OS === "android") { _TLTRN.default.logScreenLayout(currentRoute.current); } return true; }, [navigation]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: styles.connect_main, onLayout: onLayout, onStartShouldSetResponderCapture: onStartShouldSetResponderCapture, children: children }); }; function extractName(navigation) { const routeParams = navigation.current.getCurrentRoute()?.params; if (routeParams) { const { name } = routeParams; return name ? name : navigation.current?.getCurrentRoute()?.name || ""; } return ""; } var _default = exports.default = Connect; const styles = _reactNative.StyleSheet.create({ connect_main: { flex: 1 } }); //# sourceMappingURL=Connect.js.map