UNPKG

@enact/sandstone

Version:

Large-screen/TV support library for Enact, containing a variety of UI components.

32 lines (29 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSpotlightRestore = void 0; var _react = require("react"); var _SharedStateDecorator = require("../internal/SharedStateDecorator/SharedStateDecorator"); var useSpotlightRestore = exports.useSpotlightRestore = function useSpotlightRestore(props, instances) { var scrollContainerHandle = instances.scrollContainerHandle; var context = (0, _react.useContext)(_SharedStateDecorator.SharedState); // Hooks (0, _react.useEffect)(function () { // Only intended to be used within componentDidMount, this method will fetch the last stored // scroll position from SharedState and scroll (without animation) to that position function restoreScrollPosition() { var id = props.id; if (id && context && context.get) { var scrollPosition = context.get("".concat(id, ".scrollPosition")); if (scrollPosition) { scrollContainerHandle.current.scrollTo({ position: scrollPosition, animate: false }); } } } restoreScrollPosition(); }, []); // eslint-disable-line react-hooks/exhaustive-deps };