one
Version:
One is a new React Framework that makes Vite serve both native and web.
72 lines (71 loc) • 3.51 kB
JavaScript
import { Children, isValidElement } from "react";
import { StyleSheet } from "react-native-web";
import {
appendStackHeaderBackButtonPropsToOptions,
StackHeaderBackButton
} from "./StackHeaderBackButton";
import { StackHeaderLeft, appendStackHeaderLeftPropsToOptions } from "./StackHeaderLeft";
import {
StackHeaderRight,
appendStackHeaderRightPropsToOptions
} from "./StackHeaderRight";
import {
appendStackHeaderSearchBarPropsToOptions,
StackHeaderSearchBar
} from "./StackHeaderSearchBar";
import {
appendStackHeaderTitlePropsToOptions,
StackHeaderTitle
} from "./StackHeaderTitle";
import { isChildOfType } from "../../utils/children";
function StackHeaderComponent(_props) {
return null;
}
function appendStackHeaderPropsToOptions(options, props) {
const flattenedStyle = StyleSheet.flatten(props.style), flattenedLargeStyle = StyleSheet.flatten(props.largeStyle);
if (props.hidden)
return { ...options, headerShown: !1 };
if (props.asChild)
return { ...options, header: () => props.children };
const isTransparent = flattenedStyle?.backgroundColor === "transparent", hasCustomShadow = flattenedStyle?.shadowColor !== void 0, hasBackgroundColor = flattenedStyle?.backgroundColor !== void 0, hasLargeBackgroundColor = flattenedLargeStyle?.backgroundColor !== void 0;
let updatedOptions = {
...options,
headerShown: !props.hidden,
headerBlurEffect: props.blurEffect,
// Set headerTransparent when backgroundColor is 'transparent'
// This works on both iOS and Android for normal headers
// Note: When using SearchBar on iOS, if you don't have a ScrollView with
// contentInsetAdjustmentBehavior="automatic", set headerTransparent: false in options
...isTransparent && { headerTransparent: !0 },
// Only set header styles when explicitly configured to avoid interfering with native defaults
...hasBackgroundColor && {
headerStyle: { backgroundColor: flattenedStyle.backgroundColor }
},
...hasLargeBackgroundColor && {
headerLargeStyle: {
backgroundColor: flattenedLargeStyle.backgroundColor
}
},
// Only set shadow visibility when explicitly configured
...hasCustomShadow && {
headerShadowVisible: flattenedStyle?.shadowColor !== "transparent"
},
...flattenedLargeStyle?.shadowColor !== void 0 && {
headerLargeTitleShadowVisible: flattenedLargeStyle?.shadowColor !== "transparent"
}
};
function appendChildOptions(child, options2) {
let result = options2;
return isChildOfType(child, StackHeaderTitle) ? result = appendStackHeaderTitlePropsToOptions(result, child.props) : isChildOfType(child, StackHeaderLeft) ? result = appendStackHeaderLeftPropsToOptions(result, child.props) : isChildOfType(child, StackHeaderRight) ? result = appendStackHeaderRightPropsToOptions(result, child.props) : isChildOfType(child, StackHeaderBackButton) ? result = appendStackHeaderBackButtonPropsToOptions(result, child.props) : isChildOfType(child, StackHeaderSearchBar) ? result = appendStackHeaderSearchBarPropsToOptions(result, child.props) : console.warn(
`Warning: Unknown child element passed to Stack.Header: ${child.type.name ?? child.type}`
), result;
}
return Children.forEach(props.children, (child) => {
isValidElement(child) && (updatedOptions = appendChildOptions(child, updatedOptions));
}), updatedOptions;
}
export {
StackHeaderComponent,
appendStackHeaderPropsToOptions
};
//# sourceMappingURL=StackHeaderComponent.js.map