one 1.2.37 → 1.2.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/layouts/Stack.cjs +1 -6
- package/dist/cjs/layouts/Stack.js +2 -5
- package/dist/cjs/layouts/Stack.js.map +1 -1
- package/dist/cjs/layouts/Stack.native.js +1 -6
- package/dist/cjs/layouts/Stack.native.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/layouts/Stack.js +1 -5
- package/dist/esm/layouts/Stack.js.map +1 -1
- package/dist/esm/layouts/Stack.mjs +1 -6
- package/dist/esm/layouts/Stack.mjs.map +1 -1
- package/dist/esm/layouts/Stack.native.js +1 -6
- package/dist/esm/layouts/Stack.native.js.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +0 -9
- package/src/layouts/Stack.tsx +1 -7
- package/types/index.d.ts +0 -1
- package/types/index.d.ts.map +1 -1
- package/types/layouts/Stack.d.ts +0 -10
- package/types/layouts/Stack.d.ts.map +1 -1
- package/src/__mocks__/@react-navigation/native-stack.ts +0 -32
- package/src/__mocks__/@react-navigation/native.ts +0 -21
- package/src/__mocks__/expo-linking.ts +0 -6
- package/src/__mocks__/expo-modules-core.ts +0 -11
- package/src/__mocks__/react-native-screens.ts +0 -17
- package/src/__mocks__/react-native.ts +0 -20
- package/src/layouts/stack-utils/README.md +0 -211
- package/src/layouts/stack-utils/StackHeaderBackButton.tsx +0 -34
- package/src/layouts/stack-utils/StackHeaderComponent.tsx +0 -109
- package/src/layouts/stack-utils/StackHeaderLeft.tsx +0 -29
- package/src/layouts/stack-utils/StackHeaderRight.tsx +0 -29
- package/src/layouts/stack-utils/StackHeaderSearchBar.tsx +0 -21
- package/src/layouts/stack-utils/StackHeaderTitle.tsx +0 -61
- package/src/layouts/stack-utils/StackScreen.tsx +0 -65
- package/src/layouts/stack-utils/__tests__/composition.test.tsx +0 -267
- package/src/layouts/stack-utils/index.tsx +0 -35
- package/src/utils/children.ts +0 -47
- package/src/utils/style.ts +0 -17
- package/types/__mocks__/@react-navigation/native-stack.d.ts +0 -30
- package/types/__mocks__/@react-navigation/native.d.ts +0 -17
- package/types/__mocks__/expo-linking.d.ts +0 -9
- package/types/__mocks__/expo-modules-core.d.ts +0 -11
- package/types/__mocks__/react-native-screens.d.ts +0 -14
- package/types/__mocks__/react-native.d.ts +0 -12
- package/types/layouts/stack-utils/StackHeaderBackButton.d.ts +0 -17
- package/types/layouts/stack-utils/StackHeaderComponent.d.ts +0 -36
- package/types/layouts/stack-utils/StackHeaderLeft.d.ts +0 -13
- package/types/layouts/stack-utils/StackHeaderRight.d.ts +0 -13
- package/types/layouts/stack-utils/StackHeaderSearchBar.d.ts +0 -10
- package/types/layouts/stack-utils/StackHeaderTitle.d.ts +0 -26
- package/types/layouts/stack-utils/StackScreen.d.ts +0 -21
- package/types/layouts/stack-utils/index.d.ts +0 -20
- package/types/utils/children.d.ts +0 -15
- package/types/utils/style.d.ts +0 -7
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { NativeStackNavigationOptions } from '@react-navigation/native-stack'
|
|
2
|
-
import type { ImageSourcePropType } from 'react-native'
|
|
3
|
-
import type { ScreenStackHeaderConfigProps } from 'react-native-screens'
|
|
4
|
-
|
|
5
|
-
export interface StackHeaderBackButtonProps {
|
|
6
|
-
children?: string
|
|
7
|
-
style?: NativeStackNavigationOptions['headerBackTitleStyle']
|
|
8
|
-
withMenu?: boolean
|
|
9
|
-
displayMode?: ScreenStackHeaderConfigProps['backButtonDisplayMode']
|
|
10
|
-
hidden?: boolean
|
|
11
|
-
src?: ImageSourcePropType
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Configuration component for the back button in stack headers.
|
|
16
|
-
*/
|
|
17
|
-
export function StackHeaderBackButton(_props: StackHeaderBackButtonProps) {
|
|
18
|
-
return null
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function appendStackHeaderBackButtonPropsToOptions(
|
|
22
|
-
options: NativeStackNavigationOptions,
|
|
23
|
-
props: StackHeaderBackButtonProps
|
|
24
|
-
): NativeStackNavigationOptions {
|
|
25
|
-
return {
|
|
26
|
-
...options,
|
|
27
|
-
headerBackTitle: props.children,
|
|
28
|
-
headerBackTitleStyle: props.style,
|
|
29
|
-
headerBackImageSource: props.src,
|
|
30
|
-
headerBackButtonDisplayMode: props.displayMode,
|
|
31
|
-
headerBackButtonMenuEnabled: props.withMenu,
|
|
32
|
-
headerBackVisible: props.hidden !== undefined ? !props.hidden : undefined,
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type { NativeStackNavigationOptions } from '@react-navigation/native-stack'
|
|
2
|
-
import { Children, isValidElement, type ReactNode } from 'react'
|
|
3
|
-
import { StyleSheet, type ColorValue, type StyleProp } from 'react-native'
|
|
4
|
-
import type { ScreenStackHeaderConfigProps } from 'react-native-screens'
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
appendStackHeaderBackButtonPropsToOptions,
|
|
8
|
-
StackHeaderBackButton,
|
|
9
|
-
} from './StackHeaderBackButton'
|
|
10
|
-
import { StackHeaderLeft, appendStackHeaderLeftPropsToOptions } from './StackHeaderLeft'
|
|
11
|
-
import { StackHeaderRight, appendStackHeaderRightPropsToOptions } from './StackHeaderRight'
|
|
12
|
-
import {
|
|
13
|
-
appendStackHeaderSearchBarPropsToOptions,
|
|
14
|
-
StackHeaderSearchBar,
|
|
15
|
-
} from './StackHeaderSearchBar'
|
|
16
|
-
import { appendStackHeaderTitlePropsToOptions, StackHeaderTitle } from './StackHeaderTitle'
|
|
17
|
-
import { isChildOfType } from '../../utils/children'
|
|
18
|
-
|
|
19
|
-
export interface StackHeaderProps {
|
|
20
|
-
children?: ReactNode
|
|
21
|
-
hidden?: boolean
|
|
22
|
-
asChild?: boolean
|
|
23
|
-
blurEffect?: ScreenStackHeaderConfigProps['blurEffect']
|
|
24
|
-
style?: StyleProp<{
|
|
25
|
-
color?: ColorValue
|
|
26
|
-
backgroundColor?: ScreenStackHeaderConfigProps['backgroundColor']
|
|
27
|
-
shadowColor?: undefined | 'transparent'
|
|
28
|
-
}>
|
|
29
|
-
largeStyle?: StyleProp<{
|
|
30
|
-
backgroundColor?: ScreenStackHeaderConfigProps['largeTitleBackgroundColor']
|
|
31
|
-
shadowColor?: undefined | 'transparent'
|
|
32
|
-
}>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Configuration component for stack headers.
|
|
37
|
-
* Use child components to configure different parts of the header.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```tsx
|
|
41
|
-
* <Stack.Header blurEffect="regular">
|
|
42
|
-
* <Stack.Header.Title large>My Title</Stack.Header.Title>
|
|
43
|
-
* <Stack.Header.Right asChild>
|
|
44
|
-
* <Button>Action</Button>
|
|
45
|
-
* </Stack.Header.Right>
|
|
46
|
-
* </Stack.Header>
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export function StackHeaderComponent(_props: StackHeaderProps) {
|
|
50
|
-
return null
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function appendStackHeaderPropsToOptions(
|
|
54
|
-
options: NativeStackNavigationOptions,
|
|
55
|
-
props: StackHeaderProps
|
|
56
|
-
): NativeStackNavigationOptions {
|
|
57
|
-
const flattenedStyle = StyleSheet.flatten(props.style)
|
|
58
|
-
const flattenedLargeStyle = StyleSheet.flatten(props.largeStyle)
|
|
59
|
-
|
|
60
|
-
if (props.hidden) {
|
|
61
|
-
return { ...options, headerShown: false }
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (props.asChild) {
|
|
65
|
-
return { ...options, header: () => props.children }
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let updatedOptions: NativeStackNavigationOptions = {
|
|
69
|
-
...options,
|
|
70
|
-
headerShown: !props.hidden,
|
|
71
|
-
headerBlurEffect: props.blurEffect,
|
|
72
|
-
headerStyle: {
|
|
73
|
-
backgroundColor: flattenedStyle?.backgroundColor as string | undefined,
|
|
74
|
-
},
|
|
75
|
-
headerLargeStyle: {
|
|
76
|
-
backgroundColor: flattenedLargeStyle?.backgroundColor as string | undefined,
|
|
77
|
-
},
|
|
78
|
-
headerShadowVisible: flattenedStyle?.shadowColor !== 'transparent',
|
|
79
|
-
headerLargeTitleShadowVisible: flattenedLargeStyle?.shadowColor !== 'transparent',
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function appendChildOptions(child: React.ReactElement, options: NativeStackNavigationOptions) {
|
|
83
|
-
let result = options
|
|
84
|
-
if (isChildOfType(child, StackHeaderTitle)) {
|
|
85
|
-
result = appendStackHeaderTitlePropsToOptions(result, child.props)
|
|
86
|
-
} else if (isChildOfType(child, StackHeaderLeft)) {
|
|
87
|
-
result = appendStackHeaderLeftPropsToOptions(result, child.props)
|
|
88
|
-
} else if (isChildOfType(child, StackHeaderRight)) {
|
|
89
|
-
result = appendStackHeaderRightPropsToOptions(result, child.props)
|
|
90
|
-
} else if (isChildOfType(child, StackHeaderBackButton)) {
|
|
91
|
-
result = appendStackHeaderBackButtonPropsToOptions(result, child.props)
|
|
92
|
-
} else if (isChildOfType(child, StackHeaderSearchBar)) {
|
|
93
|
-
result = appendStackHeaderSearchBarPropsToOptions(result, child.props)
|
|
94
|
-
} else {
|
|
95
|
-
console.warn(
|
|
96
|
-
`Warning: Unknown child element passed to Stack.Header: ${(child.type as { name: string }).name ?? child.type}`
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
return result
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
Children.forEach(props.children, (child) => {
|
|
103
|
-
if (isValidElement(child)) {
|
|
104
|
-
updatedOptions = appendChildOptions(child, updatedOptions)
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
return updatedOptions
|
|
109
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { NativeStackNavigationOptions } from '@react-navigation/native-stack'
|
|
2
|
-
import type { ReactNode } from 'react'
|
|
3
|
-
|
|
4
|
-
export interface StackHeaderLeftProps {
|
|
5
|
-
children?: ReactNode
|
|
6
|
-
asChild?: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configuration component for custom left header content.
|
|
11
|
-
* Use `asChild` to render custom components in the left header area.
|
|
12
|
-
*/
|
|
13
|
-
export function StackHeaderLeft(_props: StackHeaderLeftProps) {
|
|
14
|
-
return null
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function appendStackHeaderLeftPropsToOptions(
|
|
18
|
-
options: NativeStackNavigationOptions,
|
|
19
|
-
props: StackHeaderLeftProps
|
|
20
|
-
): NativeStackNavigationOptions {
|
|
21
|
-
if (!props.asChild) {
|
|
22
|
-
return options
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
...options,
|
|
27
|
-
headerLeft: () => props.children,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { NativeStackNavigationOptions } from '@react-navigation/native-stack'
|
|
2
|
-
import type { ReactNode } from 'react'
|
|
3
|
-
|
|
4
|
-
export interface StackHeaderRightProps {
|
|
5
|
-
children?: ReactNode
|
|
6
|
-
asChild?: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configuration component for custom right header content.
|
|
11
|
-
* Use `asChild` to render custom components in the right header area.
|
|
12
|
-
*/
|
|
13
|
-
export function StackHeaderRight(_props: StackHeaderRightProps) {
|
|
14
|
-
return null
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function appendStackHeaderRightPropsToOptions(
|
|
18
|
-
options: NativeStackNavigationOptions,
|
|
19
|
-
props: StackHeaderRightProps
|
|
20
|
-
): NativeStackNavigationOptions {
|
|
21
|
-
if (!props.asChild) {
|
|
22
|
-
return options
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
...options,
|
|
27
|
-
headerRight: () => props.children,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { NativeStackNavigationOptions } from '@react-navigation/native-stack'
|
|
2
|
-
import type { SearchBarProps } from 'react-native-screens'
|
|
3
|
-
|
|
4
|
-
export interface StackHeaderSearchBarProps extends SearchBarProps {}
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Configuration component for adding a search bar to stack headers.
|
|
8
|
-
*/
|
|
9
|
-
export function StackHeaderSearchBar(_props: StackHeaderSearchBarProps) {
|
|
10
|
-
return null
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function appendStackHeaderSearchBarPropsToOptions(
|
|
14
|
-
options: NativeStackNavigationOptions,
|
|
15
|
-
props: StackHeaderSearchBarProps
|
|
16
|
-
): NativeStackNavigationOptions {
|
|
17
|
-
return {
|
|
18
|
-
...options,
|
|
19
|
-
headerSearchBarOptions: props,
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { NativeStackNavigationOptions } from '@react-navigation/native-stack'
|
|
2
|
-
import { StyleSheet, type StyleProp, type TextStyle } from 'react-native'
|
|
3
|
-
|
|
4
|
-
import { convertFontWeightToStringFontWeight } from '../../utils/style'
|
|
5
|
-
|
|
6
|
-
export type StackHeaderTitleProps = {
|
|
7
|
-
children?: string
|
|
8
|
-
style?: StyleProp<{
|
|
9
|
-
fontFamily?: TextStyle['fontFamily']
|
|
10
|
-
fontSize?: TextStyle['fontSize']
|
|
11
|
-
fontWeight?: Exclude<TextStyle['fontWeight'], number>
|
|
12
|
-
color?: string
|
|
13
|
-
textAlign?: 'left' | 'center'
|
|
14
|
-
}>
|
|
15
|
-
largeStyle?: StyleProp<{
|
|
16
|
-
fontFamily?: TextStyle['fontFamily']
|
|
17
|
-
fontSize?: TextStyle['fontSize']
|
|
18
|
-
fontWeight?: Exclude<TextStyle['fontWeight'], number>
|
|
19
|
-
color?: string
|
|
20
|
-
}>
|
|
21
|
-
large?: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Configuration component for stack header title.
|
|
26
|
-
* This component doesn't render anything - it's used to configure the header.
|
|
27
|
-
*/
|
|
28
|
-
export function StackHeaderTitle(_props: StackHeaderTitleProps) {
|
|
29
|
-
return null
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function appendStackHeaderTitlePropsToOptions(
|
|
33
|
-
options: NativeStackNavigationOptions,
|
|
34
|
-
props: StackHeaderTitleProps
|
|
35
|
-
): NativeStackNavigationOptions {
|
|
36
|
-
const flattenedStyle = StyleSheet.flatten(props.style)
|
|
37
|
-
const flattenedLargeStyle = StyleSheet.flatten(props.largeStyle)
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
...options,
|
|
41
|
-
title: props.children,
|
|
42
|
-
headerLargeTitle: props.large,
|
|
43
|
-
headerTitleAlign: flattenedStyle?.textAlign,
|
|
44
|
-
headerTitleStyle: {
|
|
45
|
-
...flattenedStyle,
|
|
46
|
-
...(flattenedStyle?.fontWeight
|
|
47
|
-
? {
|
|
48
|
-
fontWeight: convertFontWeightToStringFontWeight(flattenedStyle?.fontWeight),
|
|
49
|
-
}
|
|
50
|
-
: {}),
|
|
51
|
-
},
|
|
52
|
-
headerLargeTitleStyle: {
|
|
53
|
-
...flattenedLargeStyle,
|
|
54
|
-
...(flattenedLargeStyle?.fontWeight
|
|
55
|
-
? {
|
|
56
|
-
fontWeight: convertFontWeightToStringFontWeight(flattenedLargeStyle?.fontWeight),
|
|
57
|
-
}
|
|
58
|
-
: {}),
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import type { NativeStackNavigationOptions } from '@react-navigation/native-stack'
|
|
4
|
-
import { Children, isValidElement, useMemo, type PropsWithChildren } from 'react'
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
StackHeaderComponent,
|
|
8
|
-
appendStackHeaderPropsToOptions,
|
|
9
|
-
type StackHeaderProps,
|
|
10
|
-
} from './StackHeaderComponent'
|
|
11
|
-
import { Screen } from '../../views/Screen'
|
|
12
|
-
|
|
13
|
-
export interface StackScreenProps extends PropsWithChildren {
|
|
14
|
-
name?: string
|
|
15
|
-
options?: NativeStackNavigationOptions
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Stack screen component with support for compositional header configuration.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* <Stack.Screen name="home" options={{ title: 'Home' }}>
|
|
24
|
-
* <Stack.Header>
|
|
25
|
-
* <Stack.Header.Title large>Welcome</Stack.Header.Title>
|
|
26
|
-
* </Stack.Header>
|
|
27
|
-
* </Stack.Screen>
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export function StackScreen({ children, options, ...rest }: StackScreenProps) {
|
|
31
|
-
const updatedOptions = useMemo(
|
|
32
|
-
() =>
|
|
33
|
-
appendScreenStackPropsToOptions(options ?? {}, {
|
|
34
|
-
children,
|
|
35
|
-
}),
|
|
36
|
-
[options, children]
|
|
37
|
-
)
|
|
38
|
-
return <Screen {...rest} options={updatedOptions} />
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function appendScreenStackPropsToOptions(
|
|
42
|
-
options: NativeStackNavigationOptions,
|
|
43
|
-
props: StackScreenProps
|
|
44
|
-
): NativeStackNavigationOptions {
|
|
45
|
-
let updatedOptions = { ...options, ...props.options }
|
|
46
|
-
|
|
47
|
-
function appendChildOptions(child: React.ReactElement, options: NativeStackNavigationOptions) {
|
|
48
|
-
if (child.type === StackHeaderComponent) {
|
|
49
|
-
return appendStackHeaderPropsToOptions(options, child.props as StackHeaderProps)
|
|
50
|
-
} else {
|
|
51
|
-
console.warn(
|
|
52
|
-
`Warning: Unknown child element passed to Stack.Screen: ${(child.type as { name: string }).name ?? child.type}`
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
return options
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
Children.forEach(props.children, (child) => {
|
|
59
|
-
if (isValidElement(child)) {
|
|
60
|
-
updatedOptions = appendChildOptions(child, updatedOptions)
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
return updatedOptions
|
|
65
|
-
}
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import { StackHeaderTitle, appendStackHeaderTitlePropsToOptions } from '../StackHeaderTitle'
|
|
5
|
-
import { StackHeaderLeft, appendStackHeaderLeftPropsToOptions } from '../StackHeaderLeft'
|
|
6
|
-
import { StackHeaderRight, appendStackHeaderRightPropsToOptions } from '../StackHeaderRight'
|
|
7
|
-
import {
|
|
8
|
-
StackHeaderBackButton,
|
|
9
|
-
appendStackHeaderBackButtonPropsToOptions,
|
|
10
|
-
} from '../StackHeaderBackButton'
|
|
11
|
-
import {
|
|
12
|
-
StackHeaderSearchBar,
|
|
13
|
-
appendStackHeaderSearchBarPropsToOptions,
|
|
14
|
-
} from '../StackHeaderSearchBar'
|
|
15
|
-
import { StackHeaderComponent, appendStackHeaderPropsToOptions } from '../StackHeaderComponent'
|
|
16
|
-
import { appendScreenStackPropsToOptions } from '../StackScreen'
|
|
17
|
-
|
|
18
|
-
describe('Stack Header Composition', () => {
|
|
19
|
-
describe('StackHeaderTitle', () => {
|
|
20
|
-
it('sets title from children', () => {
|
|
21
|
-
const result = appendStackHeaderTitlePropsToOptions({}, { children: 'My Title' })
|
|
22
|
-
expect(result.title).toBe('My Title')
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('sets headerLargeTitle when large is true', () => {
|
|
26
|
-
const result = appendStackHeaderTitlePropsToOptions({}, { large: true })
|
|
27
|
-
expect(result.headerLargeTitle).toBe(true)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('sets headerTitleAlign from style.textAlign', () => {
|
|
31
|
-
const result = appendStackHeaderTitlePropsToOptions(
|
|
32
|
-
{},
|
|
33
|
-
{
|
|
34
|
-
style: { textAlign: 'center' },
|
|
35
|
-
}
|
|
36
|
-
)
|
|
37
|
-
expect(result.headerTitleAlign).toBe('center')
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('converts numeric fontWeight to string', () => {
|
|
41
|
-
const result = appendStackHeaderTitlePropsToOptions(
|
|
42
|
-
{},
|
|
43
|
-
{
|
|
44
|
-
style: { fontWeight: '700' },
|
|
45
|
-
}
|
|
46
|
-
)
|
|
47
|
-
expect(result.headerTitleStyle).toMatchObject({ fontWeight: '700' })
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('preserves existing options', () => {
|
|
51
|
-
const result = appendStackHeaderTitlePropsToOptions(
|
|
52
|
-
{ animation: 'slide_from_right' },
|
|
53
|
-
{ children: 'Title' }
|
|
54
|
-
)
|
|
55
|
-
expect(result.animation).toBe('slide_from_right')
|
|
56
|
-
expect(result.title).toBe('Title')
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
describe('StackHeaderLeft', () => {
|
|
61
|
-
it('does not set headerLeft without asChild', () => {
|
|
62
|
-
const result = appendStackHeaderLeftPropsToOptions(
|
|
63
|
-
{},
|
|
64
|
-
{
|
|
65
|
-
children: <button>Back</button>,
|
|
66
|
-
}
|
|
67
|
-
)
|
|
68
|
-
expect(result.headerLeft).toBeUndefined()
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('sets headerLeft with asChild', () => {
|
|
72
|
-
const CustomButton = () => <button>Back</button>
|
|
73
|
-
const result = appendStackHeaderLeftPropsToOptions(
|
|
74
|
-
{},
|
|
75
|
-
{
|
|
76
|
-
asChild: true,
|
|
77
|
-
children: <CustomButton />,
|
|
78
|
-
}
|
|
79
|
-
)
|
|
80
|
-
expect(result.headerLeft).toBeDefined()
|
|
81
|
-
expect(typeof result.headerLeft).toBe('function')
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
describe('StackHeaderRight', () => {
|
|
86
|
-
it('does not set headerRight without asChild', () => {
|
|
87
|
-
const result = appendStackHeaderRightPropsToOptions(
|
|
88
|
-
{},
|
|
89
|
-
{
|
|
90
|
-
children: <button>Action</button>,
|
|
91
|
-
}
|
|
92
|
-
)
|
|
93
|
-
expect(result.headerRight).toBeUndefined()
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('sets headerRight with asChild', () => {
|
|
97
|
-
const CustomButton = () => <button>Action</button>
|
|
98
|
-
const result = appendStackHeaderRightPropsToOptions(
|
|
99
|
-
{},
|
|
100
|
-
{
|
|
101
|
-
asChild: true,
|
|
102
|
-
children: <CustomButton />,
|
|
103
|
-
}
|
|
104
|
-
)
|
|
105
|
-
expect(result.headerRight).toBeDefined()
|
|
106
|
-
expect(typeof result.headerRight).toBe('function')
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
describe('StackHeaderBackButton', () => {
|
|
111
|
-
it('sets headerBackTitle from children', () => {
|
|
112
|
-
const result = appendStackHeaderBackButtonPropsToOptions(
|
|
113
|
-
{},
|
|
114
|
-
{
|
|
115
|
-
children: 'Go Back',
|
|
116
|
-
}
|
|
117
|
-
)
|
|
118
|
-
expect(result.headerBackTitle).toBe('Go Back')
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('sets headerBackVisible to false when hidden', () => {
|
|
122
|
-
const result = appendStackHeaderBackButtonPropsToOptions(
|
|
123
|
-
{},
|
|
124
|
-
{
|
|
125
|
-
hidden: true,
|
|
126
|
-
}
|
|
127
|
-
)
|
|
128
|
-
expect(result.headerBackVisible).toBe(false)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('sets headerBackButtonMenuEnabled', () => {
|
|
132
|
-
const result = appendStackHeaderBackButtonPropsToOptions(
|
|
133
|
-
{},
|
|
134
|
-
{
|
|
135
|
-
withMenu: true,
|
|
136
|
-
}
|
|
137
|
-
)
|
|
138
|
-
expect(result.headerBackButtonMenuEnabled).toBe(true)
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
it('sets headerBackButtonDisplayMode', () => {
|
|
142
|
-
const result = appendStackHeaderBackButtonPropsToOptions(
|
|
143
|
-
{},
|
|
144
|
-
{
|
|
145
|
-
displayMode: 'minimal',
|
|
146
|
-
}
|
|
147
|
-
)
|
|
148
|
-
expect(result.headerBackButtonDisplayMode).toBe('minimal')
|
|
149
|
-
})
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
describe('StackHeaderSearchBar', () => {
|
|
153
|
-
it('sets headerSearchBarOptions', () => {
|
|
154
|
-
const result = appendStackHeaderSearchBarPropsToOptions(
|
|
155
|
-
{},
|
|
156
|
-
{
|
|
157
|
-
placeholder: 'Search...',
|
|
158
|
-
autoCapitalize: 'none',
|
|
159
|
-
}
|
|
160
|
-
)
|
|
161
|
-
expect(result.headerSearchBarOptions).toMatchObject({
|
|
162
|
-
placeholder: 'Search...',
|
|
163
|
-
autoCapitalize: 'none',
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
describe('StackHeaderComponent', () => {
|
|
169
|
-
it('sets headerShown false when hidden', () => {
|
|
170
|
-
const result = appendStackHeaderPropsToOptions({}, { hidden: true })
|
|
171
|
-
expect(result.headerShown).toBe(false)
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
it('sets headerBlurEffect', () => {
|
|
175
|
-
const result = appendStackHeaderPropsToOptions({}, { blurEffect: 'regular' })
|
|
176
|
-
expect(result.headerBlurEffect).toBe('regular')
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('sets headerShadowVisible false when shadowColor is transparent', () => {
|
|
180
|
-
const result = appendStackHeaderPropsToOptions(
|
|
181
|
-
{},
|
|
182
|
-
{
|
|
183
|
-
style: { shadowColor: 'transparent' },
|
|
184
|
-
}
|
|
185
|
-
)
|
|
186
|
-
expect(result.headerShadowVisible).toBe(false)
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
it('processes child Title component', () => {
|
|
190
|
-
const result = appendStackHeaderPropsToOptions(
|
|
191
|
-
{},
|
|
192
|
-
{
|
|
193
|
-
children: <StackHeaderTitle large>Test Title</StackHeaderTitle>,
|
|
194
|
-
}
|
|
195
|
-
)
|
|
196
|
-
expect(result.title).toBe('Test Title')
|
|
197
|
-
expect(result.headerLargeTitle).toBe(true)
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
it('processes child BackButton component', () => {
|
|
201
|
-
const result = appendStackHeaderPropsToOptions(
|
|
202
|
-
{},
|
|
203
|
-
{
|
|
204
|
-
children: <StackHeaderBackButton hidden>Back</StackHeaderBackButton>,
|
|
205
|
-
}
|
|
206
|
-
)
|
|
207
|
-
expect(result.headerBackTitle).toBe('Back')
|
|
208
|
-
expect(result.headerBackVisible).toBe(false)
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
it('processes multiple children', () => {
|
|
212
|
-
const result = appendStackHeaderPropsToOptions(
|
|
213
|
-
{},
|
|
214
|
-
{
|
|
215
|
-
children: [
|
|
216
|
-
<StackHeaderTitle key="title" large>
|
|
217
|
-
My Screen
|
|
218
|
-
</StackHeaderTitle>,
|
|
219
|
-
<StackHeaderBackButton key="back" hidden />,
|
|
220
|
-
],
|
|
221
|
-
}
|
|
222
|
-
)
|
|
223
|
-
expect(result.title).toBe('My Screen')
|
|
224
|
-
expect(result.headerLargeTitle).toBe(true)
|
|
225
|
-
expect(result.headerBackVisible).toBe(false)
|
|
226
|
-
})
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
describe('StackScreen composition', () => {
|
|
230
|
-
it('merges options with Header composition', () => {
|
|
231
|
-
const result = appendScreenStackPropsToOptions(
|
|
232
|
-
{ animation: 'slide_from_right' },
|
|
233
|
-
{
|
|
234
|
-
options: { gestureEnabled: true },
|
|
235
|
-
children: (
|
|
236
|
-
<StackHeaderComponent blurEffect="regular">
|
|
237
|
-
<StackHeaderTitle large>Composed Title</StackHeaderTitle>
|
|
238
|
-
</StackHeaderComponent>
|
|
239
|
-
),
|
|
240
|
-
}
|
|
241
|
-
)
|
|
242
|
-
|
|
243
|
-
expect(result.animation).toBe('slide_from_right')
|
|
244
|
-
expect(result.gestureEnabled).toBe(true)
|
|
245
|
-
expect(result.headerBlurEffect).toBe('regular')
|
|
246
|
-
expect(result.title).toBe('Composed Title')
|
|
247
|
-
expect(result.headerLargeTitle).toBe(true)
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
it('composition overrides options prop', () => {
|
|
251
|
-
const result = appendScreenStackPropsToOptions(
|
|
252
|
-
{},
|
|
253
|
-
{
|
|
254
|
-
options: { title: 'Options Title' },
|
|
255
|
-
children: (
|
|
256
|
-
<StackHeaderComponent>
|
|
257
|
-
<StackHeaderTitle>Composed Title</StackHeaderTitle>
|
|
258
|
-
</StackHeaderComponent>
|
|
259
|
-
),
|
|
260
|
-
}
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
// Composition should override the options prop title
|
|
264
|
-
expect(result.title).toBe('Composed Title')
|
|
265
|
-
})
|
|
266
|
-
})
|
|
267
|
-
})
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { StackHeaderBackButton, type StackHeaderBackButtonProps } from './StackHeaderBackButton'
|
|
2
|
-
import { StackHeaderComponent, type StackHeaderProps } from './StackHeaderComponent'
|
|
3
|
-
import { StackHeaderLeft, type StackHeaderLeftProps } from './StackHeaderLeft'
|
|
4
|
-
import { StackHeaderRight, type StackHeaderRightProps } from './StackHeaderRight'
|
|
5
|
-
import { StackHeaderSearchBar, type StackHeaderSearchBarProps } from './StackHeaderSearchBar'
|
|
6
|
-
import { StackHeaderTitle, type StackHeaderTitleProps } from './StackHeaderTitle'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Compound component for configuring stack headers.
|
|
10
|
-
* Attach to Stack as `Stack.Header`.
|
|
11
|
-
*/
|
|
12
|
-
export const StackHeader = Object.assign(StackHeaderComponent, {
|
|
13
|
-
Left: StackHeaderLeft,
|
|
14
|
-
Right: StackHeaderRight,
|
|
15
|
-
BackButton: StackHeaderBackButton,
|
|
16
|
-
Title: StackHeaderTitle,
|
|
17
|
-
SearchBar: StackHeaderSearchBar,
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
StackHeaderBackButton,
|
|
22
|
-
type StackHeaderBackButtonProps,
|
|
23
|
-
StackHeaderComponent,
|
|
24
|
-
type StackHeaderProps,
|
|
25
|
-
StackHeaderLeft,
|
|
26
|
-
type StackHeaderLeftProps,
|
|
27
|
-
StackHeaderRight,
|
|
28
|
-
type StackHeaderRightProps,
|
|
29
|
-
StackHeaderSearchBar,
|
|
30
|
-
type StackHeaderSearchBarProps,
|
|
31
|
-
StackHeaderTitle,
|
|
32
|
-
type StackHeaderTitleProps,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { StackScreen, appendScreenStackPropsToOptions, type StackScreenProps } from './StackScreen'
|