UNPKG

@8man/react-native-media-console

Version:
50 lines 1.3 kB
import { useEffect, useState } from 'react'; export const useControlTimeout = ({ controlTimeout, controlTimeoutDelay, mounted, showControls, setShowControls, alwaysShowControls }) => { const [_controlTimeout, _setControlTimeout] = useState(); const [_clearTimeout, setClearTimeout] = useState(); const setControlTimeout = () => { _setControlTimeout(prevState => !prevState); }; const clearControlTimeout = () => { setClearTimeout(true); }; const resetControlTimeout = () => { clearControlTimeout(); }; const hideControls = () => { if (mounted && showControls && !alwaysShowControls) { setShowControls(false); } }; useEffect(() => { // eslint-disable-next-line react-hooks/exhaustive-deps controlTimeout = setTimeout(() => { hideControls(); }, controlTimeoutDelay); return () => { clearTimeout(controlTimeout); }; }, [_controlTimeout]); useEffect(() => { if (_clearTimeout) { clearTimeout(controlTimeout); setClearTimeout(false); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [_clearTimeout]); return { clearControlTimeout, resetControlTimeout, hideControls, setClearTimeout, setControlTimeout }; }; //# sourceMappingURL=useControlTimeout.js.map