@@ -15,6 +15,7 @@ import {
1515 ActivityIndicator
1616} from 'react-native'
1717import isEqual from 'lodash.isequal'
18+ import memoize from 'memoize-one'
1819import { RowItem } from './components'
1920import { callIfFunction } from './helpers'
2021
@@ -322,24 +323,18 @@ class SectionedMultiSelect extends PureComponent {
322323 this . state = {
323324 selector : false ,
324325 searchTerm : '' ,
325- highlightedChildren : [ ] ,
326- styles : StyleSheet . flatten ( [ defaultStyles , props . styles ] ) ,
327- colors : StyleSheet . flatten ( [ defaultColors , props . colors ] )
326+ highlightedChildren : [ ]
328327 }
329328 }
330329
331- componentDidUpdate ( prevProps ) {
332- if ( ! isEqual ( prevProps . styles , this . props . styles ) ) {
333- this . setState ( {
334- styles : StyleSheet . flatten ( [ defaultStyles , this . props . styles ] )
335- } )
336- }
337- if ( ! isEqual ( prevProps . colors , this . props . colors ) ) {
338- this . setState ( {
339- colors : StyleSheet . flatten ( [ defaultColors , this . props . colors ] )
340- } )
341- }
342- }
330+ getStyles = memoize (
331+ ( styles ) => StyleSheet . flatten ( [ defaultStyles , styles ] ) ,
332+ isEqual
333+ )
334+ getColors = memoize (
335+ ( colors ) => StyleSheet . flatten ( [ defaultColors , colors ] ) ,
336+ isEqual
337+ )
343338
344339 // componentWillUpdate() { date = new Date();}
345340 // componentDidUpdate() {console.log(new Date().valueOf() - date.valueOf())}
@@ -390,7 +385,10 @@ class SectionedMultiSelect extends PureComponent {
390385 renderSelectText,
391386 selectLabelNumberOfLines
392387 } = this . props
393- const { colors, styles } = this . state
388+
389+ const styles = this . getStyles ( this . props . styles )
390+ const colors = this . getColors ( this . props . colors )
391+
394392 let customSelect = null
395393
396394 if ( renderSelectText ) {
@@ -789,7 +787,9 @@ class SectionedMultiSelect extends PureComponent {
789787 }
790788
791789 _customChipsRenderer = ( ) => {
792- const { styles, colors } = this . state
790+ const styles = this . getStyles ( this . props . styles )
791+ const colors = this . getColors ( this . props . colors )
792+
793793 const {
794794 displayKey,
795795 items,
@@ -814,7 +814,9 @@ class SectionedMultiSelect extends PureComponent {
814814 }
815815
816816 _renderChips = ( ) => {
817- const { styles, colors } = this . state
817+ const styles = this . getStyles ( this . props . styles )
818+ const colors = this . getColors ( this . props . colors )
819+
818820 const {
819821 selectedItems,
820822 single,
@@ -900,7 +902,9 @@ class SectionedMultiSelect extends PureComponent {
900902 hideChipRemove,
901903 IconRenderer
902904 } = this . props
903- const { styles, colors } = this . state
905+ const styles = this . getStyles ( this . props . styles )
906+ const colors = this . getColors ( this . props . colors )
907+
904908 return selectedItems . map ( ( singleSelectedItem ) => {
905909 const item = this . _findItem ( singleSelectedItem )
906910
@@ -979,27 +983,33 @@ class SectionedMultiSelect extends PureComponent {
979983 } )
980984 }
981985
982- _renderSeparator = ( ) => (
983- < View
984- style = { [
985- {
986- flex : 1 ,
987- height : StyleSheet . hairlineWidth ,
988- alignSelf : 'stretch' ,
989- backgroundColor : '#dadada'
990- } ,
991- this . state . styles . separator
992- ] }
993- />
994- )
986+ _renderSeparator = ( ) => {
987+ const styles = this . getStyles ( this . props . styles )
988+ return (
989+ < View
990+ style = { [
991+ {
992+ flex : 1 ,
993+ height : StyleSheet . hairlineWidth ,
994+ alignSelf : 'stretch' ,
995+ backgroundColor : '#dadada'
996+ } ,
997+ styles . separator
998+ ] }
999+ />
1000+ )
1001+ }
9951002
9961003 _renderFooter = ( ) => {
9971004 const { footerComponent } = this . props
9981005 return < View > { footerComponent && callIfFunction ( footerComponent ) } </ View >
9991006 }
10001007
10011008 _renderItemFlatList = ( { item } ) => {
1002- const { styles, colors } = this . state
1009+ const styles = this . getStyles ( this . props . styles )
1010+ const colors = this . getColors ( this . props . colors )
1011+
1012+ // const { styles, colors } = this.state
10031013
10041014 const { searchTerm } = this . state
10051015 return (
@@ -1020,7 +1030,8 @@ class SectionedMultiSelect extends PureComponent {
10201030 }
10211031 ModalContentWrapper = ( { children } ) => {
10221032 const { modalWithSafeAreaView } = this . props
1023- const { styles } = this . state
1033+ const styles = this . getStyles ( this . props . styles )
1034+
10241035 const Component = modalWithSafeAreaView ? SafeAreaView : View
10251036 return (
10261037 < Component
@@ -1088,7 +1099,10 @@ class SectionedMultiSelect extends PureComponent {
10881099 disabled,
10891100 itemsFlatListProps
10901101 } = this . props
1091- const { searchTerm, selector, styles, colors } = this . state
1102+ const { searchTerm, selector } = this . state
1103+ const styles = this . getStyles ( this . props . styles )
1104+ const colors = this . getColors ( this . props . colors )
1105+ console . log ( { styles, colors } )
10921106 const renderItems = searchTerm
10931107 ? this . _filterItems ( searchTerm . trim ( ) )
10941108 : items
0 commit comments