@@ -53,6 +53,10 @@ interface Props {
53
53
onValueChange ?: ( value : string , options : object ) => void ;
54
54
style ?: StyleProp < ViewStyle > ;
55
55
testID ?: string ;
56
+ /**
57
+ * Give the ColorPalette a background color
58
+ */
59
+ backgroundColor ?: string ;
56
60
}
57
61
export type ColorPaletteProps = Props ;
58
62
@@ -81,7 +85,8 @@ class ColorPalette extends PureComponent<Props, State> {
81
85
static defaultProps = {
82
86
numberOfRows : DEFAULT_NUMBER_OF_ROWS ,
83
87
usePagination : true ,
84
- loop : true
88
+ loop : true ,
89
+ backgroundColor : Colors . $backgroundDefault
85
90
} ;
86
91
87
92
constructor ( props : Props ) {
@@ -219,30 +224,31 @@ class ColorPalette extends PureComponent<Props, State> {
219
224
return ( margin - 0.001 ) / 2 ;
220
225
}
221
226
222
- scrollToSelected = ( ) => setTimeout ( ( ) => {
223
- const { scrollable, currentPage} = this . state ;
224
-
225
- if ( scrollable && this . selectedColorIndex !== undefined && this . itemsRefs . current ) {
226
- // The this.selectedColorIndex layout doesn't update on time
227
- // so we use this.selectedColorIndex - 1 and add an offset of 1 Swatch
228
- const childRef : any = this . itemsRefs . current [ this . selectedColorIndex - 1 ] ?. current ;
229
-
230
- if ( childRef ) {
231
- const childLayout = childRef . getLayout ( ) ;
232
- const leftMargins = this . getHorizontalMargins ( this . selectedColorIndex ) . marginLeft ;
233
- const childX = childLayout . x + childLayout . width + SWATCH_MARGIN + leftMargins + SWATCH_SIZE ;
234
- if ( childX > this . containerWidth ) {
235
- this . scrollBar ?. current ?. scrollTo ( {
236
- x : childX + HORIZONTAL_PADDING - this . containerWidth ,
237
- y : 0 ,
238
- animated : false
239
- } ) ;
227
+ scrollToSelected = ( ) =>
228
+ setTimeout ( ( ) => {
229
+ const { scrollable, currentPage} = this . state ;
230
+
231
+ if ( scrollable && this . selectedColorIndex !== undefined && this . itemsRefs . current ) {
232
+ // The this.selectedColorIndex layout doesn't update on time
233
+ // so we use this.selectedColorIndex - 1 and add an offset of 1 Swatch
234
+ const childRef : any = this . itemsRefs . current [ this . selectedColorIndex - 1 ] ?. current ;
235
+
236
+ if ( childRef ) {
237
+ const childLayout = childRef . getLayout ( ) ;
238
+ const leftMargins = this . getHorizontalMargins ( this . selectedColorIndex ) . marginLeft ;
239
+ const childX = childLayout . x + childLayout . width + SWATCH_MARGIN + leftMargins + SWATCH_SIZE ;
240
+ if ( childX > this . containerWidth ) {
241
+ this . scrollBar ?. current ?. scrollTo ( {
242
+ x : childX + HORIZONTAL_PADDING - this . containerWidth ,
243
+ y : 0 ,
244
+ animated : false
245
+ } ) ;
246
+ }
247
+ } else if ( this . usePagination ) {
248
+ this . carousel ?. current ?. goToPage ( this . selectedPage || currentPage , false ) ;
240
249
}
241
- } else if ( this . usePagination ) {
242
- this . carousel ?. current ?. goToPage ( this . selectedPage || currentPage , false ) ;
243
250
}
244
- }
245
- } , 100 )
251
+ } , 100 ) ;
246
252
247
253
onContentSizeChange = ( contentWidth : number ) => {
248
254
this . setState ( {
@@ -331,32 +337,32 @@ class ColorPalette extends PureComponent<Props, State> {
331
337
}
332
338
333
339
renderScrollableContent ( ) {
334
- const { containerStyle, ...others } = this . props ;
340
+ const { containerStyle, backgroundColor , ...others } = this . props ;
335
341
const { scrollable, contentWidth} = this . state ;
336
342
337
343
return (
338
344
< ScrollBar
339
345
ref = { this . scrollBar }
340
- style = { [ containerStyle , styles . scrollContainer ] }
346
+ style = { [ containerStyle , { backgroundColor } ] }
341
347
scrollEnabled = { scrollable }
342
348
onContentSizeChange = { this . onContentSizeChange }
343
349
height = { SCROLLABLE_HEIGHT }
344
350
containerProps = { { width : ! scrollable ? contentWidth : undefined } }
345
351
gradientHeight = { SCROLLABLE_HEIGHT - 12 }
346
- gradientColor = { Colors . $backgroundDefault }
352
+ gradientColor = { backgroundColor }
347
353
>
348
354
{ this . renderPalette ( others , styles . scrollContent , this . colors , 0 ) }
349
355
</ ScrollBar >
350
356
) ;
351
357
}
352
358
353
359
renderPaginationContent ( ) {
354
- const { containerStyle, loop, ...others } = this . props ;
360
+ const { containerStyle, loop, backgroundColor , ...others } = this . props ;
355
361
const { currentPage} = this . state ;
356
362
const colorGroups = _ . chunk ( this . colors , this . itemsPerPage ) ;
357
363
358
364
return (
359
- < View center style = { [ containerStyle , styles . paginationContainer ] } >
365
+ < View center style = { [ containerStyle , styles . paginationContainer , { backgroundColor } ] } >
360
366
< Carousel loop = { loop } onChangePage = { this . onChangePage } ref = { this . carousel } >
361
367
{ _ . map ( colorGroups , ( colorsPerPage , index ) => {
362
368
return this . renderPalette ( others , { ...styles . page , width : this . containerWidth } , colorsPerPage , index ) ;
@@ -390,12 +396,8 @@ const styles = StyleSheet.create({
390
396
} ,
391
397
paginationContainer : {
392
398
flex : 1 ,
393
- backgroundColor : Colors . $backgroundDefault ,
394
399
paddingBottom : VERTICAL_PADDING
395
400
} ,
396
- scrollContainer : {
397
- backgroundColor : Colors . $backgroundDefault
398
- } ,
399
401
page : {
400
402
flexWrap : 'wrap'
401
403
} ,
0 commit comments