🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

@futurejj/react-native-visibility-sensor

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@futurejj/react-native-visibility-sensor - npm Package Compare versions

Comparing version

to
1.3.15

@@ -49,3 +49,6 @@ "use strict";

const [active, setActive] = (0, _react.useState)(false);
const hasMeasuredRef = (0, _react.useRef)(false);
const measureInnerView = () => {
/* Check if the sensor is active to prevent unnecessary measurements
This avoids running measurements when the sensor is disabled or stopped */
if (!active) return;

@@ -63,2 +66,5 @@ localRef.current?.measure((_x, _y, width, height, pageX, pageY) => {

setRectDimensions(dimensions);
/* Set hasMeasuredRef to true to indicate that a valid measurement has been taken
This ensures visibility checks only proceed after initial measurement */
hasMeasuredRef.current = true;
}

@@ -72,3 +78,8 @@ });

const stopWatching = (0, _react.useCallback)(() => {
if (active) setActive(false);
if (active) {
setActive(false);
/* Reset measurement state when stopping to ensure fresh measurements
when the sensor is reactivated */
hasMeasuredRef.current = false;
}
}, [active]);

@@ -84,2 +95,6 @@ (0, _react.useEffect)(() => {

(0, _react.useEffect)(() => {
/* Ensure visibility checks only run when the sensor is active and
at least one measurement has been completed. This prevents
premature visibility calculations with invalid or stale dimensions */
if (!active || !hasMeasuredRef.current) return;
const window = _reactNative.Dimensions.get('window');

@@ -102,3 +117,3 @@ const isVisible = rectDimensions.rectTop + (threshold.top || 0) <= window.height &&

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [rectDimensions, lastValue]);
}, [rectDimensions, lastValue, active]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {

@@ -105,0 +120,0 @@ ref: localRef,

@@ -43,3 +43,6 @@ "use strict";

const [active, setActive] = useState(false);
const hasMeasuredRef = useRef(false);
const measureInnerView = () => {
/* Check if the sensor is active to prevent unnecessary measurements
This avoids running measurements when the sensor is disabled or stopped */
if (!active) return;

@@ -57,2 +60,5 @@ localRef.current?.measure((_x, _y, width, height, pageX, pageY) => {

setRectDimensions(dimensions);
/* Set hasMeasuredRef to true to indicate that a valid measurement has been taken
This ensures visibility checks only proceed after initial measurement */
hasMeasuredRef.current = true;
}

@@ -66,3 +72,8 @@ });

const stopWatching = useCallback(() => {
if (active) setActive(false);
if (active) {
setActive(false);
/* Reset measurement state when stopping to ensure fresh measurements
when the sensor is reactivated */
hasMeasuredRef.current = false;
}
}, [active]);

@@ -78,2 +89,6 @@ useEffect(() => {

useEffect(() => {
/* Ensure visibility checks only run when the sensor is active and
at least one measurement has been completed. This prevents
premature visibility calculations with invalid or stale dimensions */
if (!active || !hasMeasuredRef.current) return;
const window = Dimensions.get('window');

@@ -96,3 +111,3 @@ const isVisible = rectDimensions.rectTop + (threshold.top || 0) <= window.height &&

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [rectDimensions, lastValue]);
}, [rectDimensions, lastValue, active]);
return /*#__PURE__*/_jsx(View, {

@@ -99,0 +114,0 @@ ref: localRef,

{
"name": "@futurejj/react-native-visibility-sensor",
"version": "1.3.14",
"version": "1.3.15",
"description": "A React Native wrapper to check whether a component is in the view port to track impressions and clicks",

@@ -5,0 +5,0 @@ "main": "lib/commonjs/index",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet