@multiface.js/react-native
Version:
React Native specific components and utilities for multimodal UI
829 lines (805 loc) • 31.5 kB
JavaScript
'use strict';
var require$$0 = require('react');
var reactNative = require('react-native');
var Voice = require('@react-native-voice/voice');
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
var jsxRuntime = {exports: {}};
var reactJsxRuntime_production = {};
/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var hasRequiredReactJsxRuntime_production;
function requireReactJsxRuntime_production () {
if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production;
hasRequiredReactJsxRuntime_production = 1;
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
function jsxProd(type, config, maybeKey) {
var key = null;
void 0 !== maybeKey && (key = "" + maybeKey);
void 0 !== config.key && (key = "" + config.key);
if ("key" in config) {
maybeKey = {};
for (var propName in config)
"key" !== propName && (maybeKey[propName] = config[propName]);
} else maybeKey = config;
config = maybeKey.ref;
return {
$$typeof: REACT_ELEMENT_TYPE,
type: type,
key: key,
ref: void 0 !== config ? config : null,
props: maybeKey
};
}
reactJsxRuntime_production.Fragment = REACT_FRAGMENT_TYPE;
reactJsxRuntime_production.jsx = jsxProd;
reactJsxRuntime_production.jsxs = jsxProd;
return reactJsxRuntime_production;
}
var reactJsxRuntime_development = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var hasRequiredReactJsxRuntime_development;
function requireReactJsxRuntime_development () {
if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
hasRequiredReactJsxRuntime_development = 1;
"production" !== process.env.NODE_ENV &&
(function () {
function getComponentNameFromType(type) {
if (null == type) return null;
if ("function" === typeof type)
return type.$$typeof === REACT_CLIENT_REFERENCE
? null
: type.displayName || type.name || null;
if ("string" === typeof type) return type;
switch (type) {
case REACT_FRAGMENT_TYPE:
return "Fragment";
case REACT_PROFILER_TYPE:
return "Profiler";
case REACT_STRICT_MODE_TYPE:
return "StrictMode";
case REACT_SUSPENSE_TYPE:
return "Suspense";
case REACT_SUSPENSE_LIST_TYPE:
return "SuspenseList";
case REACT_ACTIVITY_TYPE:
return "Activity";
}
if ("object" === typeof type)
switch (
("number" === typeof type.tag &&
console.error(
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
),
type.$$typeof)
) {
case REACT_PORTAL_TYPE:
return "Portal";
case REACT_CONTEXT_TYPE:
return (type.displayName || "Context") + ".Provider";
case REACT_CONSUMER_TYPE:
return (type._context.displayName || "Context") + ".Consumer";
case REACT_FORWARD_REF_TYPE:
var innerType = type.render;
type = type.displayName;
type ||
((type = innerType.displayName || innerType.name || ""),
(type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"));
return type;
case REACT_MEMO_TYPE:
return (
(innerType = type.displayName || null),
null !== innerType
? innerType
: getComponentNameFromType(type.type) || "Memo"
);
case REACT_LAZY_TYPE:
innerType = type._payload;
type = type._init;
try {
return getComponentNameFromType(type(innerType));
} catch (x) {}
}
return null;
}
function testStringCoercion(value) {
return "" + value;
}
function checkKeyStringCoercion(value) {
try {
testStringCoercion(value);
var JSCompiler_inline_result = !1;
} catch (e) {
JSCompiler_inline_result = true;
}
if (JSCompiler_inline_result) {
JSCompiler_inline_result = console;
var JSCompiler_temp_const = JSCompiler_inline_result.error;
var JSCompiler_inline_result$jscomp$0 =
("function" === typeof Symbol &&
Symbol.toStringTag &&
value[Symbol.toStringTag]) ||
value.constructor.name ||
"Object";
JSCompiler_temp_const.call(
JSCompiler_inline_result,
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
JSCompiler_inline_result$jscomp$0
);
return testStringCoercion(value);
}
}
function getTaskName(type) {
if (type === REACT_FRAGMENT_TYPE) return "<>";
if (
"object" === typeof type &&
null !== type &&
type.$$typeof === REACT_LAZY_TYPE
)
return "<...>";
try {
var name = getComponentNameFromType(type);
return name ? "<" + name + ">" : "<...>";
} catch (x) {
return "<...>";
}
}
function getOwner() {
var dispatcher = ReactSharedInternals.A;
return null === dispatcher ? null : dispatcher.getOwner();
}
function UnknownOwner() {
return Error("react-stack-top-frame");
}
function hasValidKey(config) {
if (hasOwnProperty.call(config, "key")) {
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
if (getter && getter.isReactWarning) return false;
}
return void 0 !== config.key;
}
function defineKeyPropWarningGetter(props, displayName) {
function warnAboutAccessingKey() {
specialPropKeyWarningShown ||
((specialPropKeyWarningShown = true),
console.error(
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
displayName
));
}
warnAboutAccessingKey.isReactWarning = true;
Object.defineProperty(props, "key", {
get: warnAboutAccessingKey,
configurable: true
});
}
function elementRefGetterWithDeprecationWarning() {
var componentName = getComponentNameFromType(this.type);
didWarnAboutElementRef[componentName] ||
((didWarnAboutElementRef[componentName] = true),
console.error(
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
));
componentName = this.props.ref;
return void 0 !== componentName ? componentName : null;
}
function ReactElement(
type,
key,
self,
source,
owner,
props,
debugStack,
debugTask
) {
self = props.ref;
type = {
$$typeof: REACT_ELEMENT_TYPE,
type: type,
key: key,
props: props,
_owner: owner
};
null !== (void 0 !== self ? self : null)
? Object.defineProperty(type, "ref", {
enumerable: false,
get: elementRefGetterWithDeprecationWarning
})
: Object.defineProperty(type, "ref", { enumerable: false, value: null });
type._store = {};
Object.defineProperty(type._store, "validated", {
configurable: false,
enumerable: false,
writable: true,
value: 0
});
Object.defineProperty(type, "_debugInfo", {
configurable: false,
enumerable: false,
writable: true,
value: null
});
Object.defineProperty(type, "_debugStack", {
configurable: false,
enumerable: false,
writable: true,
value: debugStack
});
Object.defineProperty(type, "_debugTask", {
configurable: false,
enumerable: false,
writable: true,
value: debugTask
});
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
return type;
}
function jsxDEVImpl(
type,
config,
maybeKey,
isStaticChildren,
source,
self,
debugStack,
debugTask
) {
var children = config.children;
if (void 0 !== children)
if (isStaticChildren)
if (isArrayImpl(children)) {
for (
isStaticChildren = 0;
isStaticChildren < children.length;
isStaticChildren++
)
validateChildKeys(children[isStaticChildren]);
Object.freeze && Object.freeze(children);
} else
console.error(
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
);
else validateChildKeys(children);
if (hasOwnProperty.call(config, "key")) {
children = getComponentNameFromType(type);
var keys = Object.keys(config).filter(function (k) {
return "key" !== k;
});
isStaticChildren =
0 < keys.length
? "{key: someKey, " + keys.join(": ..., ") + ": ...}"
: "{key: someKey}";
didWarnAboutKeySpread[children + isStaticChildren] ||
((keys =
0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}"),
console.error(
'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
isStaticChildren,
children,
keys,
children
),
(didWarnAboutKeySpread[children + isStaticChildren] = true));
}
children = null;
void 0 !== maybeKey &&
(checkKeyStringCoercion(maybeKey), (children = "" + maybeKey));
hasValidKey(config) &&
(checkKeyStringCoercion(config.key), (children = "" + config.key));
if ("key" in config) {
maybeKey = {};
for (var propName in config)
"key" !== propName && (maybeKey[propName] = config[propName]);
} else maybeKey = config;
children &&
defineKeyPropWarningGetter(
maybeKey,
"function" === typeof type
? type.displayName || type.name || "Unknown"
: type
);
return ReactElement(
type,
children,
self,
source,
getOwner(),
maybeKey,
debugStack,
debugTask
);
}
function validateChildKeys(node) {
"object" === typeof node &&
null !== node &&
node.$$typeof === REACT_ELEMENT_TYPE &&
node._store &&
(node._store.validated = 1);
}
var React = require$$0,
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
REACT_PROFILER_TYPE = Symbol.for("react.profiler");
var REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
REACT_CONTEXT_TYPE = Symbol.for("react.context"),
REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"),
REACT_MEMO_TYPE = Symbol.for("react.memo"),
REACT_LAZY_TYPE = Symbol.for("react.lazy"),
REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
ReactSharedInternals =
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
hasOwnProperty = Object.prototype.hasOwnProperty,
isArrayImpl = Array.isArray,
createTask = console.createTask
? console.createTask
: function () {
return null;
};
React = {
"react-stack-bottom-frame": function (callStackForError) {
return callStackForError();
}
};
var specialPropKeyWarningShown;
var didWarnAboutElementRef = {};
var unknownOwnerDebugStack = React["react-stack-bottom-frame"].bind(
React,
UnknownOwner
)();
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
var didWarnAboutKeySpread = {};
reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
reactJsxRuntime_development.jsx = function (type, config, maybeKey, source, self) {
var trackActualOwner =
1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
return jsxDEVImpl(
type,
config,
maybeKey,
false,
source,
self,
trackActualOwner
? Error("react-stack-top-frame")
: unknownOwnerDebugStack,
trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
);
};
reactJsxRuntime_development.jsxs = function (type, config, maybeKey, source, self) {
var trackActualOwner =
1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
return jsxDEVImpl(
type,
config,
maybeKey,
true,
source,
self,
trackActualOwner
? Error("react-stack-top-frame")
: unknownOwnerDebugStack,
trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
);
};
})();
return reactJsxRuntime_development;
}
var hasRequiredJsxRuntime;
function requireJsxRuntime () {
if (hasRequiredJsxRuntime) return jsxRuntime.exports;
hasRequiredJsxRuntime = 1;
if (process.env.NODE_ENV === 'production') {
jsxRuntime.exports = requireReactJsxRuntime_production();
} else {
jsxRuntime.exports = requireReactJsxRuntime_development();
}
return jsxRuntime.exports;
}
var jsxRuntimeExports = requireJsxRuntime();
const RNVoiceInput = ({ onTranscript, onListeningChange, language = 'en-US', continuous = false, wakeWord, style, buttonStyle, textStyle, }) => {
const [isListening, setIsListening] = require$$0.useState(false);
const [transcript, setTranscript] = require$$0.useState('');
const [error, setError] = require$$0.useState(null);
const [hasPermission, setHasPermission] = require$$0.useState(false);
const wakeWordDetected = require$$0.useRef(false);
require$$0.useEffect(() => {
Voice.onSpeechStart = onSpeechStart;
Voice.onSpeechRecognized = onSpeechRecognized;
Voice.onSpeechEnd = onSpeechEnd;
Voice.onSpeechError = onSpeechError;
Voice.onSpeechResults = onSpeechResults;
Voice.onSpeechPartialResults = onSpeechPartialResults;
return () => {
Voice.destroy().then(Voice.removeAllListeners);
};
}, []);
require$$0.useEffect(() => {
checkPermissions();
}, []);
require$$0.useEffect(() => {
onListeningChange === null || onListeningChange === void 0 ? void 0 : onListeningChange(isListening);
}, [isListening, onListeningChange]);
const checkPermissions = () => __awaiter(void 0, void 0, void 0, function* () {
if (reactNative.Platform.OS === 'android') {
try {
const granted = yield reactNative.PermissionsAndroid.request(reactNative.PermissionsAndroid.PERMISSIONS.RECORD_AUDIO);
setHasPermission(granted === reactNative.PermissionsAndroid.RESULTS.GRANTED);
}
catch (err) {
console.warn('Permission error:', err);
setHasPermission(false);
}
}
else {
setHasPermission(true); // iOS handles permissions automatically
}
});
const onSpeechStart = (e) => {
setIsListening(true);
setError(null);
};
const onSpeechRecognized = (e) => {
// Speech recognized but not yet processed
};
const onSpeechEnd = (e) => {
setIsListening(false);
if (continuous && hasPermission) {
// Restart listening for continuous mode
setTimeout(() => {
startListening();
}, 1000);
}
};
const onSpeechError = (e) => {
var _a, _b;
setError(((_a = e.error) === null || _a === void 0 ? void 0 : _a.message) || 'Speech recognition error');
setIsListening(false);
if (continuous && hasPermission && ((_b = e.error) === null || _b === void 0 ? void 0 : _b.code) !== 'permissions') {
// Restart on error for continuous mode (except permission errors)
setTimeout(() => {
startListening();
}, 2000);
}
};
const onSpeechResults = (e) => {
if (e.value && e.value.length > 0) {
const recognizedText = e.value[0];
setTranscript(recognizedText);
// Check for wake word if specified
if (wakeWord) {
if (recognizedText.toLowerCase().includes(wakeWord.toLowerCase())) {
wakeWordDetected.current = true;
const commandText = recognizedText
.toLowerCase()
.replace(wakeWord.toLowerCase(), '')
.trim();
if (commandText) {
onTranscript(commandText, 0.9);
}
}
else if (wakeWordDetected.current) {
// Process command after wake word was detected
onTranscript(recognizedText, 0.95);
wakeWordDetected.current = false;
}
}
else {
// No wake word - process all speech
onTranscript(recognizedText, 0.9);
}
}
};
const onSpeechPartialResults = (e) => {
if (e.value && e.value.length > 0) {
setTranscript(e.value[0]);
}
};
const startListening = () => __awaiter(void 0, void 0, void 0, function* () {
if (!hasPermission) {
reactNative.Alert.alert('Permission Required', 'Microphone permission is required for voice input.', [{ text: 'OK', onPress: checkPermissions }]);
return;
}
try {
yield Voice.start(language);
setError(null);
}
catch (e) {
setError('Failed to start voice recognition');
console.error('Voice start error:', e);
}
});
const stopListening = () => __awaiter(void 0, void 0, void 0, function* () {
try {
yield Voice.stop();
}
catch (e) {
console.error('Voice stop error:', e);
}
});
const toggleListening = () => {
if (isListening) {
stopListening();
}
else {
startListening();
}
};
if (!hasPermission) {
return (jsxRuntimeExports.jsxs(reactNative.View, { style: [styles$1.container, style], children: [jsxRuntimeExports.jsx(reactNative.Text, { style: [styles$1.errorText, textStyle], children: "Microphone permission required" }), jsxRuntimeExports.jsx(reactNative.TouchableOpacity, { style: [styles$1.permissionButton, buttonStyle], onPress: checkPermissions, children: jsxRuntimeExports.jsx(reactNative.Text, { style: [styles$1.buttonText, textStyle], children: "Grant Permission" }) })] }));
}
return (jsxRuntimeExports.jsxs(reactNative.View, { style: [styles$1.container, style], children: [jsxRuntimeExports.jsx(reactNative.TouchableOpacity, { style: [
styles$1.voiceButton,
isListening && styles$1.listeningButton,
buttonStyle,
], onPress: toggleListening, children: jsxRuntimeExports.jsx(reactNative.Text, { style: [styles$1.buttonText, textStyle], children: isListening ? '🎤 Listening...' : '🎤 Tap to Speak' }) }), transcript && (jsxRuntimeExports.jsx(reactNative.View, { style: styles$1.transcriptContainer, children: jsxRuntimeExports.jsx(reactNative.Text, { style: [styles$1.transcriptText, textStyle], children: wakeWord && !wakeWordDetected.current
? `Say "${wakeWord}" to activate`
: transcript }) })), error && (jsxRuntimeExports.jsx(reactNative.Text, { style: [styles$1.errorText, textStyle], children: error })), continuous && (jsxRuntimeExports.jsxs(reactNative.Text, { style: [styles$1.continuousText, textStyle], children: ["Continuous listening ", wakeWord ? `(Wake word: "${wakeWord}")` : 'enabled'] }))] }));
};
const styles$1 = reactNative.StyleSheet.create({
container: {
padding: 16,
alignItems: 'center',
},
voiceButton: {
backgroundColor: '#007AFF',
paddingHorizontal: 24,
paddingVertical: 12,
borderRadius: 25,
minWidth: 150,
alignItems: 'center',
},
listeningButton: {
backgroundColor: '#FF3B30',
shadowColor: '#FF3B30',
shadowOffset: { width: 0, height: 0 },
shadowOpacity: 0.5,
shadowRadius: 10,
elevation: 5,
},
permissionButton: {
backgroundColor: '#FF9500',
paddingHorizontal: 20,
paddingVertical: 10,
borderRadius: 20,
marginTop: 10,
},
buttonText: {
color: 'white',
fontSize: 16,
fontWeight: '600',
},
transcriptContainer: {
marginTop: 16,
padding: 12,
backgroundColor: '#F2F2F7',
borderRadius: 8,
minHeight: 40,
justifyContent: 'center',
},
transcriptText: {
fontSize: 16,
color: '#000',
textAlign: 'center',
},
errorText: {
color: '#FF3B30',
fontSize: 14,
marginTop: 8,
textAlign: 'center',
},
continuousText: {
color: '#8E8E93',
fontSize: 12,
marginTop: 8,
textAlign: 'center',
fontStyle: 'italic',
},
});
const RNGestureHandler = ({ onGesture, children, enableSwipe = true, enablePinch = true, enableTap = true, enableLongPress = true, swipeThreshold = 50, longPressDelay = 500, style, }) => {
const longPressTimer = require$$0.useRef(null);
const gestureStartTime = require$$0.useRef(0);
const initialDistance = require$$0.useRef(0);
reactNative.Dimensions.get('window').width;
reactNative.Dimensions.get('window').height;
const calculateDistance = (touches) => {
if (touches.length < 2)
return 0;
const [touch1, touch2] = touches;
const dx = touch1.pageX - touch2.pageX;
const dy = touch1.pageY - touch2.pageY;
return Math.sqrt(dx * dx + dy * dy);
};
const detectSwipeDirection = (gestureState) => {
const { dx, dy } = gestureState;
const absDx = Math.abs(dx);
const absDy = Math.abs(dy);
if (Math.max(absDx, absDy) < swipeThreshold)
return null;
if (absDx > absDy) {
return dx > 0 ? 'right' : 'left';
}
else {
return dy > 0 ? 'down' : 'up';
}
};
const calculateVelocity = (gestureState) => {
const { vx, vy } = gestureState;
return Math.sqrt(vx * vx + vy * vy);
};
const panResponder = reactNative.PanResponder.create({
onStartShouldSetPanResponder: () => true,
onMoveShouldSetPanResponder: (evt, gestureState) => {
// Allow gesture recognition for significant movements
return Math.abs(gestureState.dx) > 10 || Math.abs(gestureState.dy) > 10;
},
onPanResponderGrant: (evt, gestureState) => {
gestureStartTime.current = Date.now();
// Handle multi-touch for pinch gestures
if (enablePinch && evt.nativeEvent.touches.length === 2) {
initialDistance.current = calculateDistance(evt.nativeEvent.touches);
}
// Start long press timer
if (enableLongPress) {
longPressTimer.current = setTimeout(() => {
const gestureData = {
type: 'long_press',
duration: Date.now() - gestureStartTime.current,
coordinates: {
x: evt.nativeEvent.pageX,
y: evt.nativeEvent.pageY,
},
};
onGesture(gestureData);
}, longPressDelay);
}
},
onPanResponderMove: (evt, gestureState) => {
// Clear long press timer on movement
if (longPressTimer.current) {
clearTimeout(longPressTimer.current);
longPressTimer.current = null;
}
// Handle pinch gestures
if (enablePinch && evt.nativeEvent.touches.length === 2) {
const currentDistance = calculateDistance(evt.nativeEvent.touches);
const scale = currentDistance / initialDistance.current;
if (scale > 1.2 || scale < 0.8) {
const gestureData = {
type: 'pinch',
direction: scale > 1 ? 'out' : 'in',
distance: Math.abs(currentDistance - initialDistance.current),
};
onGesture(gestureData);
initialDistance.current = currentDistance; // Reset for next detection
}
}
},
onPanResponderRelease: (evt, gestureState) => {
// Clear long press timer
if (longPressTimer.current) {
clearTimeout(longPressTimer.current);
longPressTimer.current = null;
}
const gestureDuration = Date.now() - gestureStartTime.current;
const velocity = calculateVelocity(gestureState);
// Handle tap gestures
if (enableTap && gestureDuration < 200 && Math.abs(gestureState.dx) < 10 && Math.abs(gestureState.dy) < 10) {
const gestureData = {
type: 'tap',
duration: gestureDuration,
coordinates: {
x: evt.nativeEvent.pageX,
y: evt.nativeEvent.pageY,
},
};
onGesture(gestureData);
return;
}
// Handle swipe gestures
if (enableSwipe) {
const direction = detectSwipeDirection(gestureState);
if (direction) {
const distance = Math.sqrt(gestureState.dx ** 2 + gestureState.dy ** 2);
const gestureData = {
type: 'swipe',
direction: direction,
velocity,
distance,
duration: gestureDuration,
};
onGesture(gestureData);
}
}
},
onPanResponderTerminate: () => {
// Clear long press timer on termination
if (longPressTimer.current) {
clearTimeout(longPressTimer.current);
longPressTimer.current = null;
}
},
});
return (jsxRuntimeExports.jsx(reactNative.View, Object.assign({ style: [styles.container, style] }, panResponder.panHandlers, { children: children })));
};
// Hook for easier gesture integration with fusion
// Commented out for build compatibility - will be enabled when fusion package is properly linked
const useGestureWithFusion = (onFusedOutput) => {
// const { processInput } = useFusion({ onFusedOutput });
const handleGesture = require$$0.useCallback((gesture) => {
const gestureString = gesture.direction
? `${gesture.type}_${gesture.direction}`
: gesture.type;
// processInput({
// type: 'gesture',
// data: gestureString,
// priority: 3,
// confidence: 0.9,
// metadata: {
// gestureDetails: gesture,
// timestamp: Date.now(),
// },
// });
// For now, just call the callback directly
onFusedOutput({
type: 'gesture',
data: gestureString,
metadata: { gestureDetails: gesture }
});
}, [onFusedOutput]);
return { handleGesture };
};
const styles = reactNative.StyleSheet.create({
container: {
flex: 1,
},
});
exports.RNGestureHandler = RNGestureHandler;
exports.RNVoiceInput = RNVoiceInput;
exports.useGestureWithFusion = useGestureWithFusion;
//# sourceMappingURL=index.js.map