/** * 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. * * @format * @flow strict-local */ import type {HostInstance, ScrollViewInstance} from 'react-native'; import {RNTesterThemeContext} from '../../components/RNTesterTheme'; import * as React from 'react'; import { useCallback, useContext, useLayoutEffect, useRef, useState, } from 'react'; import {Button, ScrollView, StyleSheet, Text, View} from 'react-native'; type ViewStyleProp = NonNullable>; export const name = 'IntersectionObserver Explicit Root MDN Example'; export const title = name; export const description = 'MDN example with an explicit root'; export function render(): React.Node { return ; } /** * Showcase threshold of two overlapping elements */ component IntersectionObserverExplicitRootScrollExample() { const theme = useContext(RNTesterThemeContext); const [observationRoot, setObservationRoot] = useState(null); const [showMargin, setShowMargin] = useState(true); const roofRef: React.RefSetter = useCallback( (rootNode: ?ScrollViewInstance) => { if (rootNode != null) { setObservationRoot(rootNode); } return () => { setObservationRoot(null); }; }, [], ); return (