Skip to content

Commit 84d20f7

Browse files
committed
Fix collapseBelow implementation (Columns), remove align prop (Column)
1 parent e1a9aeb commit 84d20f7

File tree

4 files changed

+43
-30
lines changed

4 files changed

+43
-30
lines changed

src/Column/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import React from 'react'
22
import { View, ViewProps } from 'react-native'
3-
import { resolveFlex, resolveAlign, styles, Flex, AxisX, ResponsiveProp } from '../utils'
4-
import { useBreakpoint } from '../context'
3+
import { resolveFlex, styles, Flex } from '../utils'
4+
import { useColumns } from '../context'
55

66
export interface Props extends ViewProps {
77
children: React.ReactNode
88
width?: Flex
9-
align?: ResponsiveProp<AxisX>
109
}
1110

1211
export const Column = (props: Props) => {
13-
const { children, width, align: responsiveAlign, style, ...rest } = props
14-
const { resolveResponsiveProp } = useBreakpoint()
15-
const align = resolveResponsiveProp(responsiveAlign)
12+
const { children, width, style, ...rest } = props
13+
const { isCollapsed } = useColumns()
14+
15+
const columnStyle = isCollapsed ? [styles.fullWidth] : [styles.shrink, resolveFlex(width)]
1616

1717
return (
18-
<View style={[style, styles.shrink, resolveFlex(width), resolveAlign(align)]} {...rest}>
18+
<View style={[style, ...columnStyle]} {...rest}>
1919
{children}
2020
</View>
2121
)

src/Columns/index.tsx

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
ResponsiveProp,
1414
Breakpoint,
1515
} from '../utils'
16-
import { useBreakpoint, useDebugStyle, useSpacing } from '../context'
16+
import { ColumnsContext, useBreakpoint, useDebugStyle, useSpacing } from '../context'
1717

1818
export interface Props extends ViewProps {
1919
children: React.ReactNode
@@ -49,7 +49,7 @@ export const Columns = (props: Props) => {
4949
noOppositeMargin,
5050
spacing,
5151
direction,
52-
columnStyle,
52+
isCollapsed,
5353
} = resolveCollapsibleProps({
5454
currentBreakpoint,
5555
collapseBelow,
@@ -58,26 +58,28 @@ export const Columns = (props: Props) => {
5858
})
5959

6060
return (
61-
<View
62-
style={[
63-
style,
64-
styles.fullWidth,
65-
resolveDirection(direction),
66-
resolveAlign(alignY),
67-
resolveJustify(alignX),
68-
]}
69-
{...rest}
70-
>
71-
{elements.map((child, index) => {
72-
const marginStyle = isLast(index) ? noLastMargin : spacing
61+
<ColumnsContext.Provider value={{ isCollapsed }}>
62+
<View
63+
style={[
64+
style,
65+
styles.fullWidth,
66+
resolveDirection(direction),
67+
resolveAlign(alignY),
68+
resolveJustify(alignX),
69+
]}
70+
{...rest}
71+
>
72+
{elements.map((child, index) => {
73+
const marginStyle = isLast(index) ? noLastMargin : spacing
7374

74-
return isValidElement(child)
75-
? cloneElement(child, {
76-
...child.props,
77-
style: [child.props.style, columnStyle, debugStyle, noOppositeMargin, marginStyle],
78-
})
79-
: null
80-
})}
81-
</View>
75+
return isValidElement(child)
76+
? cloneElement(child, {
77+
...child.props,
78+
style: [child.props.style, debugStyle, noOppositeMargin, marginStyle],
79+
})
80+
: null
81+
})}
82+
</View>
83+
</ColumnsContext.Provider>
8284
)
8385
}

src/context.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ interface Config {
1414
breakpoints: Breakpoints
1515
}
1616

17+
interface ColumnsConfig {
18+
isCollapsed: boolean
19+
}
20+
1721
interface Props {
1822
children: React.ReactNode
1923
spacing?: number
@@ -29,13 +33,19 @@ const Context = createContext<Config>({
2933
breakpoints: defaultBreakpoints,
3034
})
3135

36+
export const ColumnsContext = createContext<ColumnsConfig>({
37+
isCollapsed: false,
38+
})
39+
3240
type UseSpacing = {
3341
(space: number): number
3442
(): (space: number) => number
3543
}
3644

3745
export const useStacks = () => useContext(Context)
3846

47+
export const useColumns = () => useContext(ColumnsContext)
48+
3949
export const useSpacing: UseSpacing = (space?: number): any => {
4050
const { spacing } = useStacks()
4151
const multiply = (value: number) => value * spacing

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export const resolveCollapsibleProps = (options: CollapsibleOptions) => {
382382
noOppositeMargin,
383383
spacing,
384384
direction,
385-
columnStyle: styles.fullWidth,
385+
isCollapsed: true,
386386
}
387387
}
388388

@@ -396,5 +396,6 @@ export const resolveCollapsibleProps = (options: CollapsibleOptions) => {
396396
noOppositeMargin,
397397
spacing,
398398
direction,
399+
isCollapsed: false,
399400
}
400401
}

0 commit comments

Comments
 (0)