one
Version:
One is a React framework for web, iOS, and Android apps.
74 lines (71 loc) • 3.92 kB
JavaScript
import { Children, isValidElement } from "react";
import { NAVIGATOR_CONFIG } from "../../headless/children.native.js";
import { StackHeaderBackButton, appendStackHeaderBackButtonPropsToOptions } from "./StackHeaderBackButton.native.js";
import { StackHeaderLeft, appendStackHeaderLeftPropsToOptions } from "./StackHeaderLeft.native.js";
import { StackHeaderRight, appendStackHeaderRightPropsToOptions } from "./StackHeaderRight.native.js";
import { StackHeaderSearchBar, appendStackHeaderSearchBarPropsToOptions } from "./StackHeaderSearchBar.native.js";
import { StackHeaderTitle, appendStackHeaderTitlePropsToOptions } from "./StackHeaderTitle.native.js";
import { isChildOfType } from "../../utils/children.native.js";
import { flattenStyle } from "../../utils/style.native.js";
function StackHeaderComponent(_props) {
return null;
}
Object.assign(StackHeaderComponent, { [NAVIGATOR_CONFIG]: true });
function appendStackHeaderPropsToOptions(options, props) {
var flattenedStyle = flattenStyle(props.style);
var flattenedLargeStyle = flattenStyle(props.largeStyle);
if (props.hidden) {
return {
...options,
headerShown: false
};
}
if (props.asChild) {
return {
...options,
header: function header() {
return props.children;
}
};
}
var isTransparent = (flattenedStyle === null || flattenedStyle === void 0 ? void 0 : flattenedStyle.backgroundColor) === "transparent";
var hasCustomShadow = (flattenedStyle === null || flattenedStyle === void 0 ? void 0 : flattenedStyle.shadowColor) !== void 0;
var hasBackgroundColor = (flattenedStyle === null || flattenedStyle === void 0 ? void 0 : flattenedStyle.backgroundColor) !== void 0;
var hasLargeBackgroundColor = (flattenedLargeStyle === null || flattenedLargeStyle === void 0 ? void 0 : flattenedLargeStyle.backgroundColor) !== void 0;
var updatedOptions = {
...options,
headerShown: !props.hidden,
headerBlurEffect: props.blurEffect,
...isTransparent && { headerTransparent: true },
...hasBackgroundColor && { headerStyle: { backgroundColor: flattenedStyle.backgroundColor } },
...hasLargeBackgroundColor && { headerLargeStyle: { backgroundColor: flattenedLargeStyle.backgroundColor } },
...hasCustomShadow && { headerShadowVisible: (flattenedStyle === null || flattenedStyle === void 0 ? void 0 : flattenedStyle.shadowColor) !== "transparent" },
...(flattenedLargeStyle === null || flattenedLargeStyle === void 0 ? void 0 : flattenedLargeStyle.shadowColor) !== void 0 && { headerLargeTitleShadowVisible: (flattenedLargeStyle === null || flattenedLargeStyle === void 0 ? void 0 : flattenedLargeStyle.shadowColor) !== "transparent" }
};
function appendChildOptions(child, options2) {
var result = options2;
if (isChildOfType(child, StackHeaderTitle)) {
result = appendStackHeaderTitlePropsToOptions(result, child.props);
} else if (isChildOfType(child, StackHeaderLeft)) {
result = appendStackHeaderLeftPropsToOptions(result, child.props);
} else if (isChildOfType(child, StackHeaderRight)) {
result = appendStackHeaderRightPropsToOptions(result, child.props);
} else if (isChildOfType(child, StackHeaderBackButton)) {
result = appendStackHeaderBackButtonPropsToOptions(result, child.props);
} else if (isChildOfType(child, StackHeaderSearchBar)) {
result = appendStackHeaderSearchBarPropsToOptions(result, child.props);
} else {
var _child_type_name;
console.warn(`Warning: Unknown child element passed to Stack.Header: ${(_child_type_name = child.type.name) !== null && _child_type_name !== void 0 ? _child_type_name : child.type}`);
}
return result;
}
Children.forEach(props.children, function(child) {
if (/* @__PURE__ */ isValidElement(child)) {
updatedOptions = appendChildOptions(child, updatedOptions);
}
});
return updatedOptions;
}
export { StackHeaderComponent, appendStackHeaderPropsToOptions };
//# sourceMappingURL=StackHeaderComponent.native.js.map