import React, { ClassAttributes, isValidElement, useContext, useEffect, useRef } from "react"; import { StyleProp, View, ViewProps, ViewStyle } from "react-native"; import { SpotlightTourContext } from "./SpotlightTour.context"; interface AttachStepProps { index: number; disabled?: boolean; style?: StyleProp; } export const AttachStep: React.FC = ({ children, disabled, index, style }) => { const { current, changeSpot, spot } = useContext(SpotlightTourContext); const childRef = useRef(null); useEffect(() => { if (!spot) { changeSpot({ height: 0, width: 0, x: 0, y: 400 }); } if (!disabled && current === index) { childRef.current?.measureInWindow((x, y, width, height) => { changeSpot({ height, width, x, y }); }); } }, [current, disabled]); if (isValidElement(children) && React.Children.count(children) === 1) { return React.cloneElement & ViewProps>( React.Children.only(children), { ref: childRef, collapsable: false } ); } return ( {children} ); };