diff --git a/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverMDNExample.js b/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverMDNExample.js
index 794a20f67abd6a..2aac729fcb4eee 100644
--- a/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverMDNExample.js
+++ b/packages/rn-tester/js/examples/IntersectionObserver/IntersectionObserverMDNExample.js
@@ -17,7 +17,7 @@ import {
useRef,
useState,
} from 'react';
-import {ScrollView, StyleSheet, Text, View} from 'react-native';
+import {Button, ScrollView, StyleSheet, Text, View} from 'react-native';
export const name = 'IntersectionObserver MDN Example';
export const title = name;
@@ -33,25 +33,35 @@ export function render(): React.Node {
*/
function IntersectionObserverMDNExample(): React.Node {
const theme = useContext(RNTesterThemeContext);
+ const [showMargin, setShowMargin] = useState(true);
return (
+
);
}
function ListItem(props: {
+ position: number,
thresholds: Array,
initialValue?: number,
}): React.Node {
const itemRef = useRef>(null);
+ const intersectionRatioRef = useRef(0);
const [intersectionRatio, setIntersectionRatio] = useState(
props.initialValue ?? 0,
);
@@ -65,6 +75,22 @@ function ListItem(props: {
const intersectionObserver = new IntersectionObserver(
entries => {
entries.forEach(entry => {
+ if (
+ intersectionRatioRef.current === 0 &&
+ entry.intersectionRatio > 0
+ ) {
+ console.log(
+ `Card #${props.position} switched to intersecting (according to thresholds)`,
+ );
+ } else if (
+ intersectionRatioRef.current !== 0 &&
+ entry.intersectionRatio === 0
+ ) {
+ console.log(
+ `Card #${props.position} switched to NOT intersecting (according to thresholds)`,
+ );
+ }
+ intersectionRatioRef.current = entry.intersectionRatio;
setIntersectionRatio(entry.intersectionRatio);
});
},
@@ -77,7 +103,7 @@ function ListItem(props: {
return () => {
intersectionObserver.disconnect();
};
- }, [props.thresholds]);
+ }, [props.position, props.thresholds]);
return (
@@ -128,6 +154,9 @@ const styles = StyleSheet.create({
scrollDownText: {
textAlign: 'center',
fontSize: 20,
+ marginTop: 20,
+ },
+ margin: {
marginBottom: 700,
},
item: {