UNPKG

react-native-google-mobile-ads

Version:

React Native Google Mobile Ads is an easy way to monetize mobile apps with targeted, in-app advertising.

45 lines (43 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useForeground = useForeground; var _react = require("react"); var _reactNative = require("react-native"); /* * Copyright (c) 2016-present Invertase Limited & Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this library except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ /** * A custom hook that invokes a callback when the app transitions to the foreground. * * @param {Function} callback - The function to be called when the app has come to the foreground. */ function useForeground(callback) { const appState = (0, _react.useRef)(_reactNative.AppState.currentState); (0, _react.useEffect)(() => { const subscription = _reactNative.AppState.addEventListener('change', nextAppState => { if (appState.current === 'background' && nextAppState === 'active') { callback(); } appState.current = nextAppState; }); return () => { subscription.remove(); }; }, []); } //# sourceMappingURL=useForeground.js.map