
Product
Socket Threat Intel Now Shows Which Malware Campaigns Were Blocked or Detected
Socket Threat Intel now shows which malware campaigns were blocked or detected in your organization, with links to scans and Firewall events.
text-input-cursor
Advanced tools
An expo module to get the cursor's on screen coordinates in a text input. Helps to build suggestion tooltips etc.
An Expo module for retrieving the on-screen coordinates of the text cursor in TextInput components. This module enables precise positioning of UI elements such as autocomplete dropdowns, mention suggestions, and tooltips relative to the cursor position.
npm install text-input-cursor
or
yarn add text-input-cursor
|
|
|
The TextInputWithCursor component provides automatic cursor tracking with real-time coordinate updates on every text change.
import { useState } from 'react';
import { View, StyleSheet } from 'react-native';
import { TextInputWithCursor, type CursorCoordinates } from 'text-input-cursor';
export default function Example() {
const [text, setText] = useState('');
const [cursorCoords, setCursorCoords] = useState<CursorCoordinates | null>(null);
return (
<View style={styles.container}>
<View>
<TextInputWithCursor
value={text}
onChangeText={setText}
onCursorCoordinatesChange={({ coordinates }) => {
setCursorCoords(coordinates);
}}
placeholder="Type @ to mention someone..."
multiline
style={styles.input}
/>
{cursorCoords && (
<View
style={[
styles.dropdown,
{
top: cursorCoords.y,
left: cursorCoords.x,
}
]}
>
{/* Your dropdown content */}
</View>
)}
</View>
</View>
);
}
For performance-critical applications, use getCursorCoordinates to fetch coordinates only when needed. This approach eliminates unnecessary calculations during normal typing and only queries cursor position when specific triggers are detected.
import { useState, useRef } from 'react';
import { View, TextInput } from 'react-native';
import { getCursorCoordinates, type CursorCoordinates } from 'text-input-cursor';
export default function PerformanceExample() {
const [text, setText] = useState('');
const [cursorCoords, setCursorCoords] = useState<CursorCoordinates | null>(null);
const inputRef = useRef<TextInput>(null);
const handleTextChange = async (newText: string) => {
setText(newText);
// Code to detect @ symbol
// Code to check if mention is still active (no space after @)
if (/* mention detected */) {
// Fetch coordinates only when needed
const coords = await getCursorCoordinates(inputRef);
setCursorCoords(coords);
} else {
setCursorCoords(null);
}
};
return (
<View style={styles.container}>
<View>
<TextInput
ref={inputRef}
value={text}
onChangeText={handleTextChange}
placeholder="Type @ to mention someone..."
multiline
style={styles.input}
/>
{cursorCoords && (
<View
style={[
styles.dropdown,
{
top: cursorCoords.y,
left: cursorCoords.x,
}
]}
>
{/* Your dropdown content */}
</View>
)}
</View>
</View>
);
}
The returned coordinates (x, y) are relative to the TextInput component, not the screen. To position elements correctly:
position: 'absolute' on the positioned elementtop and left style propertiesThe parent View establishes the coordinate space for both the TextInput and the absolutely positioned element. Make sure the parent View doesn't have a padding.
TextInputWithCursorA component that extends React Native's TextInput with automatic cursor tracking.
Props
TextInput propsonCursorCoordinatesChange?: (event: CursorCoordinatesChangeEvent) => voidCursorCoordinatesChangeEvent
{
coordinates: CursorCoordinates | null;
cursorPosition: number;
}
getCursorCoordinatesFunction to retrieve cursor coordinates on demand.
function getCursorCoordinates(
inputRef: RefObject<TextInput>
): Promise<CursorCoordinates | null>
CursorCoordinates{
x: number; // Horizontal position (points)
y: number; // Vertical position (points)
lineHeight: number; // Height of cursor line (points)
}
Returns null if the input reference is unavailable, platform is unsupported, or an error occurs.
| Platform | Support |
|---|---|
| iOS | ✅ |
| Android | ✅ |
| Web | ✅ |
This module uses native platform APIs for accurate cursor positioning. Improvements and suggestions are welcome!
UITextView.caretRect(for:) and UITextField.caretRect(for:)Layout.getPrimaryHorizontal(), Layout.getLineTop(), and Layout.getLineBottom()getBoundingClientRect() on a span element to measure the exact cursor positionMIT
FAQs
An expo module to get the cursor's on screen coordinates in a text input. Helps to build suggestion tooltips etc.
The npm package text-input-cursor receives a total of 0 weekly downloads. As such, text-input-cursor popularity was classified as not popular.
We found that text-input-cursor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Product
Socket Threat Intel now shows which malware campaigns were blocked or detected in your organization, with links to scans and Firewall events.

Security News
Fixes for eMudhra and Brotli are out. Getting them everywhere they’re needed means tracking down bundled libraries, runtimes, and certificate stores.

Threat Research
/Security News
Socket uncovered secret-stealing workflows that ran in LiteLLM’s GitHub repository 11 days before the supply chain attack on PyPI and Docker.