1
1
import React , { forwardRef , ReactNode , useMemo } from 'react' ;
2
2
import { View , ViewStyle } from 'react-native' ;
3
+ import Animated from 'react-native-reanimated' ;
3
4
import { useForegroundColor , useForegroundColors } from '../../color/useForegroundColor' ;
4
5
import { useColorMode } from '../../color/ColorMode' ;
5
6
import { Shadow , shadows } from '../../layout/shadow' ;
6
7
import { Height , heights , Width , widths } from '../../layout/size' ;
7
8
import { NegativeSpace , negativeSpace , positionSpace , PositionSpace , Space , space } from '../../layout/space' ;
8
9
import { BackgroundProvider , BackgroundProviderProps } from '../BackgroundProvider/BackgroundProvider' ;
10
+ import { Border , BorderProps } from '../Border/Border' ;
9
11
import { ApplyShadow } from '../private/ApplyShadow/ApplyShadow' ;
10
12
import type * as Polymorphic from './polymorphic' ;
11
13
@@ -26,6 +28,8 @@ export type BoxProps = {
26
28
borderTopRightRadius ?: number ;
27
29
borderBottomLeftRadius ?: number ;
28
30
borderBottomRightRadius ?: number ;
31
+ borderColor ?: BorderProps [ 'borderColor' ] ;
32
+ borderWidth ?: BorderProps [ 'borderWidth' ] ;
29
33
bottom ?: PositionSpace ;
30
34
children ?: ReactNode ;
31
35
flexBasis ?: 0 ;
@@ -45,6 +49,7 @@ export type BoxProps = {
45
49
marginRight ?: NegativeSpace ;
46
50
marginTop ?: NegativeSpace ;
47
51
marginVertical ?: NegativeSpace ;
52
+ overflow ?: 'visible' | 'hidden' | 'scroll' ;
48
53
padding ?: Space ;
49
54
paddingBottom ?: Space ;
50
55
paddingHorizontal ?: Space ;
@@ -61,7 +66,6 @@ export type BoxProps = {
61
66
elevation ?: number ;
62
67
shadowOpacity ?: number ;
63
68
shadowRadius ?: number ;
64
- overflow ?: 'visible' | 'hidden' | 'scroll' | 'auto' ;
65
69
} & (
66
70
| {
67
71
borderBottomRadius ?: number ;
@@ -103,12 +107,14 @@ export const Box = forwardRef(function Box(
103
107
borderBottomLeftRadius,
104
108
borderBottomRadius,
105
109
borderBottomRightRadius,
110
+ borderColor,
106
111
borderLeftRadius,
107
112
borderRadius,
108
113
borderRightRadius,
109
114
borderTopLeftRadius,
110
115
borderTopRadius,
111
116
borderTopRightRadius,
117
+ borderWidth,
112
118
bottom : bottomProp ,
113
119
children,
114
120
flexBasis,
@@ -165,14 +171,25 @@ export const Box = forwardRef(function Box(
165
171
const right = resolveToken ( positionSpace , rightProp ) ;
166
172
const top = resolveToken ( positionSpace , topProp ) ;
167
173
168
- const width = resolveToken ( widths , widthProp ) ;
169
- const height = resolveToken ( heights , heightProp ) ;
174
+ const width = typeof widthProp === 'number' ? widthProp : resolveToken ( widths , widthProp ) ;
175
+ const height = typeof heightProp === 'number' ? heightProp : resolveToken ( heights , heightProp ) ;
176
+
177
+ const isView = Component === View || Component === Animated . View ;
178
+
179
+ const shadowStylesExist =
180
+ ! ! styleProp &&
181
+ ( 'shadowColor' in styleProp ||
182
+ 'shadowOffset' in styleProp ||
183
+ 'shadowOpacity' in styleProp ||
184
+ 'shadowRadius' in styleProp ||
185
+ 'elevation' in styleProp ) ;
170
186
171
187
const shadows = useShadow ( shadow ) ;
172
188
173
189
const styles = useMemo ( ( ) => {
174
190
return {
175
191
alignItems,
192
+ borderRadius : borderRadius , // Apply this first as certain components don't support individual corner radii
176
193
borderBottomLeftRadius : borderBottomLeftRadius ?? borderBottomRadius ?? borderLeftRadius ?? borderRadius ,
177
194
borderBottomRightRadius : borderBottomRightRadius ?? borderBottomRadius ?? borderRightRadius ?? borderRadius ,
178
195
borderCurve : 'continuous' as ViewStyle [ 'borderCurve' ] ,
@@ -194,6 +211,7 @@ export const Box = forwardRef(function Box(
194
211
marginRight,
195
212
marginTop,
196
213
marginVertical,
214
+ ...( ( isView || borderRadius ) && ! shadowStylesExist && { overflow : borderRadius ? 'hidden' : overflow } ) ,
197
215
padding,
198
216
paddingBottom,
199
217
paddingHorizontal,
@@ -224,6 +242,7 @@ export const Box = forwardRef(function Box(
224
242
flexShrink ,
225
243
flexWrap ,
226
244
height ,
245
+ isView ,
227
246
justifyContent ,
228
247
left ,
229
248
margin ,
@@ -233,6 +252,7 @@ export const Box = forwardRef(function Box(
233
252
marginRight ,
234
253
marginTop ,
235
254
marginVertical ,
255
+ overflow ,
236
256
padding ,
237
257
paddingBottom ,
238
258
paddingHorizontal ,
@@ -242,6 +262,7 @@ export const Box = forwardRef(function Box(
242
262
paddingVertical ,
243
263
position ,
244
264
right ,
265
+ shadowStylesExist ,
245
266
top ,
246
267
width ,
247
268
] ) ;
@@ -254,13 +275,35 @@ export const Box = forwardRef(function Box(
254
275
< ApplyShadow backgroundColor = { backgroundColor } shadows = { shadows } >
255
276
< Component style = { backgroundStyle } { ...restProps } ref = { ref } >
256
277
{ children }
278
+ { borderColor || borderWidth ? (
279
+ < Border
280
+ borderBottomLeftRadius = { styles . borderBottomLeftRadius }
281
+ borderBottomRightRadius = { styles . borderBottomRightRadius }
282
+ borderColor = { borderColor }
283
+ borderTopLeftRadius = { styles . borderTopLeftRadius }
284
+ borderTopRightRadius = { styles . borderTopRightRadius }
285
+ borderWidth = { borderWidth }
286
+ enableInLightMode
287
+ />
288
+ ) : null }
257
289
</ Component >
258
290
</ ApplyShadow >
259
291
) }
260
292
</ BackgroundProvider >
261
293
) : (
262
294
< Component style = { style } { ...restProps } ref = { ref } >
263
295
{ children }
296
+ { borderColor || borderWidth ? (
297
+ < Border
298
+ borderBottomLeftRadius = { styles . borderBottomLeftRadius }
299
+ borderBottomRightRadius = { styles . borderBottomRightRadius }
300
+ borderColor = { borderColor }
301
+ borderTopLeftRadius = { styles . borderTopLeftRadius }
302
+ borderTopRightRadius = { styles . borderTopRightRadius }
303
+ borderWidth = { borderWidth }
304
+ enableInLightMode
305
+ />
306
+ ) : null }
264
307
</ Component >
265
308
) ;
266
309
} ) as PolymorphicBox ;
0 commit comments