react-native-screens
Version:
Native navigation primitives for your React Native app.
24 lines (21 loc) • 1.11 kB
JavaScript
import * as React from 'react';
import { featureFlags } from '../../flags';
export const TopInsetApplicationContext = /*#__PURE__*/React.createContext(false);
export function useTopInsetApplication(headerVisible, disableTopInsetApplication) {
const alreadyApplied = React.useContext(TopInsetApplicationContext);
const useLegacyBehavior = featureFlags.experiment?.androidLegacyTopInsetBehavior ?? false;
// We want to apply the inset if:
// - legacy mode (androidLegacyTopInsetBehavior)
// - or when no ancestor applied it yet and our header is visible
const wantsToApplyInset = useLegacyBehavior || !alreadyApplied && headerVisible;
// We apply the padding, only if we want to apply the inset and haven't been told to suppress it
const appliesTopInset = wantsToApplyInset && !disableTopInsetApplication;
// Once found header that may apply the padding, mark it as consumed for the subtree
const nextContextValue = alreadyApplied || wantsToApplyInset;
return {
appliesTopInset,
useLegacyBehavior,
nextContextValue
};
}
//# sourceMappingURL=TopInsetApplicationContext.js.map